List of usage examples for org.w3c.dom Attr getLocalName
public String getLocalName();
From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method performs the application profile checks for the * adlcp:scormType attribute. The application profile checks include * verifying that the attribute belongs to the ADL CP namespace and that it * exists as an attribute of the IMS resource element only. * /* w w w.j a v a 2s . c o m*/ * @param iCurrentAttribute * the scormType 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 checkSCORMTypeReq(Attr iCurrentAttribute, Node iParentNode) { boolean result = false; if (DOMTreeUtility.isAppropriateElement(iParentNode, "resource", "http://www.imsglobal.org/xsd/imscp_v1p1")) { result = true; } else { String msgText = Messages.getString("CPValidator.107", iCurrentAttribute.getLocalName(), "resource"); 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 assists with the application profile check for the validation * of the bucket attributes. <br>//from ww w . j a v a 2s . c o m * * @param iSizeNode * The resources node <br> */ private void checkSizeAttributes(Node iSizeNode) { mLogger.debug("CPValidator checkSizeAttributes"); String msgText; NamedNodeMap attrList = iSizeNode.getAttributes(); int numAttr = attrList.getLength(); Attr currentAttrNode; String currentAttrName; String attributeValue = null; int minVal = 0; // find the minimum and requested attributes for (int i = 0; i < numAttr; i++) { currentAttrNode = (Attr) attrList.item(i); currentAttrName = currentAttrNode.getLocalName(); // Check bucketID and bucketType Attribute Values for even numbers if (currentAttrName.equals("minimum") || currentAttrName.equals("requested")) { // Get the value and check if it is a valid even integer attributeValue = currentAttrNode.getValue(); // Assume the value is valid boolean valid = true; if (attributeValue == null) { // A null value can never be valid valid = false; } try { int value = Integer.parseInt(attributeValue, 10); if (value < minVal || (value % 2) != 0) { valid = false; } } catch (Exception e) { valid = false; } if (!valid) { msgText = "Size Attribute \"" + currentAttrName + "\" must " + "contain a valid even integer value."; mLogger.debug("SSP: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } } } }
From source file:org.adl.validator.contentpackage.CPValidator.java
/** * This method performs the meat of the application profile checks. The * application profiles are described in XML format. Each application * profile has its own XML representation. These XML rules are parsed in * order to form a document object. The test subject manifest is also * available in document format. This method compares the manifest to the * rules described in the XML dom. This recursive method is driven by the * test subject dom.//from w ww. j a v a 2 s . c o m * * @param iTestSubjectNode * Test Subject DOM * @param iPath * Path of the rule to compare to * @return - boolean result of the checks performed. True if the check was * conformant, false otherwise. */ private boolean compareToRules(Node iTestSubjectNode, String iPath) { // is there anything to do? if (iTestSubjectNode == null) return false; mLogger.debug("CPValidator compareToRules"); mLogger.debug("Node: " + iTestSubjectNode.getLocalName()); mLogger.debug("Namespace: " + iTestSubjectNode.getNamespaceURI()); mLogger.debug("Path: " + iPath); boolean result = true; String msgText = ""; // Determine which type of DOM Tree Node we are dealing with switch (iTestSubjectNode.getNodeType()) { case Node.PROCESSING_INSTRUCTION_NODE: { // Skip any processing instructions, nothing for us to do break; } case Node.DOCUMENT_NODE: { // Found the root document node Node rootNode = ((Document) iTestSubjectNode).getDocumentElement(); String rootNodeName = rootNode.getLocalName(); mLogger.debug("DOCUMENT_NODE found"); mLogger.debug("Namespace: " + rootNode.getNamespaceURI()); mLogger.debug("Node Name: " + rootNodeName); mLogger.debug("INFO: Testing element <" + rootNodeName + "> for minimum conformance"); DetailedLogMessageCollection.getInstance().addMessage( new LogMessage(MessageType.INFO, Messages.getString("CPValidator.131", rootNodeName))); mLogger.debug("PASSED: Multiplicity for element <" + rootNodeName + "> has been verified"); DetailedLogMessageCollection.getInstance().addMessage( new LogMessage(MessageType.PASSED, Messages.getString("CPValidator.135", rootNodeName))); result = compareToRules(rootNode, "") && result; break; } case Node.ELEMENT_NODE: { // Found an Element Node String parentNodeName = iTestSubjectNode.getLocalName(); if (parentNodeName.equals("manifest")) { // retrieve resources nodes for sco reference validation Node resourcesNode = DOMTreeUtility.getNode(iTestSubjectNode, "resources"); if (resourcesNode != null) { // retrieve resource nodes for sco reference validation mResourceNodes = DOMTreeUtility.getNodes(resourcesNode, "resource"); // Must also track resource identifier values for // dependency identifierref scope validation trackResourceIdentifiers(resourcesNode); } } String dataType = null; int multiplicityUsed = -1; int minRule = -1; int maxRule = -1; int spmRule = -1; mLogger.debug("Looping through attributes for the input " + "element <" + parentNodeName + ">"); // Look for the attributes of this element NamedNodeMap attrList = iTestSubjectNode.getAttributes(); int numAttr = attrList.getLength(); mLogger.debug("There are " + numAttr + " attributes of <" + parentNodeName + "> elememt to test"); Attr currentAttrNode = null; String currentNodeName = ""; String attributeValue = ""; // Loop throught attributes for (int i = 0; i < numAttr; i++) { currentAttrNode = (Attr) attrList.item(i); currentNodeName = currentAttrNode.getLocalName(); mLogger.debug("Processing the [" + currentAttrNode.getNamespaceURI() + "] " + currentNodeName + " attribute of the <" + parentNodeName + "> element."); // If the current attribute is persistState then additional // checks may be necessary if (currentNodeName.equalsIgnoreCase("persistState")) { // we must fail. SCORM 3rd Edition Addendum has removed the // persistState attribute from the adlcp namespaced schema msgText = Messages.getString("CPValidator.274", currentNodeName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } // If the current attribute is scormType then additional // checks may be necessary if (currentNodeName.equalsIgnoreCase("scormType")) { // Application Profile Check: Check to make sure that the // adlcp:scormType attribute can only appear on an // <imscp:resource> element result = checkSCORMTypeReq(currentAttrNode, iTestSubjectNode) && result; } // If the current attribute is objectivesGlobalToSystem then // additional checks may be necessary if (currentNodeName.equalsIgnoreCase("objectivesGlobalToSystem")) { // Application Profile Check: Check that the // adlseq:objectivesGlobalToSystem attribute can only appear // on an <imscp:organization> element. result = checkObjGlobalToSystemReq(currentAttrNode, iTestSubjectNode) && result; } // Retrieve the application profile rules only if the the // current // attribute being processed has SCORM application profile // requirements mLogger.debug("Additional checks needed for attribute [" + currentNodeName + "].\r\n"); // Retreive the data type rules dataType = mRulesValidator.getRuleValue(parentNodeName, iPath, "datatype", currentNodeName); // If the data type rules are for an xml:base, then there is // more processing that needs to take place. if (dataType.equalsIgnoreCase("xmlbase")) { // This is a xml:base data type msgText = Messages.getString("CPValidator.164", currentNodeName); mLogger.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); multiplicityUsed = getMultiplicityUsed(attrList, currentNodeName); // We will assume that no attribute can exist more than // once (ever). According to W3C. Therefore, min and max // rules must exist. // Get the min rule and convert to an int minRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "min", currentNodeName)); // Get the max rule and convert to an int maxRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "max", currentNodeName)); if ((minRule != -1) || (maxRule != -1)) { if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) { msgText = Messages.getString("CPValidator.169", currentNodeName); mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("CPValidator.175", currentNodeName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } // mult used >= minRule && mult used <= maxRule } // end minRule != -1, maxRule != -1 // Get the spm rule and convert to an int spmRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "spm", currentNodeName)); attributeValue = currentAttrNode.getValue(); // Check the attributes for smallest permitted maximum(spm) // conformance. result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result; // Check to make sure slashes are correct result = checkForSlashes("xml:base", attributeValue) && result; if (parentNodeName.equals("manifest")) { mXMLBase[0][1] = attributeValue; mLogger.debug(" XML:base found in manifest, value is " + attributeValue); } else if (parentNodeName.equals("resources")) { mXMLBase[1][1] = attributeValue; mLogger.debug(" XML:base found in resources, value is " + attributeValue); } else if (parentNodeName.equals("resource")) { mXMLBase[2][1] = attributeValue; mLogger.debug(" XML:base found in resource, value is " + attributeValue); } } // end if xml:base } // end looping over set of attributes for the element // If we are processing an <imscp:manifest> element, then there // are special cases application profile checks needed. if (parentNodeName.equalsIgnoreCase("manifest")) { mLogger.debug("Manifest node, additional check's being done."); mLogger.debug("Determining how many times the " + "identifier attribute is present."); multiplicityUsed = getMultiplicityUsed(attrList, "identifier"); if (multiplicityUsed < 1) { mLogger.debug("FAILED: Mandatory attribute \"identifier\"" + " could not be found"); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, Messages.getString("CPValidator.198", "identifier"))); result = false; } } else if (parentNodeName.equalsIgnoreCase("organizations") && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) { // multiple <organization> elements exist, but there is no // default attribute. // not a conformance check, warning only multiplicityUsed = getMultiplicityUsed(attrList, "default"); if (multiplicityUsed < 1) { mLogger.debug("ERROR: Mandatory attribute \"default\" " + "could not be found"); DetailedLogMessageCollection.getInstance().addMessage( new LogMessage(MessageType.FAILED, Messages.getString("CPValidator.198", "default"))); result = false; } } else if (parentNodeName.equalsIgnoreCase("organization") && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) { multiplicityUsed = getMultiplicityUsed(attrList, "identifier"); if (multiplicityUsed < 1) { mLogger.debug("FAILED: Mandatory attribute \"identifier\" " + "could not be found"); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, Messages.getString("CPValidator.198", "identifier"))); result = false; } } else if (parentNodeName.equalsIgnoreCase("item") && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) { multiplicityUsed = getMultiplicityUsed(attrList, "identifier"); if (multiplicityUsed < 1) { mLogger.debug("FAILED: Mandatory attribute \"identifier\" " + "could not be found"); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, Messages.getString("CPValidator.198", "identifier"))); result = false; } // need to perform a special check to warn when parameters // are present but no identifierref is int idrefMult = -1; int paramMult = -1; idrefMult = getMultiplicityUsed(attrList, "identifierref"); paramMult = getMultiplicityUsed(attrList, "parameters"); if ((idrefMult < 1) && !(paramMult < 1)) { // we have a parameters but no identifierref - warning msgText = Messages.getString("CPValidator.220"); mLogger.debug("WARNING: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.WARNING, msgText)); } // have to store the idref values in a List for future // app profile checking of resource attributes if (idrefMult >= 1) { String iDREFValue = DOMTreeUtility.getAttributeValue(iTestSubjectNode, "identifierref"); boolean validIdref = mResourceIdentifierList.contains(iDREFValue); if (validIdref) { mValidIdrefs.add(iDREFValue); } // Whether or not it is true we need to keep track of ALL of // the idrefs so we can look for dangling references after // the entire list of refs, including those on sub-manifests // have been inventoried. mAllIdrefsList.add(iDREFValue); } // Perform a special check to ensure that initialization data // only exists on items that reference SCOs NodeList childrenOfItem = iTestSubjectNode.getChildNodes(); if (childrenOfItem != null) { Node currentItemChild; String currentItemChildName; int len = childrenOfItem.getLength(); for (int k = 0; k < len; k++) { currentItemChild = childrenOfItem.item(k); currentItemChildName = currentItemChild.getLocalName(); if (currentItemChildName.equals("timeLimitAction") || currentItemChildName.equals("dataFromLMS") || currentItemChildName.equals("completionThreshold")) { if (idrefMult < 1) { // we have an item that contains initialization // data // and does not reference a resource at all result = false; msgText = Messages.getString("CPValidator.226", currentItemChildName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } else { // we must verify that the resource it is // referencing // is a sco String idrefValue = DOMTreeUtility.getAttributeValue(iTestSubjectNode, "identifierref"); result = result && checkForReferenceToSco(idrefValue); } } } } } else if (parentNodeName.equalsIgnoreCase("resource")) { checkBucketUniqueness(iTestSubjectNode); boolean resourceResult = checkResourceAttributes(iTestSubjectNode, attrList); result = result && resourceResult; } else if (parentNodeName.equalsIgnoreCase("bucket")) { checkBucketAttributes(iTestSubjectNode); } else if (parentNodeName.equalsIgnoreCase("size")) { checkSizeAttributes(iTestSubjectNode); } // test the attributes for (int j = 0; j < numAttr; j++) { currentAttrNode = (Attr) attrList.item(j); currentNodeName = currentAttrNode.getLocalName(); dataType = mRulesValidator.getRuleValue(parentNodeName, iPath, "datatype", currentNodeName); // we do not want to test for xml namespaces or extensions if (dataType.equalsIgnoreCase("idref") || dataType.equalsIgnoreCase("id") || dataType.equalsIgnoreCase("vocabulary") || dataType.equalsIgnoreCase("text") || dataType.equalsIgnoreCase("uri")) { msgText = Messages.getString("CPValidator.164", currentNodeName); mLogger.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); multiplicityUsed = getMultiplicityUsed(attrList, currentNodeName); // We will assume that no attribute can exist more than // once (ever). According to W3C. Therefore, min and max // rules must exist. // get the min rule and convert to an int minRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "min", currentNodeName)); // get the max rule and convert to an int maxRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "max", currentNodeName)); if ((minRule != -1) || (maxRule != -1)) { if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) { msgText = Messages.getString("CPValidator.169", currentNodeName); mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("CPValidator.175", currentNodeName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } // get the spm rule and convert to an int spmRule = Integer .parseInt(mRulesValidator.getRuleValue(parentNodeName, iPath, "spm", currentNodeName)); attributeValue = currentAttrNode.getValue(); if (dataType.equalsIgnoreCase("idref")) { // This is a IDREF data type // check the attributes for smallest permitted maximum // (spm) conformance. result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result; // check the Default Idref to make sure it points to an // valid identifier. if (currentNodeName.equalsIgnoreCase("default")) { boolean foundDefaultIdentifier = false; // check for this identifer in the organization list int numOrganizationIdentifiers = mOrganizationIdentifierList.size(); for (int i = 0; i < numOrganizationIdentifiers; i++) { String identifier = (mOrganizationIdentifierList.get(i)); if (identifier.equals(attributeValue)) { foundDefaultIdentifier = true; break; } } if (foundDefaultIdentifier) { msgText = Messages.getString("CPValidator.251", currentNodeName); mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("CPValidator.254", currentNodeName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } if (currentNodeName.equalsIgnoreCase("identifierref") && parentNodeName.equalsIgnoreCase("dependency")) { mAllIdrefsList.add(currentAttrNode.getValue()); } } else if (dataType.equalsIgnoreCase("id")) { // This is a id data type // check the attributes for smallest permitted maximum // (spm) conformance. result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result; if (parentNodeName.equals("manifest")) { mManifestID = currentAttrNode.getValue(); mLogger.debug("mManifestID is " + mManifestID); } // imsssp id attributes here } else if (dataType.equalsIgnoreCase("uri")) { // This is a URI data type // check the attributes for smallest permitted maximum // (spm) conformance. Only perform these checks if // the value is not an empty string String myAttributeValue = currentAttrNode.getValue(); if (!myAttributeValue.equals("")) { // check to ensure there are no leading slashes result = checkForSlashes("href", myAttributeValue) && result; // check if the file exists // apply xml:base on href value before href checks if (doesXMLBaseExist()) { mLogger.debug("APPLYING XML BASE"); myAttributeValue = applyXMLBase(myAttributeValue); } if (myAttributeValue.indexOf('\\') != -1) { msgText = Messages.getString("CPValidator.265", myAttributeValue); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result &= false; } // check href spm after it is pre-appended with // xml:base result = checkSPMConformance(currentNodeName, myAttributeValue, spmRule, true) && result; result = checkHref(myAttributeValue) && result; } } else if (dataType.equalsIgnoreCase("vocabulary")) { // This is a VOCAB data type // retrieve the vocab rule values and check against the // vocab values that exist within the test subject msgText = "Testing attribute \"" + currentNodeName + "\" for valid vocabulary"; mLogger.debug("INFO: " + msgText); List<String> vocabAttribValues = mRulesValidator.getAttribVocabRuleValues(parentNodeName, iPath, currentNodeName); // we are assuming that only 1 vocabulary value may // exist for an attribute result = checkVocabulary(currentNodeName, attributeValue, vocabAttribValues, true) && result; } else if (dataType.equalsIgnoreCase("text")) { // This is a TEXT data type // check the attributes for smallest permitted maximum // (spm) conformance. result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result; // test the parameter attribute for valid syntax if (currentNodeName.equalsIgnoreCase("parameters")) { ParameterChecker pc = new ParameterChecker(); result = pc.checkParameters(attributeValue) && result; } } } } // done with attributes // Test the child Nodes NodeList children = iTestSubjectNode.getChildNodes(); if (children != null) { int numChildren = children.getLength(); // update the path for this child element String path; if (iPath.equals("")) { // the node is a DOCUMENT or a root <manifest> path = parentNodeName; } else if ((iPath.equals("manifest.manifest")) && (parentNodeName.equals("manifest"))) { path = iPath; } else if (parentNodeName.equalsIgnoreCase("item")) { // the Node is an <imscp:item> if (iPath.equals("manifest.organizations.organization.item")) { path = iPath; } else { path = iPath + "." + parentNodeName; } } else { path = iPath + "." + parentNodeName; } // SPECIAL CASE: check for mandatory elements if (parentNodeName.equalsIgnoreCase("manifest")) { // check for mandatory metadata element at package level multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "metadata"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "metadata"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } else // check for mandatory children { Node caMetadataNode = DOMTreeUtility.getNode(iTestSubjectNode, "metadata"); // check for mandatory <imscp:schema> element multiplicityUsed = getMultiplicityUsed(caMetadataNode, "schema"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "schema"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } // check for mandatory <imscp:schemaversion> element multiplicityUsed = getMultiplicityUsed(caMetadataNode, "schemaversion"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "schemaversion"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organizations"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "organizations"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "resources"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "resources"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } else if (parentNodeName.equalsIgnoreCase("organizations") && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) { multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organization"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "organization"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } // have to check to ensure that empty organizations exist // for resource package else if (parentNodeName.equalsIgnoreCase("organizations") && (mRulesValidator.getApplicationProfile()).equals("resource")) { multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "organization"); if (multiplicityUsed > 0) { msgText = Messages.getString("CPValidator.311"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } else { msgText = Messages.getString("CPValidator.312"); // we have an empty <orgs> element, display a valid msg mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } } else if (parentNodeName.equalsIgnoreCase("organization") && (mRulesValidator.getApplicationProfile()).equals("contentaggregation")) { multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "title"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "title"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, "item"); if (multiplicityUsed < 1) { msgText = Messages.getString("CPValidator.287", "item"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } // special checks for item result = checkItem(iTestSubjectNode, mManifestInfo) && result; } for (int z = 0; z < numChildren; z++) { Node currentChild = children.item(z); String currentChildName = currentChild.getLocalName(); msgText = "Currentchild is " + currentChildName + " and path is " + path; mLogger.debug(msgText); if (currentChildName != null) { if (((currentChildName.equals("timeLimitAction")) || (currentChildName.equals("dataFromLMS")) || (currentChildName.equals("completionThreshold")) || (currentChildName.equals("presentation"))) && (!parentNodeName.equals("item"))) { result = false; msgText = Messages.getString("CPValidator.328", currentChildName, "item"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } if (((currentChildName.equals("constrainedChoiceConsiderations")) || (currentChildName.equals("rollupConsiderations"))) && (!parentNodeName.equals("sequencing"))) { result = false; msgText = Messages.getString("CPValidator.328", currentChildName, "sequencing"); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } // must enforce that the adlcp:location exist // as a child of metadata only - warning for best // practice. if ((currentChildName.equals("location")) && (!parentNodeName.equals("metadata"))) { result = false; msgText = Messages.getString("CPValidator.328", currentChildName, "metadata"); mLogger.debug("WARNING: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.WARNING, msgText)); } if ((currentChildName.equals("sequencing")) && (!parentNodeName.equals("item")) && (!parentNodeName.equals("organization"))) { result = false; msgText = Messages.getString("CPValidator.345", currentChildName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } dataType = mRulesValidator.getRuleValue(currentChildName, path, "datatype"); // must enforce that the imsssp:bucket exist // as a child of a resource only. if ((currentChildName.equals("bucket")) && (!parentNodeName.equals("resource"))) { // Check to enforce that bucket is a child of a // resource msgText = "<" + currentChildName + "> can only " + "exist as a child of a <resource>"; mLogger.debug("SSP: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } // must enforce that the imsssp:size exist // as a child of a bucket only. if ((currentChildName.equals("size")) && (!parentNodeName.equals("bucket"))) { msgText = "<" + currentChildName + "> can only " + "exist as a child of a <bucket>"; mLogger.debug("SSP: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } // Check the SCORMType of the resource; it must be sco if ((currentChildName.equals("bucket")) && (parentNodeName.equals("resource"))) { // Now check to ensure that the resource type is SCO String typeS = DOMTreeUtility.getAttributeValue(iTestSubjectNode, "scormType"); if (!typeS.equalsIgnoreCase("sco")) { // result = false; msgText = "The <" + currentChildName + "> shall" + " only exist in a resource that is " + " scormType = \"sco\"."; mLogger.debug("SSP: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); } } // we do not want to test for extensions here if (dataType.equalsIgnoreCase("parent") || dataType.equalsIgnoreCase("vocabulary") || dataType.equalsIgnoreCase("text") || dataType.equalsIgnoreCase("sequencing") || dataType.equalsIgnoreCase("metadata") || dataType.equalsIgnoreCase("decimal")) { // SCORM 3rd edition -- we need to ignore // (sub)manifest // and warn only if (currentChildName.equals("manifest") && path.equals("manifest")) { msgText = Messages.getString("CPValidator.100"); mLogger.debug("WARNING: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.WARNING, msgText)); // Make cleansing call for excess baggage here // pass (sub)manifest node into a new function // retrieve all adlcp:location uri's contained // in the // (sub)manifest List<String> submanifestURIList = mManifestHandler.getLocationMD(currentChild); trackSubManifest(currentChild, submanifestURIList); } else // we are not dealing with (sub)manifest { msgText = Messages.getString("CPValidator.131", currentChildName); mLogger.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); multiplicityUsed = getMultiplicityUsed(iTestSubjectNode, currentChildName); // get the min rule and convert to an int minRule = Integer .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "min")); // get the max rule and convert to an int maxRule = Integer .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "max")); if ((minRule != -1) && (maxRule != -1)) { if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) { msgText = Messages.getString("CPValidator.135", currentChildName); mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("CPValidator.364", currentChildName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } else if ((minRule != -1) && (maxRule == -1)) { if (multiplicityUsed >= minRule) { msgText = Messages.getString("CPValidator.135", currentChildName); mLogger.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("CPValidator.364", currentChildName); mLogger.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } // test for each particular data type if (dataType.equalsIgnoreCase("parent")) { // need to populate the files that belong to // each resource if (currentChildName.equals("resources")) { populateResourceTable(currentChild); } // Verify that if the resource href matches // the file href if the resource is local if (currentChildName.equals("resource")) { result = checkResourceFileHref(currentChild) && result; } // This is a parent element, need to recurse result = compareToRules(currentChild, path) && result; } else if (dataType.equalsIgnoreCase("sequencing")) { // This is a sequencing data type SequenceValidator sequenceValidator = new SequenceValidator(); result = sequenceValidator.validate(currentChild) && result; } else if (dataType.equalsIgnoreCase("metadata")) { // This is a metadata data type - no longer // need // to // check for lom and location to coexist // must detect that the metadata exists in // location if (currentChildName.equals("location")) { String currentLocationValue = mRulesValidator.getTaggedData(currentChild); // check to ensure there are no leading // slashes result = checkForSlashes("location", currentLocationValue) && result; currentLocationValue = applyXMLBase(currentLocationValue); result = result && checkHref(currentLocationValue); } } else if (dataType.equalsIgnoreCase("text")) { // This is a text data type // check spm // first must retrieve the value of this // child // element String currentChildValue = mRulesValidator.getTaggedData(currentChild); // get the spm rule and convert to an int spmRule = Integer .parseInt(mRulesValidator.getRuleValue(currentChildName, path, "spm")); result = checkSPMConformance(currentChildName, currentChildValue, spmRule, false) && result; } else if (dataType.equalsIgnoreCase("vocabulary")) { // This is a vocabulary data type // more than one vocabulary token may exist msgText = Messages.getString("CPValidator.383", currentChildName); mLogger.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); // retrieve the value of this element String currentChildValue = mRulesValidator.getTaggedData(currentChild); List<String> vocabValues = mRulesValidator.getVocabRuleValues(currentChildName, path); result = checkVocabulary(currentChildName, currentChildValue, vocabValues, false) && result; } else if (dataType.equalsIgnoreCase("decimal")) { // This is a decimal data type // only adlcp:completionThreshold is of this // type // and currently all checks are enforced by // the schema. No additional checks needed // at // this time. result = true && result; } } } // end ignorning and warning (sub)manifest } // end something } } // remove the xml:base value for this particular element if (parentNodeName.equals("manifest")) { mXMLBase[0][1] = ""; } else if (parentNodeName.equals("resources")) { mXMLBase[1][1] = ""; } else if (parentNodeName.equals("resource")) { mXMLBase[2][1] = ""; } break; } // handle entity reference nodes case Node.ENTITY_REFERENCE_NODE: { break; } // text case Node.COMMENT_NODE: { break; } case Node.CDATA_SECTION_NODE: { break; } case Node.TEXT_NODE: { break; } default: { // Do nothing - no defined requirements to process any other // type of node type break; } }// end switch statement mLogger.debug("CPValidator compareToRules()"); return result; }
From source file:org.adl.validator.RulesValidator.java
/** * Retrieves the value of the desired attribute. * * @param iNode Node which contains the attributes. * * @param iAttribute Name of the attribute desired * * @return String: Value of the desired attribute */// ww w. j ava2s . c om protected String getAttribute(Node iNode, String iAttribute) { String returnValue = ""; // grab attributes of the node Attr attrs[] = sortAttributes(iNode.getAttributes()); // now see if the asked for attribute exists and send // back the value Attr attribute; for (Attr attr : attrs) { attribute = attr; //if ( attribute.getName().equals( theAttribute ) ) if (attribute.getLocalName().equals(iAttribute)) { returnValue = attribute.getValue(); break; } } return returnValue; }
From source file:org.adl.validator.sequence.SequenceValidator.java
/** * This method validates the attribute values based on the rules defined * in the SCORM Application Profile rules. *//from w ww.ja va 2s .c om * @param iNode element parent node of the attribute being validated * @param iNodeName Parent element node name * @param iPath path of the rule to compare to * * @return True if the value is a valid vocab token, * false otherwise. * */ public boolean checkAttributes(Node iNode, String iNodeName, String iPath) { String dataType = null; boolean result = true; String msgText = ""; int multiplicityUsed = -1; NamedNodeMap attrList = iNode.getAttributes(); int numAttr = attrList.getLength(); log.debug("There are " + numAttr + " attributes of " + iNodeName + " to test"); // SPECIAL CASE: check for mandatory/shall not exist attributes on // sequencingCollection child elements if (iNodeName.equalsIgnoreCase("sequencing") && iPath.equals("sequencingCollection")) { multiplicityUsed = getMultiplicityUsed(attrList, "ID"); msgText = Messages.getString("SequenceValidator.145"); log.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.INFO, msgText)); if (multiplicityUsed < 1) { msgText = Messages.getString("SequenceValidator.147"); log.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } else { msgText = Messages.getString("SequenceValidator.149"); log.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.PASSED, msgText)); result = true && result; } // IDRef is not allowed to be present multiplicityUsed = getMultiplicityUsed(attrList, "IDRef"); if (multiplicityUsed >= 1) { msgText = Messages.getString("SequenceValidator.152"); log.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } Attr currentAttrNode; String currentNodeName; String attributeValue = null; int minRule = -1; int maxRule = -1; int spmRule = -1; // test the attributes for (int j = 0; j < numAttr; j++) { currentAttrNode = (Attr) attrList.item(j); currentNodeName = currentAttrNode.getLocalName(); dataType = mRulesValidator.getRuleValue(iNodeName, iPath, "datatype", currentNodeName); // make sure that this is a SCORM recognized attribute if (!dataType.equalsIgnoreCase("-1")) { msgText = Messages.getString("SequenceValidator.156", currentNodeName); log.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance().addMessage(new LogMessage(MessageType.INFO, msgText)); // check for multiplicity if the attribute is not deprecated if (!dataType.equalsIgnoreCase("deprecated")) { multiplicityUsed = getMultiplicityUsed(attrList, currentNodeName); // We will assume that no attribute can exist more than // once (ever). According to W3C. Therefore, min and max // rules must exist. //get the min rule and convert to an int minRule = Integer .parseInt(mRulesValidator.getRuleValue(iNodeName, iPath, "min", currentNodeName)); //get the max rule and convert to an int maxRule = Integer .parseInt(mRulesValidator.getRuleValue(iNodeName, iPath, "max", currentNodeName)); if ((minRule != -1) || (maxRule != -1)) { if (multiplicityUsed >= minRule && multiplicityUsed <= maxRule) { msgText = Messages.getString("SequenceValidator.162", currentNodeName); log.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); } else { msgText = Messages.getString("SequenceValidator.165", currentNodeName); log.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } } //get the spm rule and convert to an int spmRule = Integer .parseInt(mRulesValidator.getRuleValue(iNodeName, iPath, "spm", currentNodeName)); attributeValue = currentAttrNode.getValue(); } // check the contents of the attribute if (dataType.equalsIgnoreCase("idref")) { // This is a IDREF data type } else if (dataType.equalsIgnoreCase("id")) { // This is a ID data type } else if (dataType.equalsIgnoreCase("vocabulary")) { // This is a VOCAB data type // retrieve the vocab rule values and check against the // vocab values that exist within the test subject msgText = Messages.getString("SequenceValidator.172", currentNodeName); log.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); List<String> vocabAttribValues = mRulesValidator.getAttribVocabRuleValues(iNodeName, iPath, currentNodeName); // we are assuming that only 1 vocabulary value may // exist for an attribute result = checkVocabulary(currentNodeName, attributeValue, vocabAttribValues, true) && result; } else if (dataType.equalsIgnoreCase("deprecated")) { // This is a deprecated attribute msgText = Messages.getString("SequenceValidator.176", currentNodeName); log.debug("FAILED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.FAILED, msgText)); result = false; } else if (dataType.equalsIgnoreCase("text")) { //This is a TEXT data type // check the attributes for smallest permitted maximum // (spm) conformance. result = checkSPMConformance(currentNodeName, attributeValue, spmRule, true) && result; // we have to store the referencedObjective attribute to // validate that it references a primary or objective identifier if (currentNodeName.equals("referencedObjective")) { mReferencedObjectiveList.add(attributeValue); } } else if (dataType.equalsIgnoreCase("boolean")) { //This is a BOOLEAN data type } else if (dataType.equalsIgnoreCase("decimal")) { //This is a DECIMAL data type } else if (dataType.equalsIgnoreCase("integer")) { //This is a INTEGER data type } else if (dataType.equalsIgnoreCase("duration") || dataType.equalsIgnoreCase("dateTime")) { msgText = Messages.getString("SequenceValidator.185", currentNodeName); log.debug("INFO: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.INFO, msgText)); // We can assume that the schema validation has validated // the format. msgText = Messages.getString("SequenceValidator.188", currentNodeName); log.debug("PASSED: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.PASSED, msgText)); if (currentNodeName.equals("attemptExperiencedDurationLimit") || currentNodeName.equals("activityAbsoluteDurationLimit") || currentNodeName.equals("activityExperiencedDurationLimit") || currentNodeName.equals("beginTimeLimit") || currentNodeName.equals("endTimeLimit")) { // this attribute is out of scope of SCORM msgText = Messages.getString("SequenceValidator.196", currentNodeName); log.warn("WARNING: " + msgText); DetailedLogMessageCollection.getInstance() .addMessage(new LogMessage(MessageType.WARNING, msgText)); } } else { // it is an extension element } } } return result; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
@SuppressWarnings("unchecked") public static void rebuildInstance(final Node prototypeNode, final Node oldInstanceNode, final Node newInstanceNode, final HashMap<String, String> schemaNamespaces) { final JXPathContext prototypeContext = JXPathContext.newContext(prototypeNode); prototypeContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); final JXPathContext instanceContext = JXPathContext.newContext(oldInstanceNode); instanceContext.registerNamespace(NamespaceService.ALFRESCO_PREFIX, NamespaceService.ALFRESCO_URI); for (final String prefix : schemaNamespaces.keySet()) { prototypeContext.registerNamespace(prefix, schemaNamespaces.get(prefix)); instanceContext.registerNamespace(prefix, schemaNamespaces.get(prefix)); }/*from w w w .j a v a 2s. c om*/ // Evaluate non-recursive XPaths for all prototype elements at this level final Iterator<Pointer> it = prototypeContext.iteratePointers("*"); while (it.hasNext()) { final Pointer p = it.next(); Element proto = (Element) p.getNode(); String path = p.asPath(); // check if this is a prototype element with the attribute set boolean isPrototype = proto.hasAttributeNS(NamespaceService.ALFRESCO_URI, "prototype") && proto.getAttributeNS(NamespaceService.ALFRESCO_URI, "prototype").equals("true"); // We shouldn't locate a repeatable child with a fixed path if (isPrototype) { path = path.replaceAll("\\[(\\d+)\\]", "[position() >= $1]"); if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] evaluating prototyped nodes " + path); } } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] evaluating child node with positional path " + path); } } Document newInstanceDocument = newInstanceNode.getOwnerDocument(); // Locate the corresponding nodes in the instance document List<Node> l = (List<Node>) instanceContext.selectNodes(path); // If the prototype node isn't a prototype element, copy it in as a missing node, complete with all its children. We won't need to recurse on this node if (l.isEmpty()) { if (!isPrototype) { LOGGER.debug("[rebuildInstance] copying in missing node " + proto.getNodeName() + " to " + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement())); // Clone the prototype node and all its children Element clone = (Element) proto.cloneNode(true); newInstanceNode.appendChild(clone); if (oldInstanceNode instanceof Document) { // add XMLSchema instance NS addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, NamespaceConstants.XMLSCHEMA_INSTANCE_NS); } } } else { // Otherwise, append the matches from the old instance document in order for (Node old : l) { Element oldEl = (Element) old; // Copy the old instance element rather than cloning it, so we don't copy over attributes Element clone = null; String nSUri = oldEl.getNamespaceURI(); if (nSUri == null) { clone = newInstanceDocument.createElement(oldEl.getTagName()); } else { clone = newInstanceDocument.createElementNS(nSUri, oldEl.getTagName()); } newInstanceNode.appendChild(clone); if (oldInstanceNode instanceof Document) { // add XMLSchema instance NS addNamespace(clone, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX, NamespaceConstants.XMLSCHEMA_INSTANCE_NS); } // Copy over child text if this is not a complex type boolean isEmpty = true; for (Node n = old.getFirstChild(); n != null; n = n.getNextSibling()) { if (n instanceof Text) { clone.appendChild(newInstanceDocument.importNode(n, false)); isEmpty = false; } else if (n instanceof Element) { break; } } // Populate the nil attribute. It may be true or false if (proto.hasAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, "nil")) { clone.setAttributeNS(NamespaceConstants.XMLSCHEMA_INSTANCE_NS, NamespaceConstants.XMLSCHEMA_INSTANCE_PREFIX + ":nil", String.valueOf(isEmpty)); } // Copy over attributes present in the prototype NamedNodeMap attributes = proto.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Attr attribute = (Attr) attributes.item(i); String localName = attribute.getLocalName(); if (localName == null) { String name = attribute.getName(); if (oldEl.hasAttribute(name)) { clone.setAttributeNode( (Attr) newInstanceDocument.importNode(oldEl.getAttributeNode(name), false)); } else { LOGGER.debug("[rebuildInstance] copying in missing attribute " + attribute.getNodeName() + " to " + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement())); clone.setAttributeNode((Attr) attribute.cloneNode(false)); } } else { String namespace = attribute.getNamespaceURI(); if (!((!isEmpty && (namespace.equals(NamespaceConstants.XMLSCHEMA_INSTANCE_NS) && localName.equals("nil")) || (namespace.equals(NamespaceService.ALFRESCO_URI) && localName.equals("prototype"))))) { if (oldEl.hasAttributeNS(namespace, localName)) { clone.setAttributeNodeNS((Attr) newInstanceDocument .importNode(oldEl.getAttributeNodeNS(namespace, localName), false)); } else { LOGGER.debug("[rebuildInstance] copying in missing attribute " + attribute.getNodeName() + " to " + XMLUtil.buildXPath(clone, newInstanceDocument.getDocumentElement())); clone.setAttributeNodeNS((Attr) attribute.cloneNode(false)); } } } } // recurse on children rebuildInstance(proto, oldEl, clone, schemaNamespaces); } } // Now add in a new copy of the prototype if (isPrototype) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("[rebuildInstance] appending " + proto.getNodeName() + " to " + XMLUtil.buildXPath(newInstanceNode, newInstanceDocument.getDocumentElement())); } newInstanceNode.appendChild(proto.cloneNode(true)); } } }
From source file:org.apache.axis.encoding.SerializationContext.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element/*from www. j ava2 s . co m*/ */ public void writeDOMElement(Element el) throws IOException { if (startOfDocument && sendXMLDecl) { writeXMLDeclaration(); } // If el is a Text element, write the text and exit if (el instanceof org.apache.axis.message.Text) { writeSafeString(((Text) el).getData()); return; } AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr) attrMap.item(i); String tmp = attr.getNamespaceURI(); if (tmp != null && tmp.equals(Constants.NS_URI_XMLNS)) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if (namespaceURI == null || namespaceURI.length() == 0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element) child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text) child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData) child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text) child).getData()); } } endElement(); }
From source file:org.apache.axis.encoding.SerializationContextImpl.java
/** * Output a DOM representation to a SerializationContext * @param el is a DOM Element//www .j av a 2s . c o m */ public void writeDOMElement(Element el) throws IOException { AttributesImpl attributes = null; NamedNodeMap attrMap = el.getAttributes(); if (attrMap.getLength() > 0) { attributes = new AttributesImpl(); for (int i = 0; i < attrMap.getLength(); i++) { Attr attr = (Attr)attrMap.item(i); String tmp = attr.getNamespaceURI(); if ( tmp != null && tmp.equals(Constants.NS_URI_XMLNS) ) { String prefix = attr.getLocalName(); if (prefix != null) { if (prefix.equals("xmlns")) prefix = ""; String nsURI = attr.getValue(); registerPrefixForURI(prefix, nsURI); } continue; } attributes.addAttribute(attr.getNamespaceURI(), attr.getLocalName(), attr.getName(), "CDATA", attr.getValue()); } } String namespaceURI = el.getNamespaceURI(); String localPart = el.getLocalName(); if(namespaceURI == null || namespaceURI.length()==0) localPart = el.getNodeName(); QName qName = new QName(namespaceURI, localPart); startElement(qName, attributes); NodeList children = el.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (child instanceof Element) { writeDOMElement((Element)child); } else if (child instanceof CDATASection) { writeString("<![CDATA["); writeString(((Text)child).getData()); writeString("]]>"); } else if (child instanceof Comment) { writeString("<!--"); writeString(((CharacterData)child).getData()); writeString("-->"); } else if (child instanceof Text) { writeSafeString(((Text)child).getData()); } } endElement(); }
From source file:org.apache.axis.message.MessageElement.java
/** * remove a an attribue//from w w w . j a v a 2 s .c o m * @param oldAttr * @return oldAttr * @throws DOMException */ public Attr removeAttributeNode(Attr oldAttr) throws DOMException { makeAttributesEditable(); Name name = new PrefixedQName(oldAttr.getNamespaceURI(), oldAttr.getLocalName(), oldAttr.getPrefix()); removeAttribute(name); return oldAttr; }
From source file:org.apache.axis.message.MessageElement.java
/** * set an attribute as a node/* www.j a v a 2s. c o m*/ * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr) * @todo implement properly. * @param newAttr * @return null * @throws DOMException */ public Attr setAttributeNodeNS(Attr newAttr) throws DOMException { //attributes. AttributesImpl attributes = makeAttributesEditable(); // how to convert to DOM ATTR attributes.addAttribute(newAttr.getNamespaceURI(), newAttr.getLocalName(), newAttr.getLocalName(), "CDATA", newAttr.getValue()); return null; }