Example usage for org.w3c.dom Element getLocalName

List of usage examples for org.w3c.dom Element getLocalName

Introduction

In this page you can find the example usage for org.w3c.dom Element getLocalName.

Prototype

public String getLocalName();

Source Link

Document

Returns the local part of the qualified name of this node.

Usage

From source file:org.kalypsodeegree_impl.graphics.sld.SLDFactory.java

/**
 * Creates a <tt>Graphic</tt> -instance according to the contents of the DOM-subtree starting at the given
 * 'Graphic'-element.// ww w  . j  a  va 2s  .  co  m
 * <p>
 * 
 * @param element
 *          the 'Graphic'- <tt>Element</tt>
 * @throws XMLParsingException
 *           if a syntactic or semantic error in the DOM-subtree is encountered
 * @return the constructed <tt>Graphic</tt> -instance
 */
private static Graphic createGraphic(final IUrlResolver2 urlResolver, final Element element)
        throws XMLParsingException {
    // optional: <Opacity>
    ParameterValueType opacity = null;
    // optional: <Size>
    ParameterValueType size = null;
    // optional: <Rotation>
    ParameterValueType rotation = null;

    // optional: <ExternalGraphic>s / <Mark>s
    final NodeList nodelist = element.getChildNodes();
    final List<Object> marksAndExtGraphicsList = new ArrayList<>();

    for (int i = 0; i < nodelist.getLength(); i++) {
        if (nodelist.item(i) instanceof Element) {
            final Element child = (Element) nodelist.item(i);
            final String namespace = child.getNamespaceURI();

            if (!NS.SLD.equals(namespace))
                continue;

            final String childName = child.getLocalName();
            if ("ExternalGraphic".equals(childName))
                marksAndExtGraphicsList.add(SLDFactory.createExternalGraphic(urlResolver, child));
            else if ("Mark".equals(childName))
                marksAndExtGraphicsList.add(SLDFactory.createMark(urlResolver, child));
            else if ("Opacity".equals(childName))
                opacity = SLDFactory.createParameterValueType(child);
            else if ("Size".equals(childName))
                size = SLDFactory.createParameterValueType(child);
            else if ("Rotation".equals(childName))
                rotation = SLDFactory.createParameterValueType(child);
        }
    }

    final Object[] marksAndExtGraphics = marksAndExtGraphicsList
            .toArray(new Object[marksAndExtGraphicsList.size()]);

    return new Graphic_Impl(marksAndExtGraphics, opacity, size, rotation);
}

From source file:org.kuali.kfs.sys.spring.datadictionary.WorkflowAttributesBeanDefinitionParser.java

protected WorkflowAttributeMetadata parseAttributeDefinition(Element workflowAttributeDefinitionElement) {
    WorkflowAttributeMetadata workflowAttributeMetadata = null;
    if (workflowAttributeDefinitionElement.getLocalName().equals(SEARCHING_ATTRIBUTE)) {
        return parseSearchingAttribute(workflowAttributeDefinitionElement);
    } else if (workflowAttributeDefinitionElement.getLocalName().equals(ROUTING_ATTRIBUTE)) {
        return parseRoutingAttribute(workflowAttributeDefinitionElement);
    }//  w ww  . j a va  2 s.c  o  m
    return workflowAttributeMetadata;
}

From source file:org.kuali.kfs.sys.spring.datadictionary.WorkflowAttributesBeanDefinitionParser.java

protected Map<String, RoutingTypeDefinition> parseRoutingTypes(NodeList workflowAttributesChildren) {
    Map<String, RoutingTypeDefinition> routingTypesMap = new HashMap<String, RoutingTypeDefinition>();

    for (int i = 0; i < workflowAttributesChildren.getLength(); i++) {
        Node workflowAttributesChild = workflowAttributesChildren.item(i);
        if (workflowAttributesChild.getNodeType() == Node.ELEMENT_NODE) {
            if (((Element) workflowAttributesChild).getLocalName().equals(ROUTING_TYPES_ELEMENT)) {
                RoutingTypeDefinition routingTypeDefinition = new RoutingTypeDefinition();
                Element routingTypeElement = (Element) workflowAttributesChild;

                String name = routingTypeElement.getAttribute("nodeName");

                List<RoutingAttribute> routingAttributes = new ArrayList<RoutingAttribute>();
                List<DocumentValuePathGroup> documentValuePathGroups = new ArrayList<DocumentValuePathGroup>();
                List<Element> workflowAttributeList = extractWorkflowAttributeElements(
                        routingTypeElement.getChildNodes(), "");
                for (int j = 0; j < workflowAttributeList.size(); j++) {
                    Element workflowAttributeDefinitionElement = (Element) workflowAttributeList.get(j);
                    if (workflowAttributeDefinitionElement.getLocalName().equals("routingAttributes")) {
                        List<Element> routingAttributeList = extractWorkflowAttributeElements(
                                workflowAttributeDefinitionElement.getChildNodes(), "routingAttribute");
                        for (Element routingAttribute : routingAttributeList) {
                            routingAttributes
                                    .add((RoutingAttribute) parseAttributeDefinition(routingAttribute));
                        }/*from w ww  . j av a  2s .  c  om*/
                    } else if (workflowAttributeDefinitionElement.getLocalName()
                            .equals("documentValuePathGroup")) {
                        documentValuePathGroups
                                .add(parseDocumentValuesPathGroup(workflowAttributeDefinitionElement));
                    }
                }
                routingTypeDefinition.setDocumentValuePathGroups(documentValuePathGroups);
                routingTypeDefinition.setRoutingAttributes(routingAttributes);
                routingTypesMap.put(name, routingTypeDefinition);
            }
        }
    }

    return routingTypesMap;
}

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Retrieves the class of the bean defined by the xml element.
 *
 * @param bean the xml element for the bean being parsed
 * @return the class associated with the provided tag
 *///from w  w  w  .j  a  va 2 s  .  com
@Override
protected Class<?> getBeanClass(Element bean) {
    Map<String, BeanTagInfo> beanType = CustomTagAnnotations.getBeanTags();

    if (!beanType.containsKey(bean.getLocalName())) {
        return null;
    }

    // retrieve the connected class in the tag map using the xml tag's name.
    return beanType.get(bean.getLocalName()).getBeanClass();
}

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Parses the xml bean into a standard bean definition format and fills the information in the passed in definition
 * builder/*w w  w.jav a 2s. co  m*/
 *
 * @param element - The xml bean being parsed.
 * @param parserContext - Provided information and functionality regarding current bean set.
 * @param bean - A definition builder used to build a new spring bean from the information it is filled with.
 */
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
    // Retrieve custom schema information build from the annotations
    Map<String, Map<String, BeanTagAttributeInfo>> attributeProperties = CustomTagAnnotations
            .getAttributeProperties();
    Map<String, BeanTagAttributeInfo> entries = attributeProperties.get(element.getLocalName());

    // Log error if there are no attributes found for the bean tag
    if (entries == null) {
        LOG.error("Bean Tag not found " + element.getLocalName());
    }

    if (element.getTagName().equals(INC_TAG)) {
        String parentId = element.getAttribute("compId");
        bean.setParentName(parentId);

        return;
    }

    if (element.getTagName().equals("content")) {
        bean.setParentName("Uif-Content");

        String markup = nodesToString(element.getChildNodes());
        bean.addPropertyValue("markup", markup);

        return;
    }

    // Retrieve the information for the new bean tag and fill in the default parent if needed
    BeanTagInfo tagInfo = CustomTagAnnotations.getBeanTags().get(element.getLocalName());

    String elementParent = element.getAttribute("parent");
    if (StringUtils.isNotBlank(elementParent) && !StringUtils.equals(elementParent, tagInfo.getParent())) {
        bean.setParentName(elementParent);
    } else if (StringUtils.isNotBlank(tagInfo.getParent())) {
        bean.setParentName(tagInfo.getParent());
    }

    // Create the map for the attributes found in the tag and process them in to the definition builder.
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        processSingleValue(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue(), entries, bean);
    }

    ArrayList<Element> children = (ArrayList<Element>) DomUtils.getChildElements(element);

    // Process the children found in the xml tag
    for (int i = 0; i < children.size(); i++) {
        String tag = children.get(i).getLocalName();
        BeanTagAttributeInfo info = entries.get(tag);

        if (children.get(i).getTagName().equals("spring:property")
                || children.get(i).getTagName().equals("property")) {
            BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
            delegate.parsePropertyElement(children.get(i), bean.getBeanDefinition());

            continue;
        }

        // Sets the property name to be used when adding the property value
        String propertyName;
        BeanTagAttribute.AttributeType type = null;
        if (info == null) {
            propertyName = CustomTagAnnotations.findPropertyByType(element.getLocalName(), tag);

            if (StringUtils.isNotBlank(propertyName)) {
                bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext));

                continue;
            } else {
                // If the tag is not in the schema map let spring handle the value by forwarding the tag as the
                // propertyName
                propertyName = tag;
                type = findBeanType(children.get(i));
            }
        } else {
            // If the tag is found in the schema map use the connected name stored in the attribute information
            propertyName = info.getPropertyName();
            type = info.getType();
        }

        // Process the information stored in the child bean
        ArrayList<Element> grandChildren = (ArrayList<Element>) DomUtils.getChildElements(children.get(i));

        if (type == BeanTagAttribute.AttributeType.SINGLEVALUE) {
            String propertyValue = DomUtils.getTextValue(children.get(i));
            bean.addPropertyValue(propertyName, propertyValue);
        } else if (type == BeanTagAttribute.AttributeType.ANY) {
            String propertyValue = nodesToString(children.get(i).getChildNodes());
            bean.addPropertyValue(propertyName, propertyValue);
        } else if ((type == BeanTagAttribute.AttributeType.DIRECT)
                || (type == BeanTagAttribute.AttributeType.DIRECTORBYTYPE)) {
            boolean isPropertyTag = false;
            if ((children.get(i).getAttributes().getLength() == 0) && (grandChildren.size() == 1)) {
                String grandChildTag = grandChildren.get(0).getLocalName();

                Class<?> valueClass = info.getValueType();
                if (valueClass.isInterface()) {
                    try {
                        valueClass = Class.forName(valueClass.getName() + "Base");
                    } catch (ClassNotFoundException e) {
                        throw new RuntimeException("Unable to find impl class for interface", e);
                    }
                }

                Set<String> validTagNames = CustomTagAnnotations.getBeanTagsByClass(valueClass);
                if (validTagNames.contains(grandChildTag)) {
                    isPropertyTag = true;
                }
            }

            if (isPropertyTag) {
                bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext));
            } else {
                bean.addPropertyValue(propertyName, parseBean(children.get(i), bean, parserContext));
            }
        } else if ((type == BeanTagAttribute.AttributeType.SINGLEBEAN)
                || (type == BeanTagAttribute.AttributeType.BYTYPE)) {
            bean.addPropertyValue(propertyName, parseBean(grandChildren.get(0), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.LISTBEAN) {
            bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.LISTVALUE) {
            bean.addPropertyValue(propertyName, parseList(grandChildren, children.get(i), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.MAPVALUE) {
            bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.MAPBEAN) {
            bean.addPropertyValue(propertyName, parseMap(grandChildren, children.get(i), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.SETVALUE) {
            bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext));
        } else if (type == BeanTagAttribute.AttributeType.SETBEAN) {
            bean.addPropertyValue(propertyName, parseSet(grandChildren, children.get(i), bean, parserContext));
        }
    }
}

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Parses a bean based on the namespace of the bean.
 *
 * @param tag - The Element to be parsed.
 * @param parent - The parent bean that the tag is nested in.
 * @param parserContext - Provided information and functionality regarding current bean set.
 * @return The parsed bean.//from   w  w w.  j  a v  a  2s.  c o  m
 */
protected Object parseBean(Element tag, BeanDefinitionBuilder parent, ParserContext parserContext) {
    if (tag.getNamespaceURI().compareTo("http://www.springframework.org/schema/beans") == 0
            || tag.getLocalName().equals("bean")) {
        return parseSpringBean(tag, parserContext);
    } else {
        return parseCustomBean(tag, parent, parserContext);
    }
}

From source file:org.kuali.rice.krad.datadictionary.parse.CustomSchemaParser.java

/**
 * Parses a bean of the spring namespace.
 *
 * @param tag - The Element to be parsed.
 * @return The parsed bean.//from w w  w  .j  a va  2  s . c  om
 */
protected Object parseSpringBean(Element tag, ParserContext parserContext) {
    if (tag.getLocalName().compareTo("ref") == 0) {
        // Create the referenced bean by creating a new bean and setting its parent to the referenced bean
        // then replace grand child with it
        Element temp = tag.getOwnerDocument().createElement("bean");
        temp.setAttribute("parent", tag.getAttribute("bean"));
        tag = temp;
        return new RuntimeBeanReference(tag.getAttribute("parent"));
    }

    //peel off p: properties an make them actual property nodes - p-namespace does not work properly (unknown cause)
    Document document = tag.getOwnerDocument();
    NamedNodeMap attributes = tag.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        String name = attribute.getNodeName();
        if (name.startsWith("p:")) {
            Element property = document.createElement("property");
            property.setAttribute("name", StringUtils.removeStart(name, "p:"));
            property.setAttribute("value", attribute.getTextContent());

            if (tag.getFirstChild() != null) {
                tag.insertBefore(property, tag.getFirstChild());
            } else {
                tag.appendChild(property);
            }
        }
    }

    // Create the bean definition for the grandchild and return it.
    BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
    BeanDefinitionHolder bean = delegate.parseBeanDefinitionElement(tag);

    // Creates a custom name for the new bean.
    String name = bean.getBeanDefinition().getParentName() + "$Customchild" + beanNumber;
    if (tag.getAttribute("id") != null && !StringUtils.isEmpty(tag.getAttribute("id"))) {
        name = tag.getAttribute("id");
    } else {
        beanNumber++;
    }

    return new BeanDefinitionHolder(bean.getBeanDefinition(), name);
}

From source file:org.lilyproject.runtime.classloading.XmlClassLoaderBuilder.java

private ClassLoadingConfig build() throws Exception {

    List<ClasspathEntry> classpath = new ArrayList<ClasspathEntry>();

    // First add module self
    ArtifactSharingMode selfSharingMode = ArtifactSharingMode.PROHIBITED;
    String selfShareModeName = element.getAttribute("share-self");
    if (selfShareModeName.length() > 0) {
        selfSharingMode = ArtifactSharingMode.fromString(selfShareModeName);
    }/*from w  ww. ja v a 2  s  . c  om*/

    ClasspathEntry selfEntry = new ClasspathEntry(new FileArtifactRef(moduleSource.getClassPathEntry()),
            selfSharingMode, moduleSource);
    classpath.add(selfEntry);

    Element classPathElement = DocumentHelper.getElementChild(element, "classpath", false);
    if (classPathElement != null) {
        Element[] classPathEls = DocumentHelper.getElementChildren(classPathElement);
        classpath: for (Element classPathEl : classPathEls) {
            if (classPathEl.getLocalName().equals("artifact") && classPathEl.getNamespaceURI() == null) {
                // Create ArtifactRef
                String groupId = DocumentHelper.getAttribute(classPathEl, "groupId", true);
                String artifactId = DocumentHelper.getAttribute(classPathEl, "artifactId", true);
                String classifier = DocumentHelper.getAttribute(classPathEl, "classifier", false);
                String version = DocumentHelper.getAttribute(classPathEl, "version", false);
                String preferredVersion = versionManager.getPreferredVersion(groupId, artifactId);
                version = version == null ? preferredVersion : version;
                if (version == null) {
                    String message = String.format(
                            "Version for artifact %s:%s (%s) not specified, and no preference found in runtime configuration.",
                            groupId, artifactId, classifier);
                    throw new RuntimeException(message);
                }

                ArtifactRef artifactRef = new RepoArtifactRef(groupId, artifactId, classifier, version);

                // Check for double artifacts
                for (ClasspathEntry entry : classpath) {
                    if (entry.getArtifactRef().equals(artifactRef)) {
                        log.error(
                                "Classloader specification contains second reference to same artifact, will skip second reference. Artifact = "
                                        + artifactRef);
                        continue classpath;
                    } else if (entry.getArtifactRef().getId().equals(artifactRef.getId())) {
                        log.warn(
                                "Classloader specification contains second reference to same artifact but different version. Artifact = "
                                        + artifactRef);
                    }
                }

                // Creating SharingMode
                String sharingModeParam = classPathEl.getAttribute("share");
                ArtifactSharingMode sharingMode;
                if (sharingModeParam == null || sharingModeParam.equals("")) {
                    sharingMode = ArtifactSharingMode.ALLOWED;
                } else {
                    sharingMode = ArtifactSharingMode.fromString(sharingModeParam);
                }

                classpath.add(new ClasspathEntry(artifactRef, sharingMode, null));
            }
        }
    }

    return new ClassLoadingConfigImpl(classpath, repository);
}

From source file:org.lilyproject.runtime.module.build.LilyRuntimeNamespaceHandler.java

public BeanDefinition parse(Element element, ParserContext parserContext) {
    SpringBuildContext springBuildContext = ModuleBuilder.SPRING_BUILD_CONTEXT.get();

    String elementName = element.getLocalName();
    ElementProcessor processor = ELEMENT_PROCESSORS.get(elementName);

    if (processor != null) {
        try {//  w ww.  j a  v  a2 s . c  o  m
            return processor.process(element, parserContext, springBuildContext);
        } catch (Throwable e) {
            throw new LilyRTException("Error handling " + elementName + " directive.", e);
        }
    }

    return null;
}

From source file:org.mule.config.spring.MuleHierarchicalBeanDefinitionParserDelegate.java

protected String generateChildBeanName(Element e) {
    String id = SpringXMLUtils.getNameOrId(e);
    if (StringUtils.isBlank(id)) {
        String parentId = SpringXMLUtils.getNameOrId((Element) e.getParentNode());
        return "." + parentId + ":" + e.getLocalName();
    } else {/* w w w. j  a  va2s.c  o m*/
        return id;
    }
}