Search in sources :

Example 21 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project tdi-studio-se by Talend.

the class ExpressionFileOperation method importExpressionFromFile.

/**
     * yzhang Comment method "getExpressionFromFile".
     * 
     * @param file
     * @return
     * @throws IOException
     * @throws SAXException
     * @throws ParserConfigurationException
     */
public List importExpressionFromFile(File file, Shell shell) throws IOException, ParserConfigurationException, SAXException {
    if (file != null) {
        List list = new ArrayList();
        if (!file.isFile()) {
            openDialog(shell);
            return list;
        } else {
            final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
            final Bundle b = Platform.getBundle(PLUGIN_ID);
            final URL url = FileLocator.toFileURL(FileLocator.find(b, new Path(SCHEMA_XSD), null));
            final File schema = new File(url.getPath());
            final Document document = XSDValidator.checkXSD(file, schema);
            final NodeList expressionNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
            "ExpressionFileOperation.expression"));
            if (expressionNodes.getLength() == 1) {
                Node expressionNode = expressionNodes.item(0);
                NamedNodeMap epxressionAttrs = expressionNode.getAttributes();
                Node contentNode = epxressionAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
                "ExpressionFileOperation.content"));
                list.add(contentNode.getNodeValue());
            }
            final NodeList variableNodes = document.getElementsByTagName(Messages.getString(//$NON-NLS-1$
            "ExpressionFileOperation.variable"));
            for (int i = 0; i < variableNodes.getLength(); i++) {
                Node variableNode = variableNodes.item(i);
                NamedNodeMap varAttrs = variableNode.getAttributes();
                //$NON-NLS-1$
                Node nameNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.name"));
                //$NON-NLS-1$
                Node valueNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.value"));
                Node talendTypeNode = varAttrs.getNamedItem(Messages.getString(//$NON-NLS-1$
                "ExpressionFileOperation.talendType"));
                //$NON-NLS-1$
                Node nullableNode = varAttrs.getNamedItem(Messages.getString("ExpressionFileOperation.nullable"));
                Variable variable = new Variable();
                variable.setName(nameNode.getNodeValue());
                variable.setValue(valueNode.getNodeValue());
                variable.setTalendType(talendTypeNode.getNodeValue());
                String s = nullableNode.getNodeValue();
                Boolean boo = Boolean.valueOf(s);
                if (boo == null) {
                    boo = false;
                }
                variable.setNullable(boo);
                list.add(variable);
            }
            return list;
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) Variable(org.talend.commons.runtime.model.expressionbuilder.Variable) Bundle(org.osgi.framework.Bundle) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URL(java.net.URL) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) File(java.io.File)

Example 22 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class DelegationConfig method getAttribute.

private String getAttribute(Node node, String attrName) {
    String value = null;
    NamedNodeMap attrs = node.getAttributes();
    Node nodeID = attrs.getNamedItem(attrName);
    if (nodeID != null) {
        value = nodeID.getNodeValue();
        value = value.trim();
    }
    return value;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node)

Example 23 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project OpenAM by OpenRock.

the class AMPropertySheetModel method parseNodeList.

private void parseNodeList(NodeList nodeList) {
    if (nodeList != null) {
        int length = nodeList.getLength();
        mapOptionList = new HashMap<String, OptionList>();
        for (int i = 0; i < length; i++) {
            Node node = nodeList.item(i);
            // Check node for name attribute.
            if (node.hasAttributes()) {
                NamedNodeMap nodeAttrs = node.getAttributes();
                Node nameNode = nodeAttrs.getNamedItem(NAME_ATTRIBUTE);
                Node tagclassNode = nodeAttrs.getNamedItem(CCDescriptor.CC_ELEMENT_TAGCLASS);
                if ((nameNode != null) && (tagclassNode != null)) {
                    String name = nameNode.getNodeValue();
                    String v = tagclassNode.getNodeValue();
                    if (name.startsWith(DATE_MARKER_NAME)) {
                        String dateName = name.substring(DATE_MARKER_NAME.length());
                        dateComponents.add(dateName);
                    } else if (v != null) {
                        if (v.equals(CCTagClass.EDITABLELIST)) {
                            setModel(name, new CCEditableListModel());
                        } else if (v.equals(CCTagClass.PASSWORD)) {
                            passwordComponents.add(name);
                        } else if (v.equals(CCTagClass.RADIOBUTTON)) {
                            String def = getNodeDefaultValue(node);
                            if (def != null) {
                                radioDefaultValue.put(name, def);
                            }
                        }
                        childMap.put(name, v);
                        NodeList optionElements = ((Element) node).getElementsByTagName(VALUE_OPTION_TAG_NAME);
                        if (optionElements.getLength() > 0) {
                            OptionList optionList = new OptionList();
                            int numOptions = optionElements.getLength();
                            for (int j = 0; j < numOptions; j++) {
                                Node option = optionElements.item(j);
                                if (option.hasAttributes()) {
                                    NamedNodeMap optAttrs = option.getAttributes();
                                    optionList.add(j, optAttrs.getNamedItem(OPTION_LABEL_ATTR_NAME).getNodeValue(), optAttrs.getNamedItem(OPTION_VALUE_ATTR_NAME).getNodeValue());
                                }
                            }
                            mapOptionList.put(name, optionList);
                        }
                    }
                    if (name.equals(TBL_SUB_CONFIG)) {
                        hasSubConfigTable = true;
                    }
                }
            }
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) CCEditableListModel(com.sun.web.ui.model.CCEditableListModel) OptionList(com.iplanet.jato.view.html.OptionList)

Example 24 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project ACS by ACS-Community.

the class LogEntryXML method printNode.

/**
	 * Recursively prints the struct of the node
	 * 
	 * @param logNode The node to print 
	 */
public static void printNode(Node logNode, int depth) {
    String indent = "";
    for (int i = 0; i < depth; i++) indent = indent + "\t";
    System.out.print(indent + "Node name " + logNode.getNodeName());
    System.out.print(", type " + logNode.getNodeType());
    System.out.println(", val  " + logNode.getNodeValue());
    NamedNodeMap map = logNode.getAttributes();
    if (map != null) {
        for (int i = 0; i < map.getLength(); i++) {
            Node nd = map.item(i);
            System.out.print(indent + "\tAttr name " + nd.getNodeName());
            System.out.print(", type " + nd.getNodeType());
            System.out.println(", val  " + nd.getNodeValue());
        }
    }
    NodeList childs = logNode.getChildNodes();
    if (childs != null) {
        for (int i = 0; i < childs.getLength(); i++) {
            printNode(childs.item(i), depth + 1);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) DataNode(com.cosylab.logging.engine.DataNode) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) VectorNodeList(com.cosylab.logging.engine.VectorNodeList)

Example 25 with NamedNodeMap

use of org.w3c.dom.NamedNodeMap in project kotlin by JetBrains.

the class ResourceVisitor method visitElement.

private void visitElement(@NonNull XmlContext context, @NonNull Element element) {
    List<Detector.XmlScanner> elementChecks = mElementToCheck.get(element.getTagName());
    if (elementChecks != null) {
        assert elementChecks instanceof RandomAccess;
        for (XmlScanner check : elementChecks) {
            check.visitElement(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElement(context, element);
        }
    }
    if (!mAttributeToCheck.isEmpty() || !mAllAttributeDetectors.isEmpty()) {
        NamedNodeMap attributes = element.getAttributes();
        for (int i = 0, n = attributes.getLength(); i < n; i++) {
            Attr attribute = (Attr) attributes.item(i);
            String name = attribute.getLocalName();
            if (name == null) {
                name = attribute.getName();
            }
            List<Detector.XmlScanner> list = mAttributeToCheck.get(name);
            if (list != null) {
                for (XmlScanner check : list) {
                    check.visitAttribute(context, attribute);
                }
            }
            if (!mAllAttributeDetectors.isEmpty()) {
                for (XmlScanner check : mAllAttributeDetectors) {
                    check.visitAttribute(context, attribute);
                }
            }
        }
    }
    // Visit children
    NodeList childNodes = element.getChildNodes();
    for (int i = 0, n = childNodes.getLength(); i < n; i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            visitElement(context, (Element) child);
        }
    }
    // Post hooks
    if (elementChecks != null) {
        for (XmlScanner check : elementChecks) {
            check.visitElementAfter(context, element);
        }
    }
    if (!mAllElementDetectors.isEmpty()) {
        for (XmlScanner check : mAllElementDetectors) {
            check.visitElementAfter(context, element);
        }
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) XmlScanner(com.android.tools.klint.detector.api.Detector.XmlScanner) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RandomAccess(java.util.RandomAccess) Attr(org.w3c.dom.Attr)

Aggregations

NamedNodeMap (org.w3c.dom.NamedNodeMap)991 Node (org.w3c.dom.Node)688 NodeList (org.w3c.dom.NodeList)338 Attr (org.w3c.dom.Attr)295 Element (org.w3c.dom.Element)237 Document (org.w3c.dom.Document)153 ArrayList (java.util.ArrayList)92 HashMap (java.util.HashMap)91 DocumentBuilder (javax.xml.parsers.DocumentBuilder)59 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)58 IOException (java.io.IOException)53 SAXException (org.xml.sax.SAXException)41 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)40 List (java.util.List)36 Map (java.util.Map)33 File (java.io.File)27 InputStream (java.io.InputStream)26 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)25 DOMException (org.w3c.dom.DOMException)25 ByteArrayInputStream (java.io.ByteArrayInputStream)19