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:com.marklogic.entityservices.tests.TestInstanceConverterGenerator.java

@Test
public void testEnvelopeFunction() throws TestEvalException {

    for (String entityType : converters.keySet()) {
        String functionCall = moduleImport(entityType) + "let $p := map:map()"
                + "let $_ := map:put($p, '$type', 'Order')" + "let $_ := map:put($p, 'prop', 'val')"
                + "let $_ := map:put($p, '$attachments', element source { 'bah' })"
                + "return conv:instance-to-envelope( $p )";

        DOMHandle handle = evalOneResult(functionCall, new DOMHandle());
        Document document = handle.get();
        Element docElement = document.getDocumentElement();
        assertEquals("envelope function verification", "envelope", docElement.getLocalName());
        NodeList nl = docElement.getChildNodes();
        assertEquals("Envelope must have two children.", 2, nl.getLength());
        for (int i = 0; i < nl.getLength(); i++) {
            Node n = nl.item(i);//from  www  . j  a  v a  2  s .com
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                logger.debug("Checking node name " + n.getLocalName());
                Element e = (Element) n;
                assertTrue(e.getLocalName().equals("instance") || e.getLocalName().equals("attachments"));
            }
        }
    }

}

From source file:com.evolveum.midpoint.util.DOMUtil.java

public static Element getChildElement(Element element, String localPart) {
    for (Element subelement : listChildElements(element)) {
        if (subelement.getLocalName().equals(localPart)) {
            return subelement;
        }/*from w w  w  .  ja  v a  2 s.com*/
    }
    return null;
}

From source file:com.clustercontrol.infra.util.WinRs.java

private WinRsCommandOutput getCommandOutputFromResponse(String commandId, ManagedInstance resp) {

    StringBuilder stdout = new StringBuilder();
    StringBuilder stderr = new StringBuilder();
    long exitCode = 0;
    WinRsCommandState state = WinRsCommandState.Running;

    NodeList nodeList = resp.getBody().getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Element node = (Element) nodeList.item(i);
        if (!commandId.equals(node.getAttribute("CommandId"))) {
            continue;
        }/*from   w w w.j av  a 2 s.  c om*/

        if ("Stream".equals(node.getLocalName())) {
            if ("stdout".equals(node.getAttribute("Name"))) {
                stdout.append(new String(Base64.decodeBase64(node.getTextContent())));
            } else if ("stderr".equals(node.getAttribute("Name"))) {
                stderr.append(new String(Base64.decodeBase64(node.getTextContent())));
            }
        } else if ("CommandState".equals(node.getLocalName())) {
            if (node.getAttribute("State").endsWith("Done")) {
                exitCode = Long.parseLong(node.getChildNodes().item(0).getTextContent());
                state = WinRsCommandState.Done;
            } else if (node.getAttribute("State").endsWith("Running")) {
                state = WinRsCommandState.Running;
            } else {
                state = WinRsCommandState.Pending;
            }
        }
    }

    return new WinRsCommandOutput(stdout.toString(), stderr.toString(), exitCode, state);
}

From source file:com.amalto.core.storage.record.XmlDOMDataRecordReader.java

private void _read(MetadataRepository repository, DataRecord dataRecord, ComplexTypeMetadata type,
        Element element) {//from w w w  .j a v a 2s  .  c  o  m
    // TODO Don't use getChildNodes() but getNextSibling() calls (but cause regressions -> see TMDM-5410).
    String tagName = element.getTagName();
    NodeList children = element.getChildNodes();
    NamedNodeMap attributes = element.getAttributes();
    for (int i = 0; i < attributes.getLength(); i++) {
        Node attribute = attributes.item(i);
        if (!type.hasField(attribute.getNodeName())) {
            continue;
        }
        FieldMetadata field = type.getField(attribute.getNodeName());
        dataRecord.set(field, StorageMetadataUtils.convert(attribute.getNodeValue(), field));
    }
    for (int i = 0; i < children.getLength(); i++) {
        Node currentChild = children.item(i);
        if (currentChild instanceof Element) {
            Element child = (Element) currentChild;
            if (METADATA_NAMESPACE.equals(child.getNamespaceURI())) {
                DataRecordMetadataHelper.setMetadataValue(dataRecord.getRecordMetadata(), child.getLocalName(),
                        child.getTextContent());
            } else {
                if (!type.hasField(child.getTagName())) {
                    continue;
                }
                FieldMetadata field = type.getField(child.getTagName());
                if (field.getType() instanceof ContainedComplexTypeMetadata) {
                    ComplexTypeMetadata containedType = (ComplexTypeMetadata) field.getType();
                    String xsiType = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); //$NON-NLS-1$
                    if (xsiType.startsWith("java:")) { //$NON-NLS-1$
                        // Special format for 'java:' type names (used in Castor XML to indicate actual class name)
                        xsiType = ClassRepository.format(StringUtils
                                .substringAfterLast(StringUtils.substringAfter(xsiType, "java:"), ".")); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    if (!xsiType.isEmpty()) {
                        for (ComplexTypeMetadata subType : containedType.getSubTypes()) {
                            if (subType.getName().equals(xsiType)) {
                                containedType = subType;
                                break;
                            }
                        }
                    }
                    DataRecord containedRecord = new DataRecord(containedType,
                            UnsupportedDataRecordMetadata.INSTANCE);
                    dataRecord.set(field, containedRecord);
                    _read(repository, containedRecord, containedType, child);
                } else if (ClassRepository.EMBEDDED_XML.equals(field.getType().getName())) {
                    try {
                        dataRecord.set(field, Util.nodeToString(element));
                    } catch (TransformerException e) {
                        throw new RuntimeException(e);
                    }
                } else {
                    _read(repository, dataRecord, type, child);
                }
            }
        } else if (currentChild instanceof Text) {
            StringBuilder builder = new StringBuilder();
            for (int j = 0; j < element.getChildNodes().getLength(); j++) {
                String nodeValue = element.getChildNodes().item(j).getNodeValue();
                if (nodeValue != null) {
                    builder.append(nodeValue.trim());
                }
            }
            String textContent = builder.toString();
            if (!textContent.isEmpty()) {
                FieldMetadata field = type.getField(tagName);
                if (field instanceof ReferenceFieldMetadata) {
                    ComplexTypeMetadata actualType = ((ReferenceFieldMetadata) field).getReferencedType();
                    String mdmType = element.getAttributeNS(SkipAttributeDocumentBuilder.TALEND_NAMESPACE,
                            "type"); //$NON-NLS-1$
                    if (!mdmType.isEmpty()) {
                        actualType = repository.getComplexType(mdmType);
                    }
                    if (actualType == null) {
                        throw new IllegalArgumentException("Type '" + mdmType + "' does not exist.");
                    }
                    dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, actualType));
                } else {
                    dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, type));
                }
            }
        }
    }
}

From source file:com.amalto.workbench.providers.datamodel.util.SchemaItemImageCreator.java

protected Image getImageForElement(Element element) {

    try {//from w  w  w. ja  v a 2s. c o m
        if ("documentation".equals(element.getLocalName()))//$NON-NLS-1$
            return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());

        if ("appinfo".equals(element.getLocalName())) {//$NON-NLS-1$
            String source = element.getAttribute("source");//$NON-NLS-1$
            if (source != null) {
                if (source.startsWith("X_Label_"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.LABEL.getPath());

                if (source.equals("X_ForeignKey"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.PRIMARYKEY.getPath());

                if (source.equals("X_ForeignKeyInfo"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());

                if (source.equals("X_Retrieve_FKinfos"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());

                if (source.equals("X_FKIntegrity"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());

                if (source.equals("X_FKIntegrity_Override"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.KEYINFO.getPath());

                if (source.equals("X_SourceSystem"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.SOURCESYSTEM.getPath());

                if (source.equals("X_TargetSystem"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.TARGETSYSTEM.getPath());

                if (source.startsWith("X_Description_"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());

                if (source.equals("X_Write"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());

                if (source.equals("X_Lookup_Field"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.BROWSE.getPath());

                if (source.equals("X_Hide"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.SECURITYANNOTATION.getPath());

                if (source.equals("X_Schematron"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.ROUTINE.getPath());

                if (source.equals("X_Workflow"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.WORKFLOW_PROCESS.getPath());

                if (source.equals("X_ForeignKey_Filter"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.FILTER_PS.getPath());

                if (source.startsWith("X_Display_Format_"))//$NON-NLS-1$
                    return ImageCache.getCreatedImage(EImage.THIN_MIN_VIEW.getPath());
            }
        }

        return ImageCache.getCreatedImage(EImage.DOCUMENTATION.getPath());
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

    return getImageForUnknown();
}

From source file:edu.internet2.middleware.psp.spring.GrouperNameFromLdapDnPSOIdentifierAttributeDefinitionBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
    super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    String baseDn = pluginConfig.getAttributeNS(null, "baseDn");
    LOG.debug("Setting baseDn of element '{}' to: '{}'", pluginConfig.getLocalName(), baseDn);
    pluginBuilder.addPropertyValue("baseDn", baseDn);

    String baseStem = pluginConfig.getAttributeNS(null, "baseStem");
    LOG.debug("Setting baseStem of element '{}' to: '{}'", pluginConfig.getLocalName(), baseStem);
    pluginBuilder.addPropertyValue("baseStem", baseStem);

}

From source file:com.hp.saas.agm.core.entity.EntityQuery.java

public synchronized void fromElement(Element element) {
    setName(element.getAttribute("name"));
    Element filter = null;// ww w.  j  av  a  2 s  .co m
    Element cross = null;
    Element orderBy = null;
    Element viewing = null;

    for (Element child : (List<Element>) element.getChildNodes()) {
        if (child.getLocalName() == "filter") {
            filter = child;
        }
        if (child.getLocalName() == "crossFilter") {
            cross = child;
        }

        if (child.getLocalName() == "order") {
            orderBy = child;
        }

        if (child.getLocalName() == "view") {
            viewing = child;
        }
    }

    if (filter != null) {
        super.fromElement(filter);
    }

    if (cross != null) {
        this.cross.clear();
        for (Element child : (List<Element>) cross.getChildNodes()) {
            EntityCrossFilter cf = new EntityCrossFilter(child.getTagName());
            cf.fromElement(child);
            String alias = child.getAttribute("alias");
            if (alias == null) {
                alias = child.getLocalName();
            }
            this.cross.put(alias, cf);
        }
    }
    //Element orderBy = element.getChild("order");
    if (orderBy != null) {
        order.clear();
        for (Element child : (List<Element>) orderBy.getChildNodes()) {
            order.put(child.getLocalName(), SortOrder.valueOf(child.getAttribute("dir")));
        }
    }
    if (viewing != null) {
        view.clear();
        for (Element child : (List<Element>) viewing.getChildNodes()) {
            if (child.getLocalName() == "column") {
                view.put(child.getAttribute("name"), Integer.valueOf(child.getAttribute("width")));
            }

        }
    }
}

From source file:com.netflix.ice.login.saml.Saml.java

public LoginResponse processLogin(HttpServletRequest request) throws LoginMethodException {
    IceSession iceSession = new IceSession(request.getSession());
    iceSession.voidSession(); //a second login request voids anything previous
    logger.info("Saml::processLogin");
    LoginResponse lr = new LoginResponse();
    String assertion = (String) request.getParameter("SAMLResponse");
    if (assertion == null) {
        lr.redirectTo = config.singleSignOnUrl;
        return lr;
    }//from  w w  w  .java 2s.  c om
    logger.trace("Received SAML Assertion: " + assertion);
    try {
        // 1.1 2.0 schemas
        Schema schema = SAMLSchemaBuilder.getSAML11Schema();

        //get parser pool manager
        BasicParserPool parserPoolManager = new BasicParserPool();
        parserPoolManager.setNamespaceAware(true);
        parserPoolManager.setIgnoreElementContentWhitespace(true);
        parserPoolManager.setSchema(schema);

        String data = new String(Base64.decode(assertion));
        logger.info("Decoded SAML Assertion: " + data);

        StringReader reader = new StringReader(data);
        Document document = parserPoolManager.parse(reader);
        Element documentRoot = document.getDocumentElement();

        QName qName = new QName(documentRoot.getNamespaceURI(), documentRoot.getLocalName(),
                documentRoot.getPrefix());

        //get an unmarshaller
        Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller(documentRoot);

        //unmarshall using the document root element
        XMLObject xmlObj = unmarshaller.unmarshall(documentRoot);
        Response response = (Response) xmlObj;
        for (Assertion myAssertion : response.getAssertions()) {
            if (!myAssertion.isSigned()) {
                logger.error("SAML Assertion not signed");
                throw new LoginMethodException("SAML Assertions must be signed by a trusted provider");
            }

            Signature assertionSignature = myAssertion.getSignature();
            SAMLSignatureProfileValidator profVal = new SAMLSignatureProfileValidator();

            logger.info("Validating SAML Assertion");
            // will throw a ValidationException 
            profVal.validate(assertionSignature);

            //Credential signCred = assertionSignature.getSigningCredential();
            boolean goodSignature = false;
            for (Certificate trustedCert : trustedSigningCerts) {
                BasicCredential cred = new BasicCredential();
                cred.setPublicKey(trustedCert.getPublicKey());
                SignatureValidator validator = new SignatureValidator(cred);
                try {
                    validator.validate(assertionSignature);
                } catch (ValidationException ve) {
                    /* Not a good key! */
                    logger.debug("Not signed by " + trustedCert.toString());
                    continue;
                }
                logger.info("Assertion trusted from " + trustedCert.toString());
                processAssertion(iceSession, myAssertion, lr);
                goodSignature = true;
                break;
            }

            if (goodSignature) {
                lr.loginSuccess = true;
            }

        }
    } catch (org.xml.sax.SAXException saxe) {
        logger.error(saxe.toString());
    } catch (org.opensaml.xml.parse.XMLParserException xmlpe) {
        logger.error(xmlpe.toString());
    } catch (org.opensaml.xml.io.UnmarshallingException uee) {
        logger.error(uee.toString());
    } catch (org.opensaml.xml.validation.ValidationException ve) {
        throw new LoginMethodException("SAML Assertion Signature was not usable: " + ve.toString());
    }
    return lr;
}

From source file:org.drools.container.spring.namespace.ResourceDefinitionParser.java

@SuppressWarnings("unchecked")
@Override//from  w w  w.  java2  s.c o  m
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder factory = BeanDefinitionBuilder.rootBeanDefinition(DroolsResourceAdapter.class);

    if (StringUtils.hasText(element.getAttribute(REF))) {
        String ref = element.getAttribute(REF);
        emptyAttributeCheck(element.getLocalName(), REF, ref);
        return (AbstractBeanDefinition) parserContext.getRegistry().getBeanDefinition(ref);
    }

    String source = element.getAttribute(SOURCE_ATTRIBUTE);
    emptyAttributeCheck(element.getLocalName(), SOURCE_ATTRIBUTE, source);
    factory.addPropertyValue("resource", source);

    String type = element.getAttribute(TYPE_ATTRIBUTE);

    String resourceType = type == null || type.length() == 0 ? ResourceType.DRL.getName() : type;

    factory.addPropertyValue("resourceType", resourceType);

    boolean basicAuthenticationEnabled = element.getAttribute(BASIC_AUTHENTICATION_ATTRIBUTE) != null
            && element.getAttribute(BASIC_AUTHENTICATION_ATTRIBUTE).equalsIgnoreCase("enabled");
    factory.addPropertyValue("basicAuthenticationEnabled", basicAuthenticationEnabled);

    if (basicAuthenticationEnabled) {
        String username = element.getAttribute(USERNAME_ATTRIBUTE);
        factory.addPropertyValue("basicAuthenticationUsername", username);

        String password = element.getAttribute(PASSWORD_ATTRIBUTE);
        factory.addPropertyValue("basicAuthenticationPassword", password);
    }

    String name = element.getAttribute(NAME);
    factory.addPropertyValue("name", org.drools.core.util.StringUtils.isEmpty(name) ? null : name);

    String description = element.getAttribute(DESCRIPTION);
    factory.addPropertyValue("description",
            org.drools.core.util.StringUtils.isEmpty(description) ? null : description);

    if ("xsd".equals(resourceType.toLowerCase())) {
        XsdParser.parse(element, parserContext, factory);
    } else if ("dtable".equals(resourceType.toLowerCase())) {
        List<Element> childElements = DomUtils.getChildElementsByTagName(element, "decisiontable-conf");
        if (!childElements.isEmpty()) {
            Element conf = childElements.get(0);
            DecisionTableConfigurationImpl dtableConf = new DecisionTableConfigurationImpl();

            String inputType = conf.getAttribute(INPUT_TYPE_ATTRIBUTE);
            emptyAttributeCheck(conf.getLocalName(), INPUT_TYPE_ATTRIBUTE, inputType);
            dtableConf.setInputType(DecisionTableInputType.valueOf(inputType));

            String worksheetName = conf.getAttribute(WORKSHEET_NAME_ATTRIBUTE);
            emptyAttributeCheck(conf.getLocalName(), WORKSHEET_NAME_ATTRIBUTE, worksheetName);
            dtableConf.setWorksheetName(worksheetName);

            factory.addPropertyValue("resourceConfiguration", dtableConf);
        }
    }

    return factory.getBeanDefinition();
}

From source file:edu.internet2.middleware.psp.spring.LdapDnFromGrouperNamePSOIdentifierAttributeDefinitionBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(String pluginId, Element pluginConfig, Map<QName, List<Element>> pluginConfigChildren,
        BeanDefinitionBuilder pluginBuilder, ParserContext parserContext) {
    super.doParse(pluginId, pluginConfig, pluginConfigChildren, pluginBuilder, parserContext);

    String baseDn = pluginConfig.getAttributeNS(null, "baseDn");
    LOG.debug("Setting baseDn of element '{}' to: '{}'", pluginConfig.getLocalName(), baseDn);
    pluginBuilder.addPropertyValue("baseDn", baseDn);

    String baseStem = pluginConfig.getAttributeNS(null, "baseStem");
    LOG.debug("Setting baseStem of element '{}' to: '{}'", pluginConfig.getLocalName(), baseStem);
    pluginBuilder.addPropertyValue("baseStem", baseStem);

    String structure = pluginConfig.getAttributeNS(null, "structure");
    LOG.debug("Setting structure of element '{}' to: '{}'", pluginConfig.getLocalName(), structure);
    pluginBuilder.addPropertyValue("structure", structure);

    String rdnAttributeName = pluginConfig.getAttributeNS(null, "rdnAttributeName");
    LOG.debug("Setting rdnAttributeName of element '{}' to: '{}'", pluginConfig.getLocalName(),
            rdnAttributeName);/*from w w  w.  j a v a 2 s .  c o m*/
    pluginBuilder.addPropertyValue("rdnAttributeName", rdnAttributeName);

    String stemRdnAttributeName = pluginConfig.getAttributeNS(null, "stemRdnAttributeName");
    LOG.debug("Setting stemRdnAttributeName of element '{}' to: '{}'", pluginConfig.getLocalName(),
            stemRdnAttributeName);
    pluginBuilder.addPropertyValue("stemRdnAttributeName", stemRdnAttributeName);
}