Package org.jdom2

Examples of org.jdom2.JDOMException


                m_out.print( s );
            }
        }
        else if( element instanceof Element )
        {
            Element base = (Element)element;
            String n = base.getName().toLowerCase();
            if( "imageplugin".equals( base.getAttributeValue( "class" ) ) )
            {
                printImage( base );
            }
            else if( "wikiform".equals( base.getAttributeValue( "class" ) ) )
            {
                // only print the children if the div's class="wikiform", but not the div itself.
                printChildren( base );
            }
            else
            {
                boolean bold = false;
                boolean italic = false;
                boolean monospace = false;
                String cssSpecial = null;
                String cssClass = base.getAttributeValue( "class" );

                // accomodate a FCKeditor bug with Firefox: when a link is removed, it becomes <span class="wikipage">text</span>.
                boolean ignoredCssClass = cssClass != null && cssClass.matches( "wikipage|createpage|external|interwiki|attachment" );

                Map styleProps = null;
View Full Code Here


        for( Iterator i = base.getContent().iterator(); i.hasNext(); )
        {
            Object c = i.next();
            if( c instanceof Element )
            {
                Element e = (Element)c;
                String n = e.getName().toLowerCase();
                if( n.equals( "h1" ) )
                {
                    m_out.print( "\n!!! " );
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "h2" ) )
                {
                    m_out.print( "\n!!! " );
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "h3" ) )
                {
                    m_out.print( "\n!! " );
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "h4" ) )
                {
                    m_out.print( "\n! " );
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "p" ) )
                {
                    if( e.getContentSize() != 0 ) // we don't want to print empty elements: <p></p>
                    {
                        m_out.println();
                        print( e );
                        m_out.println();
                    }
                }
                else if( n.equals( "br" ) )
                {
                    if( m_preStack.isPreMode() )
                    {
                        m_out.println();
                    }
                    else
                    {
                        String parentElementName = base.getName().toLowerCase();

                        //
                        // To beautify the generated wiki markup, we print a newline character after a linebreak.
                        // It's only safe to do this when the parent element is a <p> or <div>; when the parent
                        // element is a table cell or list item, a newline character would break the markup.
                        // We also check that this isn't being done inside a plugin body.
                        //
                        if( parentElementName.matches( "p|div" )
                            && !base.getText().matches( "(?s).*\\[\\{.*\\}\\].*" ) )
                        {
                            m_out.print( " \\\\\n" );
                        }
                        else
                        {
                            m_out.print( " \\\\" );
                        }
                    }
                    print( e );
                }
                else if( n.equals( "hr" ) )
                {
                    m_out.println();
                    print( "----" );
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "table" ) )
                {
                    if( !m_outTimmer.isCurrentlyOnLineBegin() )
                    {
                        m_out.println();
                    }
                    print( e );
                }
                else if( n.equals( "tr" ) )
                {
                    print( e );
                    m_out.println();
                }
                else if( n.equals( "td" ) )
                {
                    m_out.print( "| " );
                    print( e );
                    if( !m_preStack.isPreMode() )
                    {
                        print( " " );
                    }
                }
                else if( n.equals( "th" ) )
                {
                    m_out.print( "|| " );
                    print( e );
                    if( !m_preStack.isPreMode() )
                    {
                        print( " " );
                    }
                }
                else if( n.equals( "a" ) )
                {
                    if( !isIgnorableWikiMarkupLink( e ) )
                    {
                        if( e.getChild( "IMG" ) != null )
                        {
                            printImage( e );
                        }
                        else
                        {
                            String ref = e.getAttributeValue( "href" );
                            if( ref == null )
                            {
                                if( isUndefinedPageLink( e ) )
                                {
                                    m_out.print( "[" );
                                    print( e );
                                    m_out.print( "]" );
                                }
                                else
                                {
                                    print( e );
                                }
                            }
                            else
                            {
                                ref = trimLink( ref );
                                if( ref != null )
                                {
                                    if( ref.startsWith( "#" ) ) // This is a link to a footnote.
                                    {
                                        // convert "#ref-PageName-1" to just "1"
                                        String href = ref.replaceFirst( "#ref-.+-(\\d+)", "$1" );
                                       
                                        // remove the brackets around "[1]"
                                        String textValue = e.getValue().substring( 1, (e.getValue().length() - 1) );
                                       
                                        if( href.equals( textValue ) ){ // handles the simplest case. Example: [1]
                                            print( e );
                                        }                                       
                                        else{ // handles the case where the link text is different from the href. Example: [something|1]
                                            m_out.print( "[" + textValue + "|" + href + "]" );
                                        }
                                    }
                                    else
                                    {
                                        Map augmentedWikiLinkAttributes = getAugmentedWikiLinkAttributes( e );

                                        m_out.print( "[" );
                                        print( e );
                                        if( !e.getTextTrim().equalsIgnoreCase( ref ) )
                                        {
                                            m_out.print( "|" );
                                            print( ref );

                                            if( !augmentedWikiLinkAttributes.isEmpty() )
                                            {
                                                m_out.print( "|" );

                                                String augmentedWikiLink = augmentedWikiLinkMapToString( augmentedWikiLinkAttributes );
                                                m_out.print( augmentedWikiLink );
                                            }
                                        }
                                        else if( !augmentedWikiLinkAttributes.isEmpty() )
                                        {
                                            // If the ref has the same value as the text and also if there
                                            // are attributes, then just print: [ref|ref|attributes] .
                                            m_out.print( "|" + ref + "|" );
                                            String augmentedWikiLink = augmentedWikiLinkMapToString( augmentedWikiLinkAttributes );
                                            m_out.print( augmentedWikiLink );
                                        }

                                        m_out.print( "]" );
                                    }
                                }
                            }
                        }
                    }
                }
                else if( n.equals( "b" ) || n.equals("strong") )
                {
                    m_out.print( "__" );
                    print( e );
                    m_out.print( "__" );
                }
                else if( n.equals( "i" ) || n.equals("em") || n.equals( "address" ) )
                {
                    m_out.print( "''" );
                    print( e );
                    m_out.print( "''" );
                }
                else if( n.equals( "u" ) )
                {
                    m_out.print( "%%( text-decoration:underline; )" );
                    print( e );
                    m_out.print( "%%" );
                }
                else if( n.equals( "strike" ) )
                {
                    m_out.print( "%%strike " );
                    print( e );
                    m_out.print( "%%" );
                    // NOTE: don't print a space before or after the double percents because that can break words into two.
                    // For example: %%(color:red)ABC%%%%(color:green)DEF%% is different from %%(color:red)ABC%% %%(color:green)DEF%%
                }
                else if( n.equals( "sup" ) )
                {
                    m_out.print( "%%sup " );
                    print( e );
                    m_out.print( "%%" );
                }
                else if( n.equals( "sub" ) )
                {
                    m_out.print( "%%sub " );
                    print( e );
                    m_out.print( "%%" );
                }
                else if( n.equals("dl") )
                {
                    m_out.print( "\n" );
                    print( e );

                    // print a newline after the definition list. If we don't,
                    // it may cause problems for the subsequent element.
                    m_out.print( "\n" );
                }
                else if( n.equals("dt") )
                {
                    m_out.print( ";" );
                    print( e );
                }
                else if( n.equals("dd") )
                {
                    m_out.print( ":" );
                    print( e );
                }
                else if( n.equals( "ul" ) )
                {
                    m_out.println();
                    m_liStack.push( "*" );
                    print( e );
                    m_liStack.pop();
                }
                else if( n.equals( "ol" ) )
                {
                    m_out.println();
                    m_liStack.push( "#" );
                    print( e );
                    m_liStack.pop();
                }
                else if( n.equals( "li" ) )
                {
                    m_out.print( m_liStack + " " );
                    print( e );

                    // The following line assumes that the XHTML has been "pretty-printed"
                    // (newlines separate child elements from their parents).
                    boolean lastListItem = base.indexOf( e ) == ( base.getContentSize() - 2 );
                    boolean sublistItem = m_liStack.toString().length() > 1;

                    // only print a newline if this <li> element is not the last item within a sublist.
                    if( !sublistItem || !lastListItem )
                    {
                        m_out.println();
                    }
                }
                else if( n.equals( "pre" ) )
                {
                    m_out.print( "\n{{{" ); // start JSPWiki "code blocks" on its own line
                    m_preStack.push();
                    print( e );
                    m_preStack.pop();

                    // print a newline after the closing braces
                    // to avoid breaking any subsequent wiki markup that follows.
                    m_out.print( "}}}\n" );
                }
                else if( n.equals( "code" ) || n.equals( "tt" ) )
                {
                    m_out.print( "{{" );
                    m_preStack.push();
                    print( e );
                    m_preStack.pop();
                    m_out.print( "}}" );
                    // NOTE: don't print a newline after the closing brackets because if the Text is inside
                    // a table or list, it would break it if there was a subsequent row or list item.
                }
                else if( n.equals( "img" ) )
                {
                    if( !isIgnorableWikiMarkupLink( e ) )
                    {
                        m_out.print( "[" );
                        print( trimLink( e.getAttributeValue( "src" ) ) );
                        m_out.print( "]" );
                    }
                }
                else if( n.equals( "form" ) )
                {
                    // remove the hidden input where name="formname" since a new one will be generated again when the xhtml is rendered.
                    Element formName = (Element)XPath.selectSingleNode( e, "INPUT[@name='formname']" );
                    if( formName != null )
                    {
                        formName.detach();
                    }

                    String name = e.getAttributeValue( "name" );

                    m_out.print( "\n[{FormOpen" );
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    private void printImage( Element base ) throws JDOMException
    {
        Element child = (Element)XPath.selectSingleNode( base, "TBODY/TR/TD/*" );
        if( child == null )
        {
            child = base;
        }
        Element img;
        String href;
        Map<Object,Object> map = new ForgetNullValuesLinkedHashMap();
        if( child.getName().equals( "A" ) )
        {
            img = child.getChild( "IMG" );
            href = child.getAttributeValue( "href" );
        }
        else
        {
            img = child;
            href = null;
        }
        if( img == null )
        {
            return;
        }
        String src = trimLink( img.getAttributeValue( "src" ) );
        if( src == null )
        {
            return;
        }
        map.put( "align", base.getAttributeValue( "align" ) );
        map.put( "height", img.getAttributeValue( "height" ) );
        map.put( "width", img.getAttributeValue( "width" ) );
        map.put( "alt", img.getAttributeValue( "alt" ) );
        map.put( "caption", emptyToNull( XPath.newInstance( "CAPTION" ).valueOf( base ) ) );
        map.put( "link", href );
        map.put( "border", img.getAttributeValue( "border" ) );
        map.put( "style", base.getAttributeValue( "style" ) );
        if( map.size() > 0 )
        {
            m_out.print( "[{Image src='" + src + "'" );
            for( Iterator i = map.entrySet().iterator(); i.hasNext(); )
View Full Code Here

     * @param xmlStream stream to parse
     */
    private void parseConfigFile( InputStream xmlStream ) {
      List< Element > pageFilters = XmlUtil.parse( xmlStream, "/pagefilters/filter" );
        for( Iterator< Element > i = pageFilters.iterator(); i.hasNext(); ) {
            Element f = i.next();
            String filterClass = f.getChildText( "class" );
            Properties props = new Properties();
           
            List< Element > params = f.getChildren( "param" );
            for( Iterator< Element > par = params.iterator(); par.hasNext(); ) {
                Element p = par.next();
                props.setProperty( p.getChildText( "name" ), p.getChildText( "value" ) );
            }

            initPageFilter( filterClass, props );
        }
    }
View Full Code Here

        // Register all filters which have created a resource containing its properties.
        //
        // Get all resources of all plugins.
        //
        for( Iterator< Element > i = filters.iterator(); i.hasNext(); ) {
            Element pluginEl = i.next();
            String className = pluginEl.getAttributeValue( "class" );
            PageFilterInfo filterInfo = PageFilterInfo.newInstance( className, pluginEl );
            if( filterInfo != null ) {
                registerFilter( filterInfo );
            }
        }
View Full Code Here

     */
    public String getString() throws IOException
    {
        StringBuffer sb = new StringBuffer(1000);
       
        Element ce = m_document.getRootElement();
       
        //
        //  Traverse through the entire tree of everything.
        //
       
View Full Code Here

                    }
                    while ( ch == '-' );

                    pushBack(ch);
                    startBlockLevel();
                    pushElement( new Element("hr") );
                    return popElement( "hr" );
                }

                pushBack( ch3 );
            }
View Full Code Here

    }

    private Element handleHeading()
        throws IOException
    {
        Element el = null;

        int ch  = nextToken();

        Heading hd = new Heading();
View Full Code Here

      Element current = null;

      XMLEvent event = events.peek();

      if (XMLStreamConstants.START_DOCUMENT != event.getEventType()) {
        throw new JDOMException("JDOM requires that XMLStreamReaders " +
            "are at their beginning when being processed.");
      }



      while (event.getEventType() != XMLStreamConstants.END_DOCUMENT) {
        if (event.isStartDocument()) {
          document.setBaseURI(event.getLocation().getSystemId());
          document.setProperty("ENCODING_SCHEME",
              ((javax.xml.stream.events.StartDocument)event).getCharacterEncodingScheme());
          document.setProperty("STANDALONE", String.valueOf(
              ((javax.xml.stream.events.StartDocument)event).isStandalone()));
          //            document.setProperty("ENCODING",
          //                ((StartDocument)event).getEncoding());
        } else if (event instanceof javax.xml.stream.events.DTD) {
          //List<?> list = (List<?>)reader.getProperty("javax.xml.stream.entities");
          //System.out.println(list);
          final DocType dtype = DTDParser.parse(((javax.xml.stream.events.DTD)event).getDocumentTypeDeclaration(), factory);
          document.setDocType(dtype);
        } else if (event.isStartElement()) {
          final Element emt = processElement(factory, event.asStartElement());
          if (current == null) {
            document.setRootElement(emt);
            final DocType dt = document.getDocType();
            if (dt != null) {
              dt.setElementName(emt.getName());
            }
          } else {
            current.addContent(emt);
          }
          current = emt;
        } else if (event.isCharacters()) {
          final Characters chars = event.asCharacters();
          if (chars.isCData()) {
            current.addContent(factory.cdata(
                ((Characters)event).getData()));
          } else {
            current.addContent(factory.text(
                ((Characters)event).getData()));
          }
        } else if (event instanceof javax.xml.stream.events.Comment) {
          final Comment comment = factory.comment(
              ((javax.xml.stream.events.Comment)event).getText());
          if (current == null) {
            document.addContent(comment);
          } else {
            current.addContent(comment);
          }
        } else if (event.isEntityReference()) {
          current.addContent(factory.entityRef(
              ((javax.xml.stream.events.EntityReference)event).getName()));
        } else if (event.isProcessingInstruction()) {
          final ProcessingInstruction pi = factory.processingInstruction(
              ((javax.xml.stream.events.ProcessingInstruction)event).getTarget(),
              ((javax.xml.stream.events.ProcessingInstruction)event).getData());
          if (current == null) {
            document.addContent(pi);
          } else {
            current.addContent(pi);
          }
        } else if (event.isEndElement()) {
          current = current.getParentElement();
        }
        if (events.hasNext()) {
          event = events.nextEvent();
        } else {
          break;
        }
      }
      return document;
    } catch (final XMLStreamException xse) {
      throw new JDOMException("Unable to process XMLStream. See Cause.", xse);
    }
  }
View Full Code Here

    try {

      int state = stream.getEventType();

      if (START_DOCUMENT != state) {
        throw new JDOMException("JDOM requires that XMLStreamReaders " +
            "are at their beginning when being processed.");
      }

      final Document document = factory.document(null);

      while (state != END_DOCUMENT) {
        switch (state) {

          case START_DOCUMENT:
            // for the <?xml version="..." standalone=".."?>
            document.setBaseURI(stream.getLocation().getSystemId());
            document.setProperty("ENCODING_SCHEME",
                stream.getCharacterEncodingScheme());
            document.setProperty("STANDALONE",
                String.valueOf(stream.isStandalone()));
            document.setProperty("ENCODING",
                stream.getEncoding());
            break;

          case DTD:
            document.setDocType(DTDParser.parse(
                stream.getText(), factory));
            break;

          case START_ELEMENT:
            document.setRootElement(processElementFragment(factory, stream));
            break;

          case END_ELEMENT:
            throw new JDOMException("Unexpected XMLStream event at Document level: END_ELEMENT");
          case ENTITY_REFERENCE:
            throw new JDOMException("Unexpected XMLStream event at Document level: ENTITY_REFERENCE");
          case CDATA:
            throw new JDOMException("Unexpected XMLStream event at Document level: CDATA");
          case SPACE:
            throw new JDOMException("Unexpected XMLStream event at Document level: SPACE");
          case CHARACTERS:
            throw new JDOMException("Unexpected XMLStream event at Document level: CHARACTERS");

          case COMMENT:
            document.addContent(
                factory.comment(stream.getText()));
            break;

          case PROCESSING_INSTRUCTION:
            document.addContent(factory.processingInstruction(
                stream.getPITarget(), stream.getPIData()));
            break;

          default:
            throw new JDOMException("Unexpected XMLStream event " + state);

        }
        if (stream.hasNext()) {
          state = stream.next();
        } else {
          throw new JDOMException("Unexpected end-of-XMLStreamReader");
        }
      }
      return document;
    } catch (final XMLStreamException xse) {
      throw new JDOMException("Unable to process XMLStream. See Cause.", xse);
    }
  }
View Full Code Here

TOP

Related Classes of org.jdom2.JDOMException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.