Example usage for org.springframework.util.xml DomUtils getTextValue

List of usage examples for org.springframework.util.xml DomUtils getTextValue

Introduction

In this page you can find the example usage for org.springframework.util.xml DomUtils getTextValue.

Prototype

public static String getTextValue(Element valueEle) 

Source Link

Document

Extracts the text value from the given DOM element, ignoring XML comments.

Usage

From source file:pl.chilldev.web.spring.config.AbstractMetaBeanDefinitionParser.java

/**
 * {@inheritDoc}/*  w  ww  .  j a  v  a 2 s . c  o m*/
 * @since 0.0.1
 */
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    String key = element.getAttribute(AbstractMetaBeanDefinitionParser.ATTRIBUTE_KEY);
    String value = DomUtils.getTextValue(element);

    this.logger.info("Adding \"{}\" with value \"{}\" as meta \"{}\".", key, value, element.getLocalName());
    this.meta.put(key, value);

    return null;
}

From source file:pl.chilldev.web.spring.config.KeywordsBeanDefinitionParser.java

/**
 * {@inheritDoc}//from ww w.ja  v  a2 s. c o  m
 * @since 0.0.1
 */
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    String keyword;
    for (Element child : DomUtils.getChildElementsByTagName(element,
            KeywordsBeanDefinitionParser.ELEMENT_KEYWORD)) {
        keyword = DomUtils.getTextValue(child);

        this.logger.info("Adding \"{}\" as keyword.", keyword);
        this.keywords.add(keyword);
    }

    return null;
}

From source file:pl.chilldev.web.spring.config.LinkBeanDefinitionParser.java

/**
 * {@inheritDoc}// w  ww  . ja v  a 2  s .c  o  m
 * @since 0.0.2
 */
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    String href = element.getAttribute(LinkBeanDefinitionParser.ATTRIBUTE_HREF);
    Set<String> rels = new HashSet<String>();
    for (Element child : DomUtils.getChildElementsByTagName(element, LinkBeanDefinitionParser.ELEMENT_REL)) {
        rels.add(DomUtils.getTextValue(child));
    }

    GenericBeanDefinition link = new GenericBeanDefinition();
    link.setBeanClass(Link.class);

    int i = 0;
    ConstructorArgumentValues arguments = link.getConstructorArgumentValues();
    arguments.addIndexedArgumentValue(i++, href);
    arguments.addIndexedArgumentValue(i++, rels);
    arguments.addIndexedArgumentValue(i++, pl.chilldev.web.spring.util.DomUtils.getRealAttributeValue(element,
            LinkBeanDefinitionParser.ATTRIBUTE_TYPE));
    arguments.addIndexedArgumentValue(i++, pl.chilldev.web.spring.util.DomUtils.getRealAttributeValue(element,
            LinkBeanDefinitionParser.ATTRIBUTE_MEDIA));

    this.logger.info("Adding \"{}\" link.", href);
    this.links.add(link);

    return null;
}

From source file:pl.chilldev.web.spring.config.TitleBeanDefinitionParser.java

/**
 * {@inheritDoc}//  w ww.ja v  a  2  s. c  om
 * @since 0.0.1
 */
@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    if (element.hasAttribute(TitleBeanDefinitionParser.ATTRIBUTE_SEPARATOR)) {
        String separator = element.getAttribute(TitleBeanDefinitionParser.ATTRIBUTE_SEPARATOR);

        this.logger.info("Setting title separator to \"{}\".", separator);
        this.properties.addPropertyValue(TitleBeanDefinitionParser.PROPERTY_TITLESEPARATOR, separator);
    }

    String part;
    for (Element child : DomUtils.getChildElementsByTagName(element, TitleBeanDefinitionParser.ELEMENT_PART)) {
        part = DomUtils.getTextValue(child);

        this.logger.info("Adding \"{}\" as title part.", part);
        this.parts.add(part);
    }

    return null;
}

From source file:org.apache.smscserver.config.spring.SpringUtil.java

/**
 * Get the text context of first child element matching the local name and namespace
 * //ww  w.j a  v  a 2s .  c om
 * @param parent
 *            The element for which to locate the child
 * @param ns
 *            The namespace to match, or null for any namespace
 * @param localName
 *            The local name to match, or null for any local name
 * @return The text content of the first child matching the criteria or null if element not found
 */
public static String getChildElementText(final Element parent, final String ns, final String localName) {
    List<Element> elements = SpringUtil.getChildElements(parent);

    for (Element element : elements) {
        if (((ns == null) || (ns.equals(element.getNamespaceURI())
                && ((localName == null) || localName.equals(element.getLocalName()))))) {
            return DomUtils.getTextValue(element);
        }
    }

    return null;
}

From source file:org.apache.ftpserver.config.spring.SpringUtil.java

/**
 * Get the text context of first child element matching the local name and
 * namespace//from   ww  w  .ja va2  s  .  c o  m
 * 
 * @param parent
 *            The element for which to locate the child
 * @param ns
 *            The namespace to match, or null for any namespace
 * @param localName
 *            The local name to match, or null for any local name
 * @return The text content of the first child matching the criteria or null
 *         if element not found
 */
public static String getChildElementText(final Element parent, final String ns, final String localName) {
    List<Element> elements = getChildElements(parent);

    for (Element element : elements) {
        if ((ns == null || ns.equals(element.getNamespaceURI())
                && (localName == null || localName.equals(element.getLocalName())))) {
            return DomUtils.getTextValue(element);
        }
    }

    return null;
}

From source file:com.developmentsprint.spring.breaker.config.BreakerAdviceParser.java

private RootBeanDefinition parseAttributeSource(List<Element> methods, ParserContext parserContext) {
    ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute> circuitBreakerAttributeMap = new ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute>(
            methods.size());/*from  w w  w. ja  v  a2  s.co m*/

    circuitBreakerAttributeMap.setSource(parserContext.extractSource(methods));

    for (Element methodEle : methods) {
        String methodName = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
        TypedStringValue nameHolder = new TypedStringValue(methodName);
        nameHolder.setSource(parserContext.extractSource(methodEle));

        RuleBasedCircuitBreakerAttribute attribute = new RuleBasedCircuitBreakerAttribute();
        attribute.setMethodName(methodName);

        String cbName = methodEle.getAttribute(CB_NAME_ATTRIBUTE);
        if (StringUtils.isEmpty(cbName)) {
            attribute.setName(methodName);
        } else {
            attribute.setName(cbName);
        }

        ManagedMap<String, String> props = new ManagedMap<String, String>();
        Element propsElement = DomUtils.getChildElementByTagName(methodEle, "properties");
        if (propsElement != null) {
            //Map<String, String> props = new HashMap<String, String>();
            List<Element> propElements = DomUtils.getChildElementsByTagName(propsElement, "prop");
            for (Element propElement : propElements) {
                String key = propElement.getAttribute("key");
                String val = DomUtils.getTextValue(propElement);
                props.put(key, new TypedStringValue(val).getValue());
            }
            attribute.setProperties(props);
        }
        if (log.isDebugEnabled()) {
            for (Map.Entry<String, String> e : attribute.getProperties().entrySet()) {
                log.debug("{} prop : {} : {}", cbName, e.getKey(), e.getValue());
            }
        }

        circuitBreakerAttributeMap.put(nameHolder, attribute);
    }

    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(
            NameMatchCircuitBreakerAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(methods));
    attributeSourceDefinition.getPropertyValues().add("nameMap", circuitBreakerAttributeMap);
    return attributeSourceDefinition;
}

From source file:cyrille.xml.xsd.XsomXsdParserSample.java

private String getDocumentation(XSElementDecl elementDeclaration) {
    String documentation;// www  .  jav a2 s. com
    XSAnnotation annotation = elementDeclaration.getAnnotation();
    Element annotationElement = (Element) annotation.getAnnotation();
    Element documentationElement = DomUtils.getChildElementByTagName(annotationElement, "documentation");
    if (documentationElement != null) {
        documentation = DomUtils.getTextValue(documentationElement);
    } else {
        documentation = null;
    }
    return documentation;
}

From source file:org.focusns.common.web.page.config.xml.XmlPageFactory.java

private PageConfig parsePageConfigFile(Element pageEle) {
    ////from w  ww .  ja  v  a 2s.  co m
    String path = pageEle.getAttribute("path");
    String layout = pageEle.getAttribute("layout");
    String authority = pageEle.getAttribute("authority");
    Map<String, String> parameters = getParameters(pageEle);
    //
    PageConfig pageConfig = new PageConfig(path, layout);
    pageConfig.setAuthority(authority);
    pageConfig.setParameters(parameters);
    List<Element> positionEles = DomUtils.getChildElementsByTagName(pageEle, "position");
    for (Element positionEle : positionEles) {
        //
        String position = positionEle.getAttribute("name");
        PositionConfig positionConfig = new PositionConfig(pageConfig);
        positionConfig.setName(position);
        List<Element> widgetEles = DomUtils.getChildElementsByTagName(positionEle, "widget");
        for (Element widgetEle : widgetEles) {
            //
            String styleId = widgetEle.getAttribute("styleId");
            String styleClass = widgetEle.getAttribute("styleClass");
            //
            String context = widgetEle.getAttribute("context");
            String target = widgetEle.getAttribute("target");
            String mode = widgetEle.getAttribute("mode");
            String cache = widgetEle.getAttribute("cache");
            String order = widgetEle.getAttribute("order");
            //
            WidgetConfig widgetConfig = new WidgetConfig(positionConfig);
            widgetConfig.setStyleId(styleId);
            widgetConfig.setStyleClass(styleClass);
            widgetConfig.setContext(context);
            widgetConfig.setTarget(target);
            widgetConfig.setMode(mode);
            widgetConfig.setCache("".equals(cache) ? 0 : Integer.parseInt(cache));
            widgetConfig.setOrder("".equals(order) ? 0 : Integer.parseInt(order));
            // preference element
            Element preferenceEle = DomUtils.getChildElementByTagName(widgetEle, "preference");
            if (preferenceEle != null) {
                for (Element prefEle : DomUtils.getChildElements(preferenceEle)) {
                    String name = prefEle.getAttribute("name");
                    String value = DomUtils.getTextValue(prefEle);
                    widgetConfig.getPreferences().put(name, value);
                }
            }
            // navigation
            Element navigationEle = DomUtils.getChildElementByTagName(widgetEle, "navigation");
            if (navigationEle != null) {
                Map<String, String> navigationMap = new HashMap<String, String>();
                List<Element> eventEles = DomUtils.getChildElementsByTagName(navigationEle, "event");
                for (Element eventEle : eventEles) {
                    String eventOn = eventEle.getAttribute("on");
                    String eventTo = DomUtils.getTextValue(eventEle);
                    navigationMap.put(eventOn, eventTo);
                }
                widgetConfig.setNavigationMap(navigationMap);
            }
            // validation
            Element validationEle = DomUtils.getChildElementByTagName(widgetEle, "validation");
            if (validationEle != null) {
                widgetConfig.setValidationForm(validationEle.getAttribute("formId"));
                Element targetEle = DomUtils.getChildElementByTagName(validationEle, "target");
                if (targetEle != null) {
                    widgetConfig.setValidationTarget(DomUtils.getTextValue(targetEle).trim());
                }
                Element groupsEle = DomUtils.getChildElementByTagName(validationEle, "groups");
                if (groupsEle != null) {
                    List<String> validationGroups = new ArrayList<String>();
                    List<Element> groupEles = DomUtils.getChildElementsByTagName(groupsEle, "group");
                    for (Element groupEle : groupEles) {
                        validationGroups.add(DomUtils.getTextValue(groupEle).trim());
                    }
                    widgetConfig.setValidationGroups(validationGroups);
                }
            }
            //
            positionConfig.addWidgetConfig(widgetConfig);
            // pageConfig.addWidgetConfig(position, widgetConfig);
        }
        pageConfig.addPositionConfig(positionConfig);
    }
    //
    return pageConfig;
}

From source file:org.romaz.spring.scripting.ext.ExtScriptBeanDefinitionParser.java

/**
 * Resolves the script source from either the '<code>script-source</code>' attribute or
 * the '<code>inline-script</code>' element. Logs and {@link XmlReaderContext#error} and
 * returns <code>null</code> if neither or both of these values are specified.
 *///from   ww w.jav  a 2  s .  c  o  m
private String resolveScriptSource(Element element, XmlReaderContext readerContext) {
    boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT);
    if (hasScriptSource && !elements.isEmpty()) {
        readerContext.error("Only one of 'script-source' and 'inline-script' should be specified.", element);
        return null;
    } else if (hasScriptSource) {
        return element.getAttribute(SCRIPT_SOURCE_ATTRIBUTE);
    } else if (!elements.isEmpty()) {
        Element inlineElement = (Element) elements.get(0);
        return "inline:" + DomUtils.getTextValue(inlineElement);
    } else {
        readerContext.error("Must specify either 'script-source' or 'inline-script'.", element);
        return null;
    }
}