Package org.jdom

Examples of org.jdom.Text


     * garbage.
     */
    public Text detach() {
        // No event trigger is required here since the superclass version will
        // end up calling {@link Text#setParent} with null anyway
        Text detachedText = super.detach();
        if (detachedText != null && changeSupport != null) {
            changeSupport.outputListenerWarnings();
        }
        return detachedText;
    }
View Full Code Here


                "</eb>" +
            "</ea>");

        Element ea = doc.getRootElement();
        Attribute ea_eb_a = ea.getChild("eb").getAttribute("a");
        Text ea_eb_ec_text = (Text)ea.getChild("eb").getChild("ec").
            getContent().get(0);
        Text ea_eb_text = (Text)ea.getChild("eb").getContent().get(1);

        assertSame("Element ea class not as",
                   ODOMElement.class,
                   ea.getClass());

        assertSame("Attribute ea/eb@a class not as",
                   ODOMAttribute.class,
                   ea_eb_a.getClass());

        assertSame("Text ea/eb/ec/text() class not as",
                   ODOMCDATA.class,
                   ea_eb_ec_text.getClass());

        assertSame("Text ea/eb/text() class not as",
                   ODOMText.class,
                   ea_eb_text.getClass());
    }
View Full Code Here

        List contentNodes = quantity.getContent();
        assertEquals("quantity element should have one text node",
                     1,
                     contentNodes.size());
        Text text = (Text) contentNodes.get(0);

        // append an invalid value to the text node.
        // This should cause validation to fail
        text.append("hello");

        validator.validate(quantity);

        // check the error count
        reporter.assertErrorCount(2);
View Full Code Here

        }

        // First make sure that the text exists. This is because clients
        // of this class are only allowed to get and set values on EXTANT
        // nodes
        final Text text = getChildTextNode();
        if (text == null) {
            throw new IllegalArgumentException(
                    "ProxyElement does not contain text");
        }

        // Propagate it to the targets and set it in this instance
        delegates.propagateSetText(str);
        text.setText(str);

        return this;
    }
View Full Code Here

     *
     * @return The first text node, or null if none exist
     */
    private Text getChildTextNode() {
        List children = getContent();
        Text text = null;
        if (children != null) {
            Iterator it = children.iterator();
            while (it.hasNext() && text == null) {
                Object nextChild = it.next();
                if (nextChild instanceof Text) {
View Full Code Here

            arg = ((Attribute) node).getName();
        } else if (node instanceof CDATA) {
            CDATA cDATA = (CDATA) node;
            arg = cDATA.getParent().getName();
        } else if (node instanceof Text) {
            Text text = (Text) node;
            arg = text.getParent().getName();
        } else {
            // this should never happen as the XPath should always refer to
            // an element or attribute.
            logger.warn("localized-message",
                    ((node != null) ? node.getClass().getName() : "null"));
View Full Code Here

            if (!contents.hasNext()) {
                ErrorDetails details = new ErrorDetails(element, new XPath(element),
                        null, FaultTypes.WHITESPACE, null, null);
                errorReporter.reportError(details);
            } else {
                Text text = (Text) contents.next();
                String value = text.getText();
                if (value.length() == 0) {
                    ErrorDetails details = new ErrorDetails(element, new XPath(element),
                            null, FaultTypes.WHITESPACE, null, null);
                    errorReporter.reportError(details);
                } else {
View Full Code Here

    /**
     * Test addContent method(s).
     */
    public void testProxyElementAddContent() throws Exception {
        try {
            proxy.addContent(new Text(""));
            fail("Expected an IllegalStateException");
        } catch (IllegalStateException e) {
            // Expected exception
        }
        proxy.addContent(new ProxyText());
View Full Code Here

    /**
     * Test removeContent method(s).
     */
    public void testRemoveContent() throws Exception {
        try {
            proxy.removeContent(new Text(""));
            fail("Expected an UnsupportedOperationException");
        } catch (UnsupportedOperationException e) {
        }
//        try {
            proxy.removeContent(new Element(("a")));
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
        {
            StringBuilder starter = new StringBuilder( lineSeparator );
            for ( int i = 0; i < counter.getDepth(); i++ )
            {
                starter.append( "  " ); // TODO make settable?
            }
            lastText = factory.text( starter.toString() );
        }
        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

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.