List of usage examples for org.w3c.dom Attr getLocalName
public String getLocalName();
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from w w w. j a va 2 s . c o m public void testAddAttributeFromQNameWithNamespace() throws Exception { SOAPElement element = saajUtil.createSOAPElement(null, "test", null); SOAPElement retValue = element.addAttribute(new QName("urn:ns", "attr", "p"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS("urn:ns", "attr"); assertEquals("urn:ns", attr.getNamespaceURI()); assertEquals("attr", attr.getLocalName()); assertEquals("p", attr.getPrefix()); assertEquals("value", attr.getValue()); Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:com.googlecode.ddom.frontend.saaj.SOAPElementTest.java
@Validated @Test//from ww w.j a v a 2 s. co m public void testAddAttributeFromNameWithNamespace() throws Exception { SOAPEnvelope envelope = saajUtil.createSOAP11Envelope(); SOAPBody body = envelope.addBody(); SOAPElement element = body.addChildElement(new QName("urn:test", "test")); SOAPElement retValue = element.addAttribute(envelope.createName("attr", "p", "urn:ns"), "value"); assertSame(element, retValue); Attr attr = element.getAttributeNodeNS("urn:ns", "attr"); assertEquals("urn:ns", attr.getNamespaceURI()); assertEquals("attr", attr.getLocalName()); assertEquals("p", attr.getPrefix()); assertEquals("value", attr.getValue()); Attr nsDecl = element.getAttributeNodeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, "p"); assertNotNull(nsDecl); assertEquals("urn:ns", nsDecl.getValue()); }
From source file:it.cnr.icar.eric.server.profile.ws.wsdl.cataloger.WSDLCatalogerEngine.java
private void resolveTypeImports(Element portTypeElement, RegistryObjectType wsdlEO) throws CatalogingException { try {//w ww. jav a2 s. c o m String id = getPortTypeId(portTypeElement); if (idToRIMMap.get(id) == null) { processPortType(portTypeElement); } @SuppressWarnings("unused") ExtrinsicObjectType rimPortType = (ExtrinsicObjectType) idToRIMMap.get(id); List<Element> typeElements = resolveTypes(wsdlDocument); Iterator<?> schemaItr = resolveSchemaExtensions(typeElements); while (schemaItr.hasNext()) { Element schemaElement = (Element) schemaItr.next(); Iterator<?> schemaAttributeItr = wsdlDocument.getAttributes(schemaElement).iterator(); String location = null; @SuppressWarnings("unused") String localName = schemaElement.getLocalName(); String namespace = schemaElement.getNamespaceURI(); while (schemaAttributeItr.hasNext()) { Attr schemaAttribute = (Attr) schemaAttributeItr.next(); String localAttrName = schemaAttribute.getLocalName(); if (localAttrName.equalsIgnoreCase("namespace")) { namespace = schemaAttribute.getValue(); } else if (localAttrName.equalsIgnoreCase("schemaLocation")) { location = schemaAttribute.getValue(); } } RegistryObjectType importedObject = catalogImportStatement(wsdlEO, namespace, location); if (importedObject != null) { AssociationType1 ebAssociationType = bu.createAssociationType(wsdlEO.getId(), importedObject.getId(), CanonicalConstants.CANONICAL_ASSOCIATION_TYPE_ID_Imports); //May need a more deterministic algorithm for setting this id?? ebAssociationType.setId(wsdlEO.getId() + ":Imports:" + importedObject.getId()); registryObjects.add(ebAssociationType); } } } catch (CatalogingException e) { throw e; } catch (Exception e) { throw new CatalogingException(e); } }
From source file:iristk.flow.FlowCompiler.java
private String createExpression(Element en) throws FlowCompilerException { String estring = ""; estring += "<" + en.getLocalName(); for (int j = 0; j < en.getAttributes().getLength(); j++) { Attr attr = (Attr) en.getAttributes().item(j); if (!(attr.getNamespaceURI() != null && attr.getNamespaceURI().equals("http://www.w3.org/2000/xmlns/")) && !attr.getLocalName().equals("xmlns") && !attr.getLocalName().equals("xsi")) { estring += " " + attr.getLocalName() + "=\\\"" + attr.getValue() + "\\\""; }//w ww. j av a 2 s . c o m } if (en.getChildNodes().getLength() == 0) { estring += "/>"; return "\"" + estring + "\""; } else { String varName = varname("string"); code.println("StringCreator " + varName + " = new StringCreator();"); List<Object> children = new ArrayList<>(); estring += ">"; children.add(estring); for (int i = 0; i < en.getChildNodes().getLength(); i++) { children.add(en.getChildNodes().item(i)); } children.add("</" + en.getLocalName() + ">"); printActions(children, en, varName); return varName + ".toString()"; } }
From source file:org.adl.parsers.dom.ADLDOMParser.java
/** * This method checks to see if the node that is being processed contains * an xsi:schemaLocation attribute. If it does, the method adds the name * value of the attribute to the list of schemaLocations. * // w w w . j a v a 2 s . co m * @param iNode The node that is being processed * @param iXMLFileName The name of the XML test subject */ private void checkForSchemaLocations(Node iNode, String iXMLFileName) { log.debug("checkForSchemaLocations()"); log.debug("Processing Node: [" + iNode.getLocalName() + "]"); log.debug("Processing Nodes Namespace: [" + iNode.getNamespaceURI() + "]"); // Get the list of attributes of the element NamedNodeMap attrList = iNode.getAttributes(); // Loop over the attributes for this element, remove any attributes // that are extensions log.debug("Processing " + attrList.getLength() + " attributes"); for (int i = 0; i < attrList.getLength(); i++) { Attr currentAttribute = (Attr) attrList.item(i); String parentNamespace = iNode.getNamespaceURI(); String attributeNamespace = currentAttribute.getNamespaceURI(); log.debug("Processing attribute [" + i + "]: [" + currentAttribute.getLocalName() + "]"); log.debug("Attributes Namespace [" + i + "]: [" + attributeNamespace + "]"); if (!mDeclaredNamespaces.contains(attributeNamespace) && (attributeNamespace != null)) { mDeclaredNamespaces.add(attributeNamespace); } log.debug("Attributes Parent Node [" + i + "]: [" + iNode.getLocalName() + "]"); log.debug("Parent Nodes Namespace [" + i + "]: [" + parentNamespace + "]"); if (!mDeclaredNamespaces.contains(attributeNamespace) && (parentNamespace != null)) { mDeclaredNamespaces.add(parentNamespace); } // If one of the attributes is xsi:schemaLocation, then // save off the namespace and the schema location. These // will be used later during the validation process if (currentAttribute.getLocalName().equals("schemaLocation") && currentAttribute.getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema-instance")) { // A schema location has been defined in the XML, don't // use the defaults if (mFirstTimeSchemaLocationFound) { // Don't use the default schema locations mSchemaLocation = null; mFirstTimeSchemaLocationFound = false; // flag that xsi:schemalocation attribute has been declared mSchemaLocExists = true; } addSchemaLocationToList(currentAttribute.getValue(), iXMLFileName); } } // end looping over attributes log.debug("checkForSchemaLocations()"); }
From source file:org.adl.parsers.dom.ADLDOMParser.java
/** * Traverses the DOM Tree and removes Ignorable Whitespace Text Nodes and * Comment Text. The function also removes extension elements and * attributes that are not defined by SCORM. If extensions are found * the function also sets a flag stating that extensions are present in the * input XML instance.//from w w w. j ava 2 s.c om * * @param iNode The node to be pruned of whitespace and comments<br> * @param iXMLFileName The XML file to be pruned */ private void pruneTree(Node iNode, String iXMLFileName) { String value; // is there anything to do? if (iNode == null) return; switch (iNode.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: { break; } case Node.DOCUMENT_NODE: { pruneTree(((Document) iNode).getDocumentElement(), iXMLFileName); break; } case Node.ELEMENT_NODE: { log.debug("Processing Element Node: [" + iNode.getLocalName() + "]"); log.debug("************************************************"); log.debug("Processing Element Node: [" + iNode.getLocalName() + "]"); checkForSchemaLocations(iNode, iXMLFileName); // Get the list of attributes of the element NamedNodeMap attrList = iNode.getAttributes(); // Loop over the attributes for this element, remove any attributes // that are extensions log.debug("Processing " + attrList.getLength() + " attributes"); for (int i = 0; i < attrList.getLength(); i++) { Attr currentAttribute = (Attr) attrList.item(i); if (!(DOMTreeUtility.isSCORMAppProfileNode(currentAttribute, iNode))) { log.debug("Extension attribute, removing: [" + currentAttribute.getNamespaceURI() + "] " + currentAttribute.getLocalName() + " from the its parent node [" + iNode.getNamespaceURI() + "] " + iNode.getLocalName()); // Remove the Element Node from the DOM attrList.removeNamedItemNS(currentAttribute.getNamespaceURI(), currentAttribute.getLocalName()); i--; mExtensionsFound = true; } else { log.debug("Valid SCORM attribute, keeping attribute: [" + currentAttribute.getNamespaceURI() + "] " + currentAttribute.getLocalName()); } } log.debug("Done processing attributes for node: [" + iNode.getNamespaceURI() + "] " + iNode.getLocalName()); log.debug("************************************************"); // Done looping over the attributes for this element, now loop over // the set of children nodes. log.debug(""); log.debug("************************************************"); log.debug("Processing direct-descendances for node: [" + iNode.getNamespaceURI() + "] " + iNode.getLocalName()); NodeList children = iNode.getChildNodes(); if (children != null) { // Loop over set of children elements for this element, remove // any elements that are extensions log.debug("Processing " + children.getLength() + " elements"); for (int z = 0; z < children.getLength(); z++) { Node childNode = children.item(z); if (childNode.getNodeType() == Node.ELEMENT_NODE) { log.debug("Processing element: [" + childNode + "]"); log.debug("Elements Namespace: [" + childNode.getNamespaceURI() + "]"); log.debug("Elements Parent Node: [" + iNode.getLocalName() + "]"); log.debug("Parent Nodes Namespace: [" + iNode.getNamespaceURI() + "]"); if (!(DOMTreeUtility.isSCORMAppProfileNode(children.item(z), children.item(z).getParentNode()))) { // Before we remove the element see if the elemen // contains any xsi:schemaLocations. We need // to add them to the list of schema locations for // parsing checkForSchemaLocations(childNode, iXMLFileName); log.debug("Extension Element Found, removing from DOM Tree "); // Remove the Element Node from the DOM children.item(z).getParentNode().removeChild(children.item(z)); z--; mExtensionsFound = true; } else { log.debug("ADL SCORM Element Found, leaving " + "element in DOM Tree"); pruneTree(children.item(z), iXMLFileName); } } // end if NodeType == ELEMENT_NODE if (childNode instanceof TextImpl) { value = children.item(z).getNodeValue().trim(); if (((TextImpl) children.item(z)).isIgnorableWhitespace()) { iNode.removeChild(children.item(z)); z--; } else if (value.length() == 0) { iNode.removeChild(children.item(z)); z--; } } else if (children.item(z).getNodeType() == Node.COMMENT_NODE) { iNode.removeChild(children.item(z)); z--; } } // end looping over children nodes } // end if there are children log.debug("Done processing direct-descendants for node: [" + iNode.getNamespaceURI() + "] " + iNode.getLocalName()); log.debug("**************************************************"); break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { NodeList children = iNode.getChildNodes(); if (children != null) { int len = children.getLength(); for (int i = 0; i < len; i++) { pruneTree(children.item(i), iXMLFileName); } } break; } // text case Node.COMMENT_NODE: { break; } case Node.CDATA_SECTION_NODE: { break; } case Node.TEXT_NODE: { break; } default: { break; } } }
From source file:org.adl.parsers.dom.DOMTreeUtility.java
/** * This method returns the attribute of the given node whose name matches * the named value (iAttributeName) and a particular namespace * (iNamespaceForAttr)./*w w w.j a va2 s .c om*/ * * @param iNode The element containing the attribute * @param iAttributeName The name of the attribute being retrieved * * @return Returns the attribute matching the name and namespace */ public static Attr getAttribute(Node iNode, String iAttributeName) { log.debug("DOMTreeUtility getAttribute()"); Attr result = null; // Determine if the node is null if (iNode != null) { log.debug("Parent Node: " + iNode.getLocalName()); log.debug("Node being searched for: " + iAttributeName); // If the node is not null, then get the list of attributes from // the node NamedNodeMap attrList = iNode.getAttributes(); int numAttr = attrList.getLength(); Attr currentAttrNode = null; String currentNodeName = null; // Loop through the attributes and get their values assuming // that the multiplicity of each attribute is 1 and only 1. for (int k = 0; k < numAttr; k++) { // Get the attribute currentAttrNode = (Attr) attrList.item(k); // Get the local name of the attribute currentNodeName = currentAttrNode.getLocalName(); // First check to see if the current node is the one with the // same Local Name as the value we are looking for (iAttributeName) if (currentNodeName.equalsIgnoreCase(iAttributeName)) { // We have found a node that shares the same name as the // node we are looking for (iAttributeName). // Matching attribute found result = currentAttrNode; break; } } // end for loop } return result; }
From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method assists with the application profile check for the validation * of the bucket attributes. <br>/* ww w. j a v a 2 s . c o m*/ * * @param iBucketNode * The resources node <br> */ private void checkBucketAttributes(Node iBucketNode) { mLogger.debug("CPValidator checkBucketAttributes"); String msgText; boolean foundValidChar = false; NamedNodeMap attrList = iBucketNode.getAttributes(); int numAttr = attrList.getLength(); Attr currentAttrNode; String currentAttrName; String attributeValue = null; // find the bucketID and bucketType attributes for (int i = 0; i < numAttr; i++) { currentAttrNode = (Attr) attrList.item(i); currentAttrName = currentAttrNode.getLocalName(); // Check bucketID and bucketType Attribute Values for nothing but // white space if (currentAttrName.equals("bucketID") || currentAttrName.equals("bucketType")) { // Find the length of bucket attribute and check if its all // whitespace attributeValue = currentAttrNode.getValue(); for (int j = 0; j < attributeValue.length(); j++) { char tempChar = attributeValue.charAt(j); if (!(Character.isWhitespace(tempChar))) { foundValidChar = true; break; } } if (!foundValidChar) { msgText = "Attribute \"" + currentAttrName + "\" must " + "contain valid characters, all whitespace found."; mLogger.debug("SSP: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } foundValidChar = false; } } }
From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method checks the item to ensure that the identifierref attribute is * not used on a non-leaf item. This method also checks to ensure that a * leaf item shall reference a resource. A leaf item fails if it contains no * identifierref attribute at all, or if it contains an identifierref * attribute that is set to an empty string. * //w w w. j av a 2 s.c o m * @param iOrgNode * - the organization node containing the item element(s) * @return boolean - result of the check for the item identifierref * attribute True if the identifierref passes, false otherwise. */ private boolean checkItemIdentifierRef(Node iOrgNode) { mLogger.debug("CPValidator checkItemIdentifierRef"); String msgText = ""; NodeList orgChildren = iOrgNode.getChildNodes(); int orgChildSize = orgChildren.getLength(); Node currentNode; String currentName; boolean result = true; for (int j = 0; j < orgChildSize; j++) { currentNode = orgChildren.item(j); currentName = currentNode.getLocalName(); if (currentName.equals("item")) { NodeList itemChildren = currentNode.getChildNodes(); int itemChildrenSize = itemChildren.getLength(); boolean itemHasItemChildren = false; for (int k = 0; k < itemChildrenSize; k++) { // see if we have a child item of item // if so, this signals that the currentNode is not a leaf // and // should not have an identifierref Node currentItemChild = itemChildren.item(k); String currentItemChildName = currentItemChild.getLocalName(); if (currentItemChildName != null) { if (currentItemChildName.equals("item")) { NamedNodeMap attrList = currentNode.getAttributes(); int numAttr = attrList.getLength(); Attr currentAttrNode = null; String currentNodeName = ""; for (int i = 0; i < numAttr; i++) { currentAttrNode = (Attr) attrList.item(i); currentNodeName = currentAttrNode.getLocalName(); if (currentNodeName.equals("identifierref")) { result = result && false; msgText = Messages.getString("CPValidator.461"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } // end if ( // currentNodeName.equals("identifierref") ) } // end for // set the flag that signals that the item is // NOT a leaf // item itemHasItemChildren = true; } // end if ( currentItemChildName.equals("item") ) } } // need to check if we are dealing with a leaf item if (!itemHasItemChildren) { // Verify that a leaf item references a resource Attr identifierRef = DOMTreeUtility.getAttribute(currentNode, "identifierref"); if (identifierRef == null) { // ERROR, must reference a resource therefore it must // contain // an identifierref attribute result = result && false; msgText = Messages.getString("CPValidator.464"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } else { String identifierRefValue = identifierRef.getValue(); if (identifierRefValue.equals("")) { // ERROR, must reference a resource therefore it // cannot // contain an identifierref attibute that is set to // an // empty string result = result && false; msgText = Messages.getString("CPValidator.467"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } } } } } return result; }
From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method performs the application profile checks for the * adlcp:objectivesGlobalToSystem attribute. The application profile checks * include verifying that the attribute belongs to the IMS namespace and * that it exists as an attribute of the IMS organization element only. * /*from w ww . j av a 2 s . c o m*/ * @param iCurrentAttribute * the objectivesGlobalToSystem attribute to be tested * @param iParentNode * the parent element that the attribute belongs to. * @return boolean True implies that the application profile checks passed; * false implies that they did not */ private boolean checkObjGlobalToSystemReq(Attr iCurrentAttribute, Node iParentNode) { boolean result = false; if (DOMTreeUtility.isAppropriateElement(iParentNode, "organization", "http://www.imsglobal.org/xsd/imscp_v1p1")) { result = true; } else { String msgText = Messages.getString("CPValidator.107", iCurrentAttribute.getLocalName(), "organization"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText)); } return result; }