Package org.jdom

Examples of org.jdom.Content


            event = r.next();
        }

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

            switch (event) {
            case XMLStreamConstants.CDATA:
                child = f.cdata(r.getText());
                break;
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

                }
            }

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

                doc.getRootElement().addContent( n );
            }
        }
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 encapusalted 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

    //--- handle children

    for (int i=0; i<el.getContentSize(); i++)
    {
      Content c = el.getContent(i);

      if (c instanceof Element)
        substitute((Element) c, vars);

      else if (c instanceof Text)
View Full Code Here

        if (getTo() > 0) {
            Set<String> encountered = new HashSet<String>();
            final Iterator descendants = _elSummary.getDescendants();
            while (descendants.hasNext()) {
                Content next = (Content) descendants.next();

                if (next instanceof Element) {
                    Element element = (Element) next;

                    if (element.getContentSize() == 0 && element.getAttribute("name") != null) {
View Full Code Here

     * @throws Exception
     */
  private void computeQuery(ServiceContext srvContext, Element request, ServiceConfig config) throws Exception {

//    resultType is not specified in search params - it's in config?
        Content child = request.getChild(Geonet.SearchResult.RESULT_TYPE);
        String resultType;
        if (child == null) {
            resultType  = config.getValue(Geonet.SearchResult.RESULT_TYPE, Geonet.SearchResult.ResultType.HITS);
        } else {
            resultType = child.getValue();
            child.detach();
        }

        _summaryConfig = _luceneConfig.getTaxonomy().get(resultType);

        final Element summaryItemsEl = request.getChild(Geonet.SearchResult.SUMMARY_ITEMS);
View Full Code Here

            event = r.next();
        }

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

            switch (event) {
            case XMLStreamConstants.CDATA:
                child = f.cdata(r.getText());
                break;
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

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.