Package org.jdom

Examples of org.jdom.Text


       
        // name
        String name = getName();
        if (name != null) {
            Element nameElement = new Element(Tags.NAME, Service.NAMESPACE);
            Text nameText = new Text(name);
            nameElement.addContent(nameText);
            member.addContent(nameElement);
        }
       
        // handle
        String handle = getHandle();
        if (handle != null) {
            Element handleElement = new Element(Tags.HANDLE, NAMESPACE);
            Text handleText = new Text(handle);
            handleElement.addContent(handleText);
            member.addContent(handleElement);
        }
       
        // permission
        String perm = getPermission();
        if (perm != null) {
            Element permissionElement = new Element(Tags.PERMISSION, NAMESPACE);
            Text permissionText = new Text(perm);
            permissionElement.addContent(permissionText);
            member.addContent(permissionElement);
        }
       
        return doc;
View Full Code Here


    protected void insertAtPreferredLocation( Element parent, Element child, Counter counter )
    {
        int contentIndex = 0;
        int elementCounter = 0;
        Iterator it = parent.getContent().iterator();
        Text lastText = null;
        int offset = 0;
        while ( it.hasNext() && elementCounter <= counter.getCurrentIndex() )
        {
            Object next = it.next();
            offset = offset + 1;
            if ( next instanceof Element )
            {
                elementCounter = elementCounter + 1;
                contentIndex = contentIndex + offset;
                offset = 0;
            }
            if ( next instanceof Text && it.hasNext() )
            {
                lastText = (Text) next;
            }
        }
        if ( lastText != null && lastText.getTextTrim().length() == 0 )
        {
            lastText = (Text) lastText.clone();
        }
        else
        {
            String starter = lineSeparator;
            for ( int i = 0; i < counter.getDepth(); i++ )
            {
                starter = starter + "    "; // TODO make settable?
            }
            lastText = factory.text( starter );
        }
        if ( parent.getContentSize() == 0 )
        {
            Text finalText = (Text) lastText.clone();
            finalText.setText( finalText.getText().substring( 0, finalText.getText().length() - "    ".length() ) );
            parent.addContent( contentIndex, finalText );
        }
        parent.addContent( contentIndex, child );
        parent.addContent( contentIndex, lastText );
    } // -- void insertAtPreferredLocation(Element, Element, Counter)
View Full Code Here

            if ( index > 0 )
            {
                Content previous = parent.getContent( index - 1 );
                if ( previous instanceof Text )
                {
                    Text txt = (Text) previous;
                    if ( txt.getTextTrim().length() == 0 )
                    {
                        parent.removeContent( txt );
                    }
                }
            }
View Full Code Here

                      while (iterator.hasNext()) {
                        
                          Object child = iterator.next();
                          //If Child is a Text Node, then append the text
                          if (child instanceof Text) {
                              Text t = (Text) child;
                              textBuffer.append(t.getValue());
                          }
                          else
                          processElement(textBuffer, child); // Recursively process the child element                  
                      }                  
                  }
View Full Code Here

        }
        replacement += "/>";

        Element parent = element.getParentElement();
        int index = parent.indexOf(element);
        parent.setContent(index, new Text(replacement));
      } else {
        // The element contains data
        String prepend = "<" + element.getName();

        @SuppressWarnings("unchecked")
        // This cast is correct
        List<Attribute> attributes = element.getAttributes();
        for (Attribute attribute : attributes) {
          prepend += " " + attribute.getName() + "=\""
              + attribute.getValue() + "\"";
        }
        prepend += ">";

        String postpend = "</" + element.getName() + ">";

        Element parent = element.getParentElement();
        int index = parent.indexOf(element);

        parent.addContent(index, new Text(postpend));
        parent.addContent(index, element.removeContent());
        parent.addContent(index, new Text(prepend));
        parent.removeContent(element);
      }
    } else {
      // If it's not an element just remove the content from the document.
      Element parent = content.getParentElement();
View Full Code Here

    for (Content content : contents) {
      if (empty == false)
        continue;

      if (content instanceof Text) {
        Text text = (Text) content;
        if (!"".equals(text.getTextNormalize()))
          empty = false;
      } else {
        empty = false;
      }
    }
View Full Code Here

            if (parts.size() > 0) {
              String lastPart = parts.remove(parts.size()-1);

              for (String part : parts) {
                removed.add(new Text(part));

                if (paragraphWrap(parent, i+1, removed)) {
                  removed.clear();
                  i++;// account for the field added
                }
              }

              removed.add(new Text(lastPart));
            }
          } else {
            removed.add(current);
            parent.removeContent(current);
            i--; // move back to account for the removed content.
View Full Code Here

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

      else if (c instanceof Text)
      {
        Text t = (Text) c;

        String text = t.getText();
        text = substitute(text, vars);
        t.setText(text);
      }
    }
  }
View Full Code Here

    }

    private static String[] createXpathFrom(Text[] textToMatch) {
        String[] xpaths = new String[textToMatch.length];
        for (int i = 0; i < textToMatch.length; i++) {
            Text text = textToMatch[i];
            xpaths[i] = Xml.getXPathExpr(text);
        }
        return xpaths;
    }
View Full Code Here

                    accept = (Boolean) nodes.get(0);
                    if (accept) {
                        break;
                    }
                }else if (node instanceof Text) {
                    Text text = (Text) node;
                    if (!text.getTextTrim().isEmpty()) {
                        accept = true;
                        break;
                    }
                } else if (node instanceof Element || node instanceof Attribute) {
                    accept = true;
View Full Code Here

TOP

Related Classes of org.jdom.Text

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.