Example usage for org.w3c.dom Element getAttributes

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

Introduction

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

Prototype

public NamedNodeMap getAttributes();

Source Link

Document

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

Usage

From source file:fi.csc.kapaVirtaAS.MessageTransformer.java

public String transform(String message, MessageDirection direction) throws Exception {
    try {/*from  w ww.  ja v a2s. co m*/
        DocumentBuilder dBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document doc = dBuilder
                .parse(new InputSource(new ByteArrayInputStream(stripXmlDefinition(message).getBytes())));
        doc.setXmlVersion("1.0");
        doc.normalizeDocument();
        Element root = doc.getDocumentElement();

        if (direction == MessageDirection.XRoadToVirta) {
            // Save XRoad schema prefix for response message
            xroadSchemaPrefix = namedNodeMapToStream(root.getAttributes())
                    .filter(node -> node
                            .getNodeValue().toLowerCase().contains(conf.getXroadSchema().toLowerCase()))
                    .findFirst()
                    .orElseThrow(
                            () -> new DOMException(DOMException.NOT_FOUND_ERR, "Xroad schema prefix not found"))
                    .getNodeName();

            xroadIdSchemaPrefix = namedNodeMapToStream(root.getAttributes())
                    .filter(node -> node.getNodeValue().toLowerCase()
                            .contains(conf.getXroadIdSchema().toLowerCase()))
                    .findFirst().orElseThrow(() -> new DOMException(DOMException.NOT_FOUND_ERR,
                            "XroadId schema prefix not found"))
                    .getNodeName();

            // Change tns schema
            getNodeByKeyword(namedNodeMapToStream(root.getAttributes()), conf.getAdapterServiceSchema())
                    .map(attribute -> setNodeValueToNode(attribute, conf.getVirtaServiceSchema()));

            //There should be two children under the root node: header and body
            for (int i = 0; i < root.getChildNodes().getLength(); ++i) {
                Node child = root.getChildNodes().item(i);
                // Save soap-headers for reply message and remove child elements under soap-headers
                if (child.getNodeName().toLowerCase().contains("header")) {
                    this.xroadHeaderElement = child.cloneNode(true);
                    root.replaceChild(child.cloneNode(false), child);
                }
                // Change SOAP-body
                else if (child.getNodeName().toLowerCase().contains("body")) {
                    for (int j = 0; j < child.getChildNodes().getLength(); ++j) {
                        if (child.getChildNodes().item(j).getNodeType() == Node.ELEMENT_NODE) {
                            doc.renameNode(child.getChildNodes().item(j), conf.getVirtaServiceSchema(),
                                    child.getChildNodes().item(j).getNodeName() + "Request");
                            break;
                        }
                    }

                }
            }
        }
        if (direction == MessageDirection.VirtaToXRoad) {
            // Add XRoad schemas with saved prefix to response message
            root.setAttribute(xroadSchemaPrefix, conf.getXroadSchema());
            root.setAttribute(xroadIdSchemaPrefix, conf.getXroadIdSchema());

            // Change tns schema
            getNodeByKeyword(namedNodeMapToStream(root.getAttributes()), conf.getVirtaServiceSchema())
                    .map(attribute -> setNodeValueToNode(attribute, conf.getAdapterServiceSchema()));

            // Change SOAP-headers
            Node headerNode = getNodeByKeyword(nodeListToStream(root.getChildNodes()), "header").get();
            for (int i = 0; i < this.xroadHeaderElement.getChildNodes().getLength(); ++i) {
                headerNode.appendChild(doc.importNode(this.xroadHeaderElement.getChildNodes().item(i), true));
            }

            // Change SOAP-body
            getNodeByKeyword(nodeListToStream(root.getChildNodes()), "body")
                    .map(bodyNode -> removeAttribureFromElement(nodeToElement(bodyNode), virtaServicePrefix))
                    .map(bodyNode -> setAttributeToElement(nodeToElement(bodyNode), virtaServicePrefix,
                            conf.getAdapterServiceSchema()));

            //Virta gives malformed soap fault message. Need to parse it correct.
            getNodeByKeyword(nodeListToStream(root.getChildNodes()), "body")
                    .map(bodyNode -> nodeListToStream(bodyNode.getChildNodes())).map(
                            nodesInBodyStream -> getNodeByKeyword(nodesInBodyStream, "fault")
                                    .map(faultNode -> removeAttribureFromElement(
                                            nodeToElement(nodeToElement(faultNode)
                                                    .getElementsByTagName("faultstring").item(0)),
                                            "xml:lang")));
        }

        doc.normalizeDocument();
        DOMSource domSource = new DOMSource(doc);
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(domSource, result);
        message = writer.toString();

        return stripXmlDefinition(message);
    } catch (Exception e) {
        if (direction == MessageDirection.XRoadToVirta) {
            log.error("Error in parsing request message.");
            throw e;
        } else {
            log.error("Error in parsing response message");
            log.error(e.toString());
            return stripXmlDefinition(faultMessageService.generateSOAPFault(message,
                    faultMessageService.getResValidFail(), this.xroadHeaderElement));
        }
    }
}

From source file:com.amalto.workbench.actions.XSDAddComplexTypeElementAction.java

public Map<String, List<String>> cloneXSDAnnotation(XSDAnnotation oldAnn) {
    Map<String, List<String>> infor = new HashMap<String, List<String>>();
    try {//from www. j  av a2s .c  om
        if (oldAnn != null) {
            for (int i = 0; i < oldAnn.getApplicationInformation().size(); i++) {
                Element oldElem = oldAnn.getApplicationInformation().get(i);
                String type = oldElem.getAttributes().getNamedItem("source").getNodeValue(); //$NON-NLS-1$
                // X_Write,X_Hide,X_Workflow
                if (type.equals("X_Write") || type.equals("X_Hide") || type.equals("X_Workflow")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    if (!infor.containsKey(type)) {
                        List<String> typeList = new ArrayList<String>();
                        typeList.add(oldElem.getFirstChild().getNodeValue());
                        infor.put(type, typeList);
                    } else {
                        (infor.get(type)).add(oldElem.getFirstChild().getNodeValue());
                    }
                }
            }
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(this.page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages._PasteError, e.getLocalizedMessage()));
    }
    return infor;
}

From source file:com.amalto.core.storage.hibernate.DefaultStorageClassLoader.java

public Document generateHibernateConfiguration(RDBMSDataSource rdbmsDataSource)
        throws ParserConfigurationException, SAXException, IOException, XPathExpressionException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from   w  ww  .  j av  a 2s .  c  o m
    factory.setExpandEntityReferences(false);

    DocumentBuilder documentBuilder = factory.newDocumentBuilder();
    documentBuilder.setEntityResolver(HibernateStorage.ENTITY_RESOLVER);
    Document document = documentBuilder
            .parse(DefaultStorageClassLoader.class.getResourceAsStream(HIBERNATE_CONFIG_TEMPLATE));
    String connectionUrl = rdbmsDataSource.getConnectionURL();
    String userName = rdbmsDataSource.getUserName();
    String driverClass = rdbmsDataSource.getDriverClassName();
    RDBMSDataSource.DataSourceDialect dialectType = rdbmsDataSource.getDialectName();
    String dialect = getDialect(dialectType);
    String password = rdbmsDataSource.getPassword();
    String indexBase = rdbmsDataSource.getIndexDirectory();
    int connectionPoolMinSize = rdbmsDataSource.getConnectionPoolMinSize();
    int connectionPoolMaxSize = rdbmsDataSource.getConnectionPoolMaxSize();
    if (connectionPoolMaxSize == 0) {
        LOGGER.info("No value provided for property connectionPoolMaxSize of datasource " //$NON-NLS-1$
                + rdbmsDataSource.getName() + ". Using default value: " //$NON-NLS-1$
                + RDBMSDataSourceBuilder.CONNECTION_POOL_MAX_SIZE_DEFAULT);
        connectionPoolMaxSize = RDBMSDataSourceBuilder.CONNECTION_POOL_MAX_SIZE_DEFAULT;
    }

    setPropertyValue(document, "hibernate.connection.url", connectionUrl); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.connection.username", userName); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.connection.driver_class", driverClass); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.dialect", dialect); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.connection.password", password); //$NON-NLS-1$
    // Sets up DBCP pool features
    setPropertyValue(document, "hibernate.dbcp.initialSize", String.valueOf(connectionPoolMinSize)); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.dbcp.maxActive", String.valueOf(connectionPoolMaxSize)); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.dbcp.maxIdle", String.valueOf(10)); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.dbcp.maxTotal", String.valueOf(connectionPoolMaxSize)); //$NON-NLS-1$
    setPropertyValue(document, "hibernate.dbcp.maxWaitMillis", "60000"); //$NON-NLS-1$ //$NON-NLS-2$

    Node sessionFactoryElement = document.getElementsByTagName("session-factory").item(0); //$NON-NLS-1$
    if (rdbmsDataSource.supportFullText()) {
        /*
        <property name="hibernate.search.default.directory_provider" value="filesystem"/>
        <property name="hibernate.search.default.indexBase" value="/var/lucene/indexes"/>
         */
        addProperty(document, sessionFactoryElement, "hibernate.search.default.directory_provider", //$NON-NLS-1$
                "filesystem"); //$NON-NLS-1$
        addProperty(document, sessionFactoryElement, "hibernate.search.default.indexBase", //$NON-NLS-1$
                indexBase + '/' + storageName);
        addProperty(document, sessionFactoryElement, "hibernate.search.default.sourceBase", //$NON-NLS-1$
                indexBase + '/' + storageName);
        addProperty(document, sessionFactoryElement, "hibernate.search.default.source", ""); //$NON-NLS-1$ //$NON-NLS-2$
        addProperty(document, sessionFactoryElement, "hibernate.search.default.exclusive_index_use", "false"); //$NON-NLS-1$ //$NON-NLS-2$
        addProperty(document, sessionFactoryElement, "hibernate.search.lucene_version", "LUCENE_CURRENT"); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        addProperty(document, sessionFactoryElement, "hibernate.search.autoregister_listeners", "false"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    if (dataSource.getCacheDirectory() != null && !dataSource.getCacheDirectory().isEmpty()) {
        /*
        <!-- Second level cache -->
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
        <property name="hibernate.cache.use_query_cache">true</property>
        <property name="net.sf.ehcache.configurationResourceName">ehcache.xml</property>
         */
        addProperty(document, sessionFactoryElement, "hibernate.cache.use_second_level_cache", "true"); //$NON-NLS-1$ //$NON-NLS-2$
        addProperty(document, sessionFactoryElement, "hibernate.cache.provider_class", //$NON-NLS-1$
                "net.sf.ehcache.hibernate.EhCacheProvider"); //$NON-NLS-1$
        addProperty(document, sessionFactoryElement, "hibernate.cache.use_query_cache", "true"); //$NON-NLS-1$ //$NON-NLS-2$
        addProperty(document, sessionFactoryElement, "net.sf.ehcache.configurationResourceName", "ehcache.xml"); //$NON-NLS-1$ //$NON-NLS-2$
    } else {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(
                    "Hibernate configuration does not define second level cache extensions due to datasource configuration."); //$NON-NLS-1$
        }
        addProperty(document, sessionFactoryElement, "hibernate.cache.use_second_level_cache", "false"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    // Override default configuration with values from configuration
    Map<String, String> advancedProperties = rdbmsDataSource.getAdvancedProperties();
    for (Map.Entry<String, String> currentAdvancedProperty : advancedProperties.entrySet()) {
        setPropertyValue(document, currentAdvancedProperty.getKey(), currentAdvancedProperty.getValue());
    }
    // Order of elements highly matters and mapping shall be declared after <property/> and before <event/>.
    Element mapping = document.createElement("mapping"); //$NON-NLS-1$
    Attr resource = document.createAttribute("resource"); //$NON-NLS-1$
    resource.setValue(HIBERNATE_MAPPING);
    mapping.getAttributes().setNamedItem(resource);
    sessionFactoryElement.appendChild(mapping);

    if (rdbmsDataSource.supportFullText()) {
        addEvent(document, sessionFactoryElement, "post-update", //$NON-NLS-1$
                "org.hibernate.search.event.FullTextIndexEventListener"); //$NON-NLS-1$
        addEvent(document, sessionFactoryElement, "post-insert", //$NON-NLS-1$
                "org.hibernate.search.event.FullTextIndexEventListener"); //$NON-NLS-1$
        addEvent(document, sessionFactoryElement, "post-delete", //$NON-NLS-1$
                "org.hibernate.search.event.FullTextIndexEventListener"); //$NON-NLS-1$
    } else if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(
                "Hibernate configuration does not define full text extensions due to datasource configuration."); //$NON-NLS-1$
    }

    return document;
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleDefaultsEventMeta(Configuration configuration, Element parentElement) {
    DOMElementIterator nodeIterator = new DOMElementIterator(parentElement.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("class-property-resolution")) {
            Node styleNode = subElement.getAttributes().getNamedItem("style");
            if (styleNode != null) {
                String styleText = styleNode.getTextContent();
                Configuration.PropertyResolutionStyle value = Configuration.PropertyResolutionStyle
                        .valueOf(styleText.toUpperCase());
                configuration.getEngineDefaults().getEventMeta().setClassPropertyResolutionStyle(value);
            }/* w  w  w  .  j a v a 2s . c o  m*/

            Node accessorStyleNode = subElement.getAttributes().getNamedItem("accessor-style");
            if (accessorStyleNode != null) {
                String accessorStyleText = accessorStyleNode.getTextContent();
                ConfigurationEventTypeLegacy.AccessorStyle value = ConfigurationEventTypeLegacy.AccessorStyle
                        .valueOf(accessorStyleText.toUpperCase());
                configuration.getEngineDefaults().getEventMeta().setDefaultAccessorStyle(value);
            }
        }

        if (subElement.getNodeName().equals("event-representation")) {
            Node typeNode = subElement.getAttributes().getNamedItem("type");
            if (typeNode != null) {
                String typeText = typeNode.getTextContent();
                Configuration.EventRepresentation value = Configuration.EventRepresentation
                        .valueOf(typeText.toUpperCase());
                configuration.getEngineDefaults().getEventMeta().setDefaultEventRepresentation(value);
            }
        }

        if (subElement.getNodeName().equals("anonymous-cache")) {
            Node sizeNode = subElement.getAttributes().getNamedItem("size");
            if (sizeNode != null) {
                configuration.getEngineDefaults().getEventMeta()
                        .setAnonymousCacheSize(Integer.parseInt(sizeNode.getTextContent()));
            }
        }
    }
}

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

protected String getLableForElement(Element element) {
    try {//from www  . java 2  s .  c  om
        if (element.getLocalName().equals("documentation")) {//$NON-NLS-1$
            return "Documentation: " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
        } else if (element.getLocalName().equals("appinfo")) {//$NON-NLS-1$
            String source = element.getAttribute("source");//$NON-NLS-1$
            if (source != null) {
                if (source.startsWith("X_Label_")) {//$NON-NLS-1$
                    return Util.iso2lang.get(source.substring(8).toLowerCase()) + " Label: "//$NON-NLS-1$
                            + element.getChildNodes().item(0).getNodeValue();
                } else if (source.equals("X_ForeignKey")) {//$NON-NLS-1$
                    return "Foreign Key:  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_ForeignKeyInfo")) {//$NON-NLS-1$
                    return "Foreign Key Info:  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_SourceSystem")) {//$NON-NLS-1$
                    return "Source System:  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_TargetSystem")) {//$NON-NLS-1$
                    return "Target System(s):  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.startsWith("X_Description_")) {//$NON-NLS-1$
                    return Util.iso2lang.get(source.substring(14).toLowerCase()) + " Description: "//$NON-NLS-1$
                            + element.getChildNodes().item(0).getNodeValue();
                } else if (source.equals("X_Write")) {//$NON-NLS-1$
                    return "Writable By : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_Lookup_Field")) {//$NON-NLS-1$
                    return "Look Field : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_Workflow")) {//$NON-NLS-1$
                    return "Workflow access : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_Hide")) {//$NON-NLS-1$
                    return "No Access to : " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$

                } else if (source.startsWith("X_Facet")) {//$NON-NLS-1$
                    return source.substring(2, 7) + "_Msg_" + source.substring(8) + ": "//$NON-NLS-1$//$NON-NLS-2$
                            + element.getChildNodes().item(0).getNodeValue();

                } else if (source.startsWith("X_Display_Format_")) {//$NON-NLS-1$
                    return source + ": " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_Schematron")) {//$NON-NLS-1$

                    String pattern = (String) element.getFirstChild().getUserData("pattern_name");//$NON-NLS-1$
                    if (pattern == null) {
                        Element el = Util.parse(element.getChildNodes().item(0).getNodeValue())
                                .getDocumentElement();
                        if (el.getAttributes().getNamedItem("name") != null)//$NON-NLS-1$
                            pattern = el.getAttributes().getNamedItem("name").getTextContent();//$NON-NLS-1$
                    }
                    return "Validation Rule: " + (pattern == null ? "" : pattern);//$NON-NLS-1$//$NON-NLS-2$
                } else if (source.equals("X_Retrieve_FKinfos")) {//$NON-NLS-1$
                    return "Foreign Key resolution:  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else if (source.equals("X_FKIntegrity")) {//$NON-NLS-1$
                    return "Foreign Key integrity:  " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$
                } else if (source.equals("X_FKIntegrity_Override")) {//$NON-NLS-1$
                    return "Foreign Key integrity override:  " + element.getChildNodes().item(0).getNodeValue(); //$NON-NLS-1$
                }
                if (source.equals("X_ForeignKey_Filter")) {//$NON-NLS-1$
                    return "Foreign Key Filter:  " + element.getChildNodes().item(0).getNodeValue();//$NON-NLS-1$
                } else {
                    return source + ": " + Util.nodeToString(element);//$NON-NLS-1$
                }
            } else {
                return Util.nodeToString(element);
            }
        } else {
            return Util.nodeToString(element);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }

    return "?? " + element.getClass().getName() + " : " + element.toString();//$NON-NLS-1$//$NON-NLS-2$
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleVariantStream(Configuration configuration, Element element) {
    ConfigurationVariantStream variantStream = new ConfigurationVariantStream();
    String varianceName = getRequiredAttribute(element, "name");

    if (element.getAttributes().getNamedItem("type-variance") != null) {
        String typeVar = element.getAttributes().getNamedItem("type-variance").getTextContent();
        ConfigurationVariantStream.TypeVariance typeVarianceEnum;
        try {/* www  . jav a 2s .co m*/
            typeVarianceEnum = ConfigurationVariantStream.TypeVariance.valueOf(typeVar.trim().toUpperCase());
            variantStream.setTypeVariance(typeVarianceEnum);
        } catch (RuntimeException ex) {
            throw new ConfigurationException(
                    "Invalid enumeration value for type-variance attribute '" + typeVar + "'");
        }
    }

    DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes());
    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("variant-event-type")) {
            String name = subElement.getAttributes().getNamedItem("name").getTextContent();
            variantStream.addEventTypeName(name);
        }
    }

    configuration.addVariantStream(varianceName, variantStream);
}

From source file:com.wwpass.connection.WWPassConnection.java

private static InputStream getReplyData(final InputStream rawXMLInput)
        throws IOException, WWPassProtocolException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    Document dom;/*ww  w.j  a va  2s . c o m*/
    InputStream is = null;

    try {
        DocumentBuilder db = dbf.newDocumentBuilder();

        is = rawXMLInput;

        dom = db.parse(is);

        Element docEle = dom.getDocumentElement();

        Node result = docEle.getElementsByTagName("result").item(0);
        boolean res = result.getTextContent().equalsIgnoreCase("true");

        Element data = (Element) docEle.getElementsByTagName("data").item(0);
        String encoding = data.getAttributes().getNamedItem("encoding").getTextContent();
        String strData;
        byte[] bb;
        if ("base64".equalsIgnoreCase(encoding)) {
            bb = (new Base64()).decode(data.getTextContent());
            strData = new String(bb, Charset.forName("UTF-8"));
            if (!res) {
                throw new WWPassProtocolException("SPFE returned error: " + strData);
            }
            return new ByteArrayInputStream(bb);
        } else {
            strData = data.getTextContent();
            if (!res) {
                throw new WWPassProtocolException("SPFE returned error: " + strData);
            }
            return new ByteArrayInputStream(strData.getBytes());
        }

    } catch (ParserConfigurationException pce) {
        throw new WWPassProtocolException("Malformed SPFE reply: " + pce.getMessage());
    } catch (SAXException se) {
        throw new WWPassProtocolException("Malformed SPFE reply: " + se.getMessage());
    } finally {
        if (is != null) {
            is.close();
        }
    }
}

From source file:edu.lternet.pasta.datapackagemanager.LevelOneEMLFactory.java

private void modifyAccessElementAttributes(Document emlDocument) throws TransformerException {
    CachedXPathAPI xpathapi = new CachedXPathAPI();

    // Parse the access elements
    NodeList accessNodeList = xpathapi.selectNodeList(emlDocument, ACCESS_PATH);
    if (accessNodeList != null) {
        for (int i = 0; i < accessNodeList.getLength(); i++) {
            boolean hasSystemAttribute = false;
            Element accessElement = (Element) accessNodeList.item(i);
            NamedNodeMap accessAttributesList = accessElement.getAttributes();

            for (int j = 0; j < accessAttributesList.getLength(); j++) {
                Node attributeNode = accessAttributesList.item(j);
                String nodeName = attributeNode.getNodeName();
                String nodeValue = attributeNode.getNodeValue();
                if (nodeName.equals("authSystem")) {
                    attributeNode.setNodeValue(LEVEL_ONE_AUTH_SYSTEM_ATTRIBUTE);
                } else if (nodeName.equals("system")) {
                    attributeNode.setNodeValue(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                    hasSystemAttribute = true;
                }/* w w w .  ja v  a 2  s. c  om*/
            }

            /*
             * No @system attribute was found in the access element, so we
             * need to add one.
             */
            if (!hasSystemAttribute) {
                Attr systemAttribute = emlDocument.createAttribute("system");
                systemAttribute.setTextContent(LEVEL_ONE_SYSTEM_ATTRIBUTE);
                accessElement.setAttributeNode(systemAttribute);
            }
        }
    }
}

From source file:com.espertech.esper.client.ConfigurationParser.java

private static void handleRevisionEventType(Configuration configuration, Element element) {
    ConfigurationRevisionEventType revEventType = new ConfigurationRevisionEventType();
    String revTypeName = getRequiredAttribute(element, "name");

    if (element.getAttributes().getNamedItem("property-revision") != null) {
        String propertyRevision = element.getAttributes().getNamedItem("property-revision").getTextContent();
        ConfigurationRevisionEventType.PropertyRevision propertyRevisionEnum;
        try {//ww  w  .  j a v a2s.  c  om
            propertyRevisionEnum = ConfigurationRevisionEventType.PropertyRevision
                    .valueOf(propertyRevision.trim().toUpperCase());
            revEventType.setPropertyRevision(propertyRevisionEnum);
        } catch (RuntimeException ex) {
            throw new ConfigurationException(
                    "Invalid enumeration value for property-revision attribute '" + propertyRevision + "'");
        }
    }

    DOMElementIterator nodeIterator = new DOMElementIterator(element.getChildNodes());
    Set<String> keyProperties = new HashSet<String>();

    while (nodeIterator.hasNext()) {
        Element subElement = nodeIterator.next();
        if (subElement.getNodeName().equals("base-event-type")) {
            String name = getRequiredAttribute(subElement, "name");
            revEventType.addNameBaseEventType(name);
        }
        if (subElement.getNodeName().equals("delta-event-type")) {
            String name = getRequiredAttribute(subElement, "name");
            revEventType.addNameDeltaEventType(name);
        }
        if (subElement.getNodeName().equals("key-property")) {
            String name = getRequiredAttribute(subElement, "name");
            keyProperties.add(name);
        }
    }

    String[] keyProps = keyProperties.toArray(new String[keyProperties.size()]);
    revEventType.setKeyPropertyNames(keyProps);

    configuration.addRevisionEventType(revTypeName, revEventType);
}

From source file:org.hdiv.config.xml.EditableValidationsBeanDefinitionParser.java

protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {

    Object source = parserContext.extractSource(element);

    Map map = new Hashtable();
    bean.addPropertyValue("rawUrls", map);
    bean.setInitMethodName("init");

    // Register default editable validation
    boolean registerDefaults = true;
    String registerDefaultsValue = element.getAttributes().getNamedItem("registerDefaults").getTextContent();
    if (registerDefaultsValue != null) {
        registerDefaults = Boolean.TRUE.toString().equalsIgnoreCase(registerDefaultsValue);
    }/*from   w w w. j  a v  a  2 s.  com*/

    if (registerDefaults) {
        // Create beans for default validations
        createDefaultEditableValidations(element, parserContext);
    }

    NodeList list = element.getChildNodes();

    for (int i = 0; i < list.getLength(); i++) {
        Node node = list.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            if (node.getLocalName().equalsIgnoreCase("validationRule")) {

                this.processValidationRule(node, bean, map);
            }
        }
    }

    if (this.springMvcPresent) {
        parserContext.getRegistry().registerBeanDefinition("hdivEditableValidator",
                this.createValidator(element, source, parserContext));
    }
}