Package org.jdom

Examples of org.jdom.Content


            }
        }

        for (Iterator itr = e.getContent().iterator(); itr.hasNext();)
        {
            Content n = (Content) itr.next();
            if (n instanceof CDATA)
            {
                writer.writeCData(n.getValue());
            }
            else if (n instanceof Text)
            {
                writer.writeCharacters(((Text) n).getText());
            }
            else if (n instanceof Element)
            {
                writeElement((Element) n, writer);
            }
            else if (n instanceof Comment)
            {
                writer.writeComment(n.getValue());
            }
            else if (n instanceof EntityRef)
            {
                EntityRef ref = (EntityRef) n;
                // writer.writeEntityRef(ref.)
View Full Code Here


        if (event == -1) event = r.next();

        while (true)
        {
            boolean noadd = false;
            Content child = null;

            switch (event)
            {
            case XMLStreamConstants.CDATA:
                child = f.cdata(r.getText());
View Full Code Here

                if (namespace == null) {
                    namespace = "";
                }
                Element previousSchema = createSchemaType(namespace);
                while (schema.getContentSize() > 0) {
                    Content child = schema.removeContent(0);
                    previousSchema.addContent(child);
                }
            }
        }
        catch (JAXBException e)
View Full Code Here

            else {
              throw new NoSuchElementException("Somehow we lost our iterator");
            }
        }

        Content child = (Content) iterator.next();
        if (child instanceof Element) {
            nextIterator = ((Element)child).getContent().iterator();
        }
        return child;
    }
View Full Code Here

        if ( !shouldExist && element != null )
        {
            int index = parent.indexOf( element );
            if ( index > 0 )
            {
                Content previous = parent.getContent( index - 1 );
                if ( previous instanceof Text )
                {
                    Text txt = (Text) previous;
                    if ( txt.getTextTrim().length() == 0 )
                    {
View Full Code Here

  private void translate(Element parent) {
    // Step 1:
    // Recurse through all elements and either
    // translate them or remove them.
    for (int i = 0; i < parent.getContentSize(); i++) {
      Content decedent = parent.getContent(i);

      if (decedent instanceof org.jdom.Text) {

      } else if (decedent instanceof Element) {
        Element element = (Element) decedent;
        String name = element.getName();

        // First all the DRI elements, allow them to pass.
        if ("p".equals(name)) {
          // Paragraphs are tricky, it may be either an HTML
          // or DRI <p> element. However, while HTML will allow
          // <p> to nest DRI does not, thus first we need to
          // check if this is at the block level, if it is then
          // we need remove it.

          if (parent.isRootElement()) {
            // The paragraph is not nested, so translate it to
            // a DRI <p>
            moveAttribute(element, "class", "rend");
            limitAttributes(element, "id", "n", "rend");

            translate(element);
          } else {
            // The paragraph is nested which is not allowed in
            // DRI, so remove it.
            removeContent(element);
          }
        } else if ("h1".equals(name) || "h2".equals(name)
            || "h3".equals(name) || "h4".equals(name)
            || "h5".equals(name)) {
          // The HTML <H1> tag is translated into the DRI
          // <p rend="heading"> tag.
          if (parent.isRootElement()) {
            limitAttributes(element);
            element.setName("p");
            element.setAttribute("rend", "heading");

            translate(element);
          } else {
            // DRI paragraphs can not be nested.
            removeContent(element);
          }
        } else if ("a".equals(name)) {
          // The HTML <a> tag is translated into the DRI
          // <xref> tag.
          moveAttribute(element, "href", "target");
          limitAttributes(element, "target");
          element.setName("xref");

          translate(element);
        } else if ("ol".equals(name)) {
          // the HTML tag <ol> its translated into the DRI
          // <list> tag
          // <list type="ordered" n="list_part_one"
          // id="css.submit.LicenseAgreement.list.list_part_one">
          moveAttribute(element, "class", "rend");
          limitAttributes(element, "id", "n", "rend");
          element.setName("list");
          element.setAttribute("type", "ordered");
          translate(element);
        } else if ("li".equals(name)) {
          // the HTML tag <li> its translated into the DRI
          // <item> tag
          moveAttribute(element, "class", "rend");
          limitAttributes(element, "id", "n", "rend");
          element.setName("item");
          translate(element);
        } else if ("b".equals(name)) {
          // The HTML <b> tag is translated to a highlight
          // element with a rend of bold.
          limitAttributes(element);
          element.setName("hi");
          element.setAttribute("rend", "bold");

          translate(element);
        } else if ("i".equals(name)) {
          // The HTML <i> tag is translated to a highlight
          // element with a rend of italic.
          limitAttributes(element);
          element.setName("hi");
          element.setAttribute("rend", "italic");

          translate(element);
        } else if ("u".equals(name)) {
          // The HTML <u> tag is translated to a highlight
          // element with a rend of underline.
          limitAttributes(element);
          element.setName("hi");
          element.setAttribute("rend", "underline");

          translate(element);
        } else if ("img".equals(name)) {
          // The HTML <img> element is translated into a DRI figure
          moveAttribute(element, "src", "source");
          limitAttributes(element, "source");
          element.setName("figure");

          translate(element);
        }
        // Next all the DRI elements that we allow to pass through.
        else if ("hi".equals(name)) {
          limitAttributes(element, "rend");

          translate(element);
        } else if ("xref".equals(name)) {
          limitAttributes(element, "target");

          translate(element);
        } else if ("figure".equals(name)) {
          limitAttributes(element, "rend", "source", "target");

          translate(element);
        } else {
          removeContent(decedent);
        }
      } else {
        removeContent(decedent);
      }
    }

    // Step 2:
    // Ensure that all top level elements are encapsulated inside
    // a block level element (i.e. a paragraph)
    if (parent.isRootElement()) {
      List<Content> removed = new ArrayList<Content>();
      for (int i = 0; i < parent.getContentSize(); i++) {
        Content current = parent.getContent(i);
       
        if ((current instanceof Element)
            && ("p".equals(((Element) current).getName()))) {
          // A paragraph is being open, combine anything up to this
          // point into a paragraph.
View Full Code Here

            else {
              throw new NoSuchElementException("Somehow we lost our iterator");
            }
        }

        Content child = (Content) iterator.next();
        if (child instanceof Element) {
            nextIterator = ((Element)child).getContent().iterator();
        }
        return child;
    }
View Full Code Here

                Document r = new SAXBuilder()
                    .build(new ByteArrayInputStream(ent.getValue().toByteArray()));
               
                Element root = r.getRootElement();
                for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) {
                    Content n = (Content)itr.next();
                    if (n instanceof Element) {
                        Element e = (Element)n;
                        if ("import".equals(e.getName())
                            && "http://www.springframework.org/schema/beans".equals(e.getNamespaceURI())) {
                           
View Full Code Here

            el.setAttribute("provider", "cxf.apache.org");
        } else {
            Element root = r.getRootElement();

            for (Iterator itr = root.getChildren().iterator(); itr.hasNext();) {
                Content n = (Content)itr.next();
                itr.remove();

                doc.getRootElement().addContent(n);
            }
        }
View Full Code Here

        if ( !shouldExist && element != null )
        {
            int index = parent.indexOf( element );
            if ( index > 0 )
            {
                Content previous = parent.getContent( index - 1 );
                if ( previous instanceof Text )
                {
                    Text txt = (Text) previous;
                    if ( txt.getTextTrim().length() == 0 )
                    {
View Full Code Here

TOP

Related Classes of org.jdom.Content

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.