Java Code Examples for org.w3c.dom.Node.ELEMENT_NODE

The following are Jave code examples for showing how to use ELEMENT_NODE of the org.w3c.dom.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ciguan   File: AsUtil.java   View Source Code Vote up 7 votes
/**
 * Method removed when ref removed from configuration, only used for menu... separator, languages
 */
@Deprecated
public static void makeIdMap(Node pElement, Map<String, CwfDataIf> pIdMap) {
    if (pElement.getNodeType() == Node.ELEMENT_NODE) {
        String tTagName = ((Element) pElement).getTagName();
        String tId = ((Element) pElement).getAttribute("id");
        if (!tId.isEmpty() && tTagName.equals(TAG_MENUITEM)) {
            CwfDataIf tData = CwfDataFactory.create();
            tData.setProperty(ATTR_TAG_NAME, TAG_MENUITEM);
            for (int i = 0; i < pElement.getAttributes().getLength(); i++) {
                Attr tAttr = (Attr) pElement.getAttributes().item(i);
                tData.setProperty(tAttr.getName(), tAttr.getValue());
            }
            pIdMap.put(tId, tData);

        }
        NodeList tNodes = pElement.getChildNodes();
        for (int i = 0; i < tNodes.getLength(); i++) {
            makeIdMap(tNodes.item(i), pIdMap);
        }
    }
}
 
Example 2
Project: springbootWeb   File: MyBatisGeneratorConfigurationParser.java   View Source Code Vote up 6 votes
private void parseIgnoreColumnByRegex(TableConfiguration tc, Node node) {
    Properties attributes = parseAttributes(node);
    String pattern = attributes.getProperty("pattern"); //$NON-NLS-1$

    IgnoredColumnPattern icPattern = new IgnoredColumnPattern(pattern);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("except".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseException(icPattern, childNode);
        }
    }

    tc.addIgnoredColumnPattern(icPattern);
}
 
Example 3
Project: OpenJSharp   File: DocumentImpl.java   View Source Code Vote up 6 votes
/**
 * Dispatches event to the target node's descendents recursively
 *
 * @param n node to dispatch to
 * @param e event to be sent to that node and its subtree
 */
protected void dispatchingEventToSubtree(Node n, Event e) {
    if (n==null)
            return;

    // ***** Recursive implementation. This is excessively expensive,
    // and should be replaced in conjunction with optimization
    // mentioned above.
    ((NodeImpl) n).dispatchEvent(e);
    if (n.getNodeType() == Node.ELEMENT_NODE) {
        NamedNodeMap a = n.getAttributes();
        for (int i = a.getLength() - 1; i >= 0; --i)
            dispatchingEventToSubtree(a.item(i), e);
    }
    dispatchingEventToSubtree(n.getFirstChild(), e);
    dispatchingEventToSubtree(n.getNextSibling(), e);
}
 
Example 4
Project: Shopping-Cart-using-Web-Services   File: MyClientRest.java   View Source Code Vote up 6 votes
private void parseCartList(String xml){
	cartList = new ArrayList<String>();
	//get the factory
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	try {
		DocumentBuilder db = dbf.newDocumentBuilder();
		domCL = db.parse(new InputSource(new StringReader(xml)));
		domCL.getDocumentElement().normalize();
		
		NodeList nList = domCL.getElementsByTagName("item");
	    for (int temp = 0; temp < nList.getLength(); temp++) {
	        Node nNode = nList.item(temp);
	        if (nNode.getNodeType() == Node.ELEMENT_NODE) {
	        	Element eElement = (Element) nNode; 
	        	//put cart items in list
	        	String accum = ""+eElement.getElementsByTagName("type").item(0).getTextContent() + " / " +
	        			eElement.getElementsByTagName("make").item(0).getTextContent() + " / " +
	        			eElement.getElementsByTagName("model").item(0).getTextContent()+ " / " +
	        			eElement.getElementsByTagName("price").item(0).getTextContent(); 
	        	cartList.add(accum);
	         }
	    }
	    //catch total price and item returned from server
	    totalPrice=domCL.getElementsByTagName("totalcost").item(0).getTextContent();
	    totalItem=domCL.getElementsByTagName("totalitem").item(0).getTextContent();
	    
	}catch(ParserConfigurationException pce) {			pce.printStackTrace();
	}catch(SAXException se) {							se.printStackTrace();
	}catch(IOException ioe) {							ioe.printStackTrace();
	}catch (Exception e){								e.printStackTrace();
	}
}
 
Example 5
Project: generator_mybatis   File: IbatorConfigurationParser.java   View Source Code Vote up 6 votes
public Configuration parseIbatorConfiguration(Element rootNode)
        throws XMLParserException {

    Configuration configuration = new Configuration();

    NodeList nodeList = rootNode.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("properties".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperties(configuration, childNode);
        } else if ("classPathEntry".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseClassPathEntry(configuration, childNode);
        } else if ("ibatorContext".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseIbatorContext(configuration, childNode);
        }
    }

    return configuration;
}
 
Example 6
Project: dacapobench   File: RuleSetFactory.java   View Source Code Vote up 6 votes
/**
 * Parse a property node
 * @param rule the rule being constructed
 * @param propertyNode must be a property element node
 */
private void parsePropertyNode(Rule rule, Node propertyNode) {
    Element propertyElement = (Element) propertyNode;
    String name = propertyElement.getAttribute("name");
    String value = propertyElement.getAttribute("value");
    if (value.trim().length() == 0) {
        NodeList nodeList = propertyNode.getChildNodes();
        for (int i = 0; i < nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if ((node.getNodeType() == Node.ELEMENT_NODE) && (node.getNodeName().equals("value"))) {
                value = parseValueNode(node);
            }
        }
    }
    if (propertyElement.hasAttribute("pluginname")) {
        rule.addProperty("pluginname", propertyElement.getAttributeNode("pluginname").getNodeValue());
    }
    rule.addProperty(name, value);
}
 
Example 7
Project: Tarski   File: XMLDOMHelper.java   View Source Code Vote up 5 votes
/**
 * Find the named subnode in a node's sublist.
 * <ul>
 * <li>Ignores comments and processing instructions.
 * <li>Ignores TEXT nodes (likely to exist and contain ignorable whitespace, if not validating.
 * <li>Ignores CDATA nodes and EntityRef nodes.
 * <li>Examines element nodes to find one with the specified name.
 * </ul>
 * 
 * @param name the tag name for the element to find
 * @param node the element node to start searching from
 * @return the Node found
 */
public static Node findNode(String name, Node node) {
  // get all child nodes
  NodeList list = node.getChildNodes();

  for (int i = 0; i < list.getLength(); i++) {
    // get child node
    Node childNode = list.item(i);

    if (childNode.getNodeType() == Node.ELEMENT_NODE) {
      Element element = (Element) childNode;
      if (element.hasAttributes()) {
        if (element.hasAttribute("id") && element.getAttribute("id") != null
            && !element.getAttribute("id").isEmpty() && element.getAttribute("id").equals(name)) {
          return element;
        } else if (element.hasAttribute("name") && element.getAttribute("name") != null
            && !element.getAttribute("name").isEmpty()
            && element.getAttribute("name").equals(name)) {
          return element;
        }
      }
    }
    // visit child node
    Node temp = findNode(name, childNode);
    if (temp != null)
      return temp;
  }
  return null;
}
 
Example 8
Project: MybatisGeneatorUtil   File: MyBatisGeneratorConfigurationParser.java   View Source Code Vote up 5 votes
private void parseJavaClientGenerator(Context context, Node node) {
    JavaClientGeneratorConfiguration javaClientGeneratorConfiguration = new JavaClientGeneratorConfiguration();

    context.setJavaClientGeneratorConfiguration(javaClientGeneratorConfiguration);

    Properties attributes = parseAttributes(node);
    String type = attributes.getProperty("type"); //$NON-NLS-1$
    String targetPackage = attributes.getProperty("targetPackage"); //$NON-NLS-1$
    String targetProject = attributes.getProperty("targetProject"); //$NON-NLS-1$
    String implementationPackage = attributes
            .getProperty("implementationPackage"); //$NON-NLS-1$

    javaClientGeneratorConfiguration.setConfigurationType(type);
    javaClientGeneratorConfiguration.setTargetPackage(targetPackage);
    javaClientGeneratorConfiguration.setTargetProject(targetProject);
    javaClientGeneratorConfiguration
            .setImplementationPackage(implementationPackage);

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(javaClientGeneratorConfiguration, childNode);
        }
    }
}
 
Example 9
Project: geomapapp   File: XML_Menu.java   View Source Code Vote up 5 votes
private static List<Node> getElements(Node node, String elementName) {
	List<Node> list = new LinkedList<Node>();
	NodeList nodeList = node.getChildNodes();
	for (int i = 0; i < nodeList.getLength(); i++)
		if (nodeList.item(i).getNodeName().equals(elementName)
				&& nodeList.item(i).getNodeType() == Node.ELEMENT_NODE)
			list.add(nodeList.item(i));
	return list;
}
 
Example 10
Project: OpenJSharp   File: KeyInfo.java   View Source Code Vote up 5 votes
/**
 * Searches the per-KeyInfo KeyResolvers for public keys
 *
 * @return The public key contained in this Node.
 * @throws KeyResolverException
 */
PublicKey getPublicKeyFromInternalResolvers() throws KeyResolverException {
    for (KeyResolverSpi keyResolver : internalKeyResolvers) {
        if (log.isLoggable(java.util.logging.Level.FINE)) {
            log.log(java.util.logging.Level.FINE, "Try " + keyResolver.getClass().getName());
        }
        keyResolver.setSecureValidation(secureValidation);
        Node currentChild = this.constructionElement.getFirstChild();
        String uri = this.getBaseURI();
        while (currentChild != null)      {
            if (currentChild.getNodeType() == Node.ELEMENT_NODE) {
                for (StorageResolver storage : storageResolvers) {
                    PublicKey pk =
                        keyResolver.engineLookupAndResolvePublicKey(
                            (Element) currentChild, uri, storage
                        );

                    if (pk != null) {
                        return pk;
                    }
                }
            }
            currentChild = currentChild.getNextSibling();
        }
    }

    return null;
}
 
Example 11
Project: openrasp   File: TomcatSecurityChecker.java   View Source Code Vote up 5 votes
/**
 * 检测tomcat后台管理员角色密码是否安全
 */
private void checkManagerPassword(String tomcatBaseDir, List<EventInfo> infos) {
    File userFile = new File(tomcatBaseDir + File.separator + "conf/tomcat-users.xml");
    if (!(userFile.exists() && userFile.canRead())) {
        LOGGER.warn(getJsonFormattedMessage(TOMCAT_CHECK_ERROR_LOG_CHANNEL,
                "can not load file conf/tomcat-users.xml"));
        return;
    }

    Element userElement = getXmlFileRootElement(userFile);
    if (userElement != null) {
        NodeList userNodeList = userElement.getElementsByTagName("user");
        if (userNodeList != null) {
            for (int i = 0; i < userNodeList.getLength(); i++) {
                Node userNode = userNodeList.item(i);
                if (userNode.getNodeType() == Node.ELEMENT_NODE) {
                    Element user = (Element) userNode;
                    String rolesAttribute = user.getAttribute("roles");
                    String[] roles = rolesAttribute == null ? null : rolesAttribute.split(",");
                    if (roles != null && roles.length > 0) {
                        List<String> managerList = Arrays.asList(TOMCAT_MANAGER_ROLES);
                        for (int j = 0; j < roles.length; j++) {
                            if (managerList.contains(roles[j].trim())) {
                                List<String> weakWords = Arrays.asList(WEAK_WORDS);
                                String userName = user.getAttribute("username");
                                String password = user.getAttribute("password");
                                if (weakWords.contains(userName) && weakWords.contains(password)) {
                                    infos.add(new SecurityPolicyInfo(Type.MANAGER_PASSWORD, "tomcat后台管理角色存在弱用户名和弱密码.", true));
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
Example 12
Project: summer-mybatis-generator   File: MyBatisGeneratorConfigurationParser.java   View Source Code Vote up 5 votes
protected void parseJdbcConnection(Context context, Node node) {
    JDBCConnectionConfiguration jdbcConnectionConfiguration = new JDBCConnectionConfiguration();

    context.setJdbcConnectionConfiguration(jdbcConnectionConfiguration);

    Properties attributes = parseAttributes(node);
    String driverClass = attributes.getProperty("driverClass"); //$NON-NLS-1$
    String connectionURL = attributes.getProperty("connectionURL"); //$NON-NLS-1$
    String userId = attributes.getProperty("userId"); //$NON-NLS-1$
    String password = attributes.getProperty("password"); //$NON-NLS-1$

    jdbcConnectionConfiguration.setDriverClass(driverClass);
    jdbcConnectionConfiguration.setConnectionURL(connectionURL);

    if (stringHasValue(userId)) {
        jdbcConnectionConfiguration.setUserId(userId);
    }

    if (stringHasValue(password)) {
        jdbcConnectionConfiguration.setPassword(password);
    }

    NodeList nodeList = node.getChildNodes();
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node childNode = nodeList.item(i);

        if (childNode.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }

        if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$
            parseProperty(jdbcConnectionConfiguration, childNode);
        }
    }
}
 
Example 13
Project: Proyecto-DASI   File: ReadXMLTestRobots.java   View Source Code Vote up 5 votes
private String getRobotCoordinateZ(Element info, String tagcoordinate, String tagdimension){
      String valuez = "";        
NodeList coordinateNmElmntLst = info.getElementsByTagName(tagcoordinate);
Node coordinateNode = coordinateNmElmntLst.item(0);
if (coordinateNode.getNodeType() == Node.ELEMENT_NODE){
 Element coorInfo = (Element) coordinateNode;			  			  
 //Obtain information about z coordinate for the current robot 
 NodeList zNmElmntLst = coorInfo.getElementsByTagName(tagdimension);
 Element zNmElmnt = (Element) zNmElmntLst.item(0);
 NodeList zNm = zNmElmnt.getChildNodes();					  
 valuez = ((Node)zNm.item(0)).getNodeValue();				  
}
return valuez;
}
 
Example 14
Project: GermEval2017-Baseline   File: XMLReader.java   View Source Code Vote up 5 votes
@Override
public Document next() {
    Node reviewNode = reviewList.item(reviewPosition);
    if (reviewNode.getNodeType() == Node.ELEMENT_NODE) {
        Element elem = (Element) reviewNode;
        return buildDocument(elem);

    } else {
        return null;
    }
}
 
Example 15
Project: Equella   File: PropBagEx.java   View Source Code Vote up 5 votes
@SuppressWarnings("null")
private Node lookupNode(final Node parent, String nodeName, final int index, final boolean create)
{
	Node foundNode = null;

	int nNumFound = 0;
	final Document doc = parent.getOwnerDocument();

	final boolean isAttribute = nodeName.startsWith(ATTR);
	nodeName = DOMHelper.stripAttribute(nodeName);
	if( isAttribute )
	{
		foundNode = ((Element) parent).getAttributeNode(nodeName);
	}
	else
	{
		nodeName = DOMHelper.stripNamespace(nodeName);
		final boolean matchAny = nodeName.equals(WILD);

		final NodeList children = parent.getChildNodes();
		for( int i = 0; i < children.getLength() && foundNode == null; i++ )
		{
			final Node child = children.item(i);
			if( child.getNodeType() == Node.ELEMENT_NODE )
			{
				final String childName = DOMHelper.stripNamespace(child.getNodeName());
				if( matchAny || nodeName.equals(childName) )
				{
					if( nNumFound != index )
					{
						nNumFound++;
					}
					else
					{
						foundNode = child;
						break;
					}
				}
			}
		}
	}

	if( foundNode == null && create == true )
	{
		// If the Index is 0 and we didn't find a node or if the number
		// found (which is not zero based) equals the index (which is)
		// then this is the same as saying index is one more that the
		// number of nodes that exist then add a new child node.
		if( index == 0 || nNumFound == index )
		{
			if( isAttribute )
			{
				((Element) parent).setAttribute(nodeName, BLANK);
				foundNode = ((Element) parent).getAttributeNode(nodeName);
			}
			else
			{
				foundNode = doc.createElement(nodeName);
				parent.appendChild(foundNode);
			}
		}
		else
		{
			// An illegal index has been used - throw an error
			String szError = new String("Error creating node ");
			szError += nodeName;
			szError += " with an index of ";
			szError += index;
			throw new RuntimeException(szError);
		}
	}
	return foundNode;
}
 
Example 16
Project: openjdk-jdk10   File: DOMUtil.java   View Source Code Vote up 5 votes
public static List<Element> getChildElements(Element e) {
    List<Element> r = new ArrayList<Element>();
    NodeList l = e.getChildNodes();
    for(int i=0;i<l.getLength();i++) {
        Node n = l.item(i);
        if(n.getNodeType()==Node.ELEMENT_NODE)
            r.add((Element)n);
    }
    return r;
}
 
Example 17
Project: server-utility   File: DomWriter.java   View Source Code Vote up 4 votes
/**
 * Write any node.
 *
 * @param node
 *            the node
 * @throws ShellException
 *             the shell exception
 */
protected void writeAnyNode(Node node) throws ShellException {
    // is there anything to do?
    if (node == null) {
        return;
    }

    short type = node.getNodeType();
    switch (type) {
    case Node.DOCUMENT_NODE:
        write((Document) node);
        break;

    case Node.DOCUMENT_TYPE_NODE:
        write((DocumentType) node);
        break;

    case Node.ELEMENT_NODE:
        write((Element) node);
        break;

    case Node.ENTITY_REFERENCE_NODE:
        write((EntityReference) node);
        break;

    case Node.CDATA_SECTION_NODE:
        write((CDATASection) node);
        break;

    case Node.TEXT_NODE:
        write((Text) node);
        break;

    case Node.PROCESSING_INSTRUCTION_NODE:
        write((ProcessingInstruction) node);
        break;

    case Node.COMMENT_NODE:
        write((Comment) node);
        break;

    default:
        throw new ShellException(getString(
                "RuntimeError.18", Short.toString(type))); //$NON-NLS-1$
    }
}
 
Example 18
Project: jdk8u-jdk   File: DOMSubTreeData.java   View Source Code Vote up 4 votes
/**
 * Recursively traverses the subtree, and returns an XPath-equivalent
 * node-set of all nodes traversed, excluding any comment nodes,
 * if specified.
 *
 * @param node the node to traverse
 * @param nodeSet the set of nodes traversed so far
 * @param the previous sibling node
 */
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
                                      Node prevSibling)
{
    switch (node.getNodeType()) {
        case Node.ELEMENT_NODE :
            NamedNodeMap attrs = node.getAttributes();
            if (attrs != null) {
                for (int i = 0, len = attrs.getLength(); i < len; i++) {
                    nodeSet.add(attrs.item(i));
                }
            }
            nodeSet.add(node);
            Node pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.DOCUMENT_NODE :
            pSibling = null;
            for (Node child = node.getFirstChild(); child != null;
                child = child.getNextSibling()) {
                nodeSetMinusCommentNodes(child, nodeSet, pSibling);
                pSibling = child;
            }
            break;
        case Node.TEXT_NODE :
        case Node.CDATA_SECTION_NODE:
            // emulate XPath which only returns the first node in
            // contiguous text/cdata nodes
            if (prevSibling != null &&
                (prevSibling.getNodeType() == Node.TEXT_NODE ||
                 prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
                return;
            }
            nodeSet.add(node);
            break;
        case Node.PROCESSING_INSTRUCTION_NODE :
            nodeSet.add(node);
            break;
        case Node.COMMENT_NODE:
            if (withComments) {
                nodeSet.add(node);
            }
    }
}
 
Example 19
Project: org.mybatis.generator.core-1.3.5   File: XmlFileMergerJaxp.java   View Source Code Vote up 4 votes
private static boolean isGeneratedNode(Node node) {
    boolean rc = false;

    if (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
        Element element = (Element) node;
        String id = element.getAttribute("id"); //$NON-NLS-1$
        if (id != null) {
            for (String prefix : MergeConstants.OLD_XML_ELEMENT_PREFIXES) {
                if (id.startsWith(prefix)) {
                    rc = true;
                    break;
                }
            }
        }

        if (rc == false) {
            // check for new node format - if the first non-whitespace node
            // is an XML comment, and the comment includes
            // one of the old element tags,
            // then it is a generated node
            NodeList children = node.getChildNodes();
            int length = children.getLength();
            for (int i = 0; i < length; i++) {
                Node childNode = children.item(i);
                if (isWhiteSpace(childNode)) {
                    continue;
                } else if (childNode.getNodeType() == Node.COMMENT_NODE) {
                    Comment comment = (Comment) childNode;
                    String commentData = comment.getData();
                    for (String tag : MergeConstants.OLD_ELEMENT_TAGS) {
                        if (commentData.contains(tag)) {
                            rc = true;
                            break;
                        }
                    }
                } else {
                    break;
                }
            }
        }
    }

    return rc;
}
 
Example 20
Project: javaide   File: ResourceItem.java   View Source Code Vote up 4 votes
@NonNull
private static String getTextNode(@NonNull NodeList children) {
    StringBuilder sb = new StringBuilder();

    for (int i = 0, n = children.getLength(); i < n; i++) {
        Node child = children.item(i);

        short nodeType = child.getNodeType();

        switch (nodeType) {
            case Node.ELEMENT_NODE: {
                Element element = (Element) child;
                if (XLIFF_G_TAG.equals(element.getLocalName()) &&
                        element.getNamespaceURI() != null &&
                        element.getNamespaceURI().startsWith( XLIFF_NAMESPACE_PREFIX)) {
                    if (element.hasAttribute(ATTR_EXAMPLE)) {
                        // <xliff:g id="number" example="7">%d</xliff:g> minutes
                        // => "(7) minutes"
                        String example = element.getAttribute(ATTR_EXAMPLE);
                        sb.append('(').append(example).append(')');
                        continue;
                    } else if (element.hasAttribute(ATTR_ID)) {
                        // Step <xliff:g id="step_number">%1$d</xliff:g>
                        // => Step ${step_number}
                        String id = element.getAttribute(ATTR_ID);
                        sb.append('$').append('{').append(id).append('}');
                        continue;
                    }
                }

                NodeList childNodes = child.getChildNodes();
                if (childNodes.getLength() > 0) {
                    sb.append(getTextNode(childNodes));
                }
                break;
            }
            case Node.TEXT_NODE:
                sb.append(child.getNodeValue());
                break;
            case Node.CDATA_SECTION_NODE:
                sb.append(child.getNodeValue());
                break;
        }
    }

    return sb.toString();
}