Package org.jdom

Examples of org.jdom.Text


                }
                else if( o instanceof Element ) {
                    add((Element)o);
                }
                else if( o instanceof Text ) {
                    Text t = (Text)o;
                    t.setText( t.getTextTrim() );
                    add(t);
                }
                else if( o instanceof Comment ) {
                    add((Comment)o);
                }
View Full Code Here


            if (o instanceof Element && E_HREF.equals(((Element)o).getName())) {
                Element hrefElm = (Element)o;
                String href = hrefElm.getTextTrim();
                if (href.startsWith(servletContext)) {
                    hrefElm.setContent(java.util.Arrays.asList(
                                           new Text[]{new Text(href.substring(servletContext.length()))}));
                }
            }
        }
    }
View Full Code Here

    private void print( Object element ) throws IOException, JDOMException
    {
        if( element instanceof Text )
        {
            Text t = (Text)element;
            String s = t.getText();
            if( m_preStack.isPreMode() )
            {
                m_out.print( s );
            }
            else
View Full Code Here

     * @param element The element to update, must not be <code>null</code>.
     * @param value   The text string to set, must not be <code>null</code>.
     */
    private void rewriteValue( Element element, String value )
    {
        Text text = null;
        if ( element.getContent() != null )
        {
            for ( Iterator it = element.getContent().iterator(); it.hasNext(); )
            {
                Object content = it.next();
                if ( ( content instanceof Text ) && ( (Text) content ).getTextTrim().length() > 0 )
                {
                    text = (Text) content;
                    while ( it.hasNext() )
                    {
                        content = it.next();
                        if ( content instanceof Text )
                        {
                            text.append( (Text) content );
                            it.remove();
                        }
                        else
                        {
                            break;
                        }
                    }
                    break;
                }
            }
        }
        if ( text == null )
        {
            element.addContent( value );
        }
        else
        {
            String chars = text.getText();
            String trimmed = text.getTextTrim();
            int idx = chars.indexOf( trimmed );
            String leadingWhitespace = chars.substring( 0, idx );
            String trailingWhitespace = chars.substring( idx + trimmed.length() );
            text.setText( leadingWhitespace + value + trailingWhitespace );
        }
    }
View Full Code Here

                Element artifactIdElement = rootElement.getChild( "artifactId", namespace );
                int index = rootElement.indexOf( artifactIdElement );

                versionElement = new Element( "version", namespace );
                versionElement.setText( version );
                rootElement.addContent( index + 1, new Text( "\n  " ) );
                rootElement.addContent( index + 2, versionElement );
            }
        }
        else
        {
View Full Code Here

                .setFormatting("\n", true, true).createPluginParameters());
    }

    @Test
    public void testIsEmptyLine() {
        assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text("\n      sortpom\n  ")));
        assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text("sortpom")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\n  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \n  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \n\n  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\n\n")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \r  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \r\r  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\r\r")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \r\n  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("  \r\n\r\n  ")));
        assertEquals(true, textWrapperCreator.isBlankLineOrLines(new Text("\r\n\r\n")));
        assertEquals(false, textWrapperCreator.isBlankLineOrLines(new Text("  ")));
    }
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

       
        // handle (required)
        String handle = getHandle();
        if (handle != null && handle.length() > 0) {
            Element handleElement = new Element(Tags.HANDLE, Service.NAMESPACE);
            Text handleText = new Text(handle);
            handleElement.addContent(handleText);
            weblog.addContent(handleElement);
        }
       
        // name
        String name = getName();
        if (name != null) {
            Element nameElement = new Element(Tags.NAME, Service.NAMESPACE);
            Text nameText = new Text(name);
            nameElement.addContent(nameText);
            weblog.addContent(nameElement);
        }
       
        // description
        String desc = getDescription();
        if (desc != null) {
            Element descElement = new Element(Tags.DESCRIPTION, Service.NAMESPACE);
            Text descText = new Text(desc);
            descElement.addContent(descText);
            weblog.addContent(descElement);
        }
       
        // locale
        Locale locale = getLocale();
        if (locale != null) {
            Element localeElement = new Element(Tags.LOCALE, Service.NAMESPACE);
            Text localeText = new Text(locale.toString());
            localeElement.addContent(localeText);
            weblog.addContent(localeElement);
        }
       
        // timezone
        TimeZone tz = getTimezone();
        if (tz != null) {
            Element tzElement = new Element(Tags.TIMEZONE, Service.NAMESPACE);
            Text tzText = new Text(tz.getID());
            tzElement.addContent(tzText);
            weblog.addContent(tzElement);
        }
       
        // creating user
        String creator = getCreatingUser();
        if (creator != null) {
            Element creatorElement = new Element(Tags.CREATING_USER, Service.NAMESPACE);
            Text creatorText = new Text(creator);
            creatorElement.addContent(creatorText);
            weblog.addContent(creatorElement);
        }
       
        // email address
        String email = getEmailAddress();
        if (email != null) {
            Element emailElement = new Element(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
            Text emailText = new Text(email);
            emailElement.addContent(emailText);
            weblog.addContent(emailElement);
        }
       
        // creation date
        Element dateCreatedElement = new Element(Tags.DATE_CREATED, Service.NAMESPACE);
        Date datedCreated = getDateCreated();
        if (dateCreated != null) {
            Text createdText = new Text(String.valueOf(dateCreated.getTime()));
            dateCreatedElement.addContent(createdText);
            weblog.addContent(dateCreatedElement);
        }
       
        // APP entries URL
        Element appEntriesUrlElement = new Element(Tags.APP_ENTRIES_URL, Service.NAMESPACE);
        String appEntriesUrl = getAppEntriesUrl();
        if (appEntriesUrl != null) {
            Text appEntriesUrlText = new Text(appEntriesUrl);
            appEntriesUrlElement.addContent(appEntriesUrlText);
            weblog.addContent(appEntriesUrlElement);
        }
       
        // APP entries URL
        Element appResourcesUrlElement = new Element(Tags.APP_RESOURCES_URL, Service.NAMESPACE);
        String appResourcesUrl = getAppResourcesUrl();
        if (appResourcesUrl != null) {
            Text appResourcesUrlText = new Text(appResourcesUrl);
            appResourcesUrlElement.addContent(appResourcesUrlText);
            weblog.addContent(appResourcesUrlElement);
        }
       
        // enabled
        Element enabledElement = new Element(Tags.ENABLED, Service.NAMESPACE);
        Boolean enabled = getEnabled();
        if (enabled != null) {
            Text enabledText = new Text(getEnabled().toString());
            enabledElement.addContent(enabledText);
            weblog.addContent(enabledElement);
        }
       
        return doc;
View Full Code Here

       
        // name
        String name = getName();
        if (name != null) {
            Element nameElement = new Element(Tags.NAME, Service.NAMESPACE);
            Text nameText = new Text(name);
            nameElement.addContent(nameText);
            userElement.addContent(nameElement);
        }

        // screen name
        String screenName = getScreenName();
        if (screenName != null) {
            Element screenNameElement = new Element(Tags.SCREEN_NAME, NAMESPACE);
            Text screenNameText = new Text(screenName);
            screenNameElement.addContent(screenNameText);
            userElement.addContent(screenNameElement);
        }

        // full name
        String fullName = getFullName();
        if (fullName != null) {
            Element fullNameElement = new Element(Tags.FULL_NAME, NAMESPACE);
            Text fullNameText = new Text(fullName);
            fullNameElement.addContent(fullNameText);
            userElement.addContent(fullNameElement);
        }
       
        // password
        String password = getPassword();
        if (password != null) {
            Element passwordElement = new Element(Tags.PASSWORD, NAMESPACE);
            Text passwordText = new Text(password);
            passwordElement.addContent(passwordText);
            userElement.addContent(passwordElement);
        }
       
        // locale
        Locale locale = getLocale();
        if (locale != null) {
            Element localeElement = new Element(Tags.LOCALE, Service.NAMESPACE);
            Text localeText = new Text(getLocale().toString());
            localeElement.addContent(localeText);
            userElement.addContent(localeElement);
        }
       
        // timezone
        TimeZone timezone = getTimezone();
        if (timezone != null) {
            Element timezoneElement = new Element(Tags.TIMEZONE, Service.NAMESPACE);
            Text timezoneText = new Text(timezone.getID());
            timezoneElement.addContent(timezoneText);
            userElement.addContent(timezoneElement);
        }
       
        // email address
        String emailAddress = getEmailAddress();
        if (emailAddress != null) {
            Element emailAddressElement = new Element(Tags.EMAIL_ADDRESS, Service.NAMESPACE);
            Text emailAddressText = new Text(emailAddress);
            emailAddressElement.addContent(emailAddressText);
            userElement.addContent(emailAddressElement);
        }
       
        // creation date
        Date datedCreated = getDateCreated();
        if (dateCreated != null) {
            Element dateCreatedElement = new Element(Tags.DATE_CREATED, Service.NAMESPACE);
            Text dateCreatedText = new Text(String.valueOf(dateCreated.getTime()));
            dateCreatedElement.addContent(dateCreatedText);
            userElement.addContent(dateCreatedElement);
        }
       
        // enabled
        Boolean enabled = getEnabled();
        if (enabled != null) {
            Element enabledElement = new Element(Tags.ENABLED, NAMESPACE);
            Text enabledText = new Text(enabled.toString());
            enabledElement.addContent(enabledText);
            userElement.addContent(enabledElement);
        }
       
        return doc;
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.