XMLUtils.java revision 41202e15f589286770cacca433bbee5df379d00b
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: XMLUtils.java,v 1.5 2008/06/25 05:41:28 qcheng Exp $
*
*/
/**
* Portions Copyrighted [2011] [ForgeRock AS]
*/
/**
* This class contains utilities to parse XML documents
(
* @deprecated As of OpenSSO version 8.0
* {@link com.sun.identity.shared.xml.XMLUtils}
*/
public class XMLUtils {
.unmodifiableMap(new HashMap());
// property to see if XML document validating is needed. The validating
// is turned on only if the value for com.iplanet.am.util.xml.validating
// property is set to "on" and value for com.iplanet.services.debug.level
// property is set to "warning" or "message".
private static boolean validating = false;
static {
try {
"off");
validating = true;
}
} catch (Exception e) {
// ignore since there is not debug class here
}
}
/**
* Converts the XML document from a String format to DOM Document format.
*
* @param xmlString
* is the XML document in a String format
* @param debug
* is the debug object used for logging debug info
* @return Document is the DOM object obtained by converting the String XML
* Returns null if xmlString is null. Returns null if there are any
* parser errores.
*/
return null;
}
try {
.getBytes("UTF-8"));
} catch (UnsupportedEncodingException uee) {
uee);
}
return null;
}
}
/**
* Converts the XML document from an input stream to DOM Document format.
*
* @param is
* is the InputStream that contains XML document
* @return Document is the DOM object obtained by parsing the input stream.
* Returns null if there are any parser errores.
*/
/*
* Constructing a DocumentBuilderFactory for every call is less
* expensive than a synchronizing a single instance of the factory and
* obtaining the builder
*/
try {
// Assign new debug object
dbFactory.setNamespaceAware(true);
} catch (Exception e) {
}
}
try {
if (documentBuilder == null) {
}
return null;
}
debug));
}
} catch (Exception e) {
// Since there may potentially be several invalid XML documents
// that are mostly client-side errors, only a warning is logged for
// efficiency reasons.
}
return null;
}
}
/**
* This method parse an Attributes tag, DTD for Attribute is as follows.
*
* <pre>
* < !-- This DTD defines the DPro Attribute tag.
* Unique Declaration name for DOCTYPE tag:
* "Directory Pro 5.0 Attributes DTD"
* -->
* < !ELEMENT Attributes (Attribute)+>
* < !ELEMENT Attribute EMPTY>
* < !ATTLIST Attribute
* name NMTOKEN #REQUIRED
* >
* </pre>
*
* @param n
* Node
* @return Set Set of the attribute names
*/
// get Attribute node list
if (numAttributes == 0) {
return null;
}
for (int l = 0; l < numAttributes; l++) {
// get next attribute
// need error handling
continue;
}
}
return set;
}
/**
* @param parentNode
* is the element tag that contains all the AttirbuteValuePair
* tags as children
* @return Map Returns the AV pairs in a Map where each entry in the Map is
* an AV pair. The key is the attribute name and the value is a Set
* of String objects.
*/
if (numAVPairs <= 0) {
return EMPTY_MAP;
}
for (int l = 0; l < numAVPairs; l++) {
continue;
}
if (numLeafNodes < 2) {
// TODO: More error handling required later for missing
// 'Attribute' or
// 'Value' tags.
continue;
}
// Since Attribute tag is always the first leaf node as per the
// DTD,and
// values can one or more, Attribute tag can be parsed first and
// then
// iterate over the values, if any.
for (int i = 0; i < numLeafNodes; i++) {
i = (int) numLeafNodes;
} else {
continue;
}
}
// Now parse the Value tags. If there are not 'Value' tags, ignore
// this key
// TODO: More error handling required later for zero 'Value' tags.
for (int m = 0; m < numLeafNodes; m++) {
// TODO: Error handling required here
continue;
}
}
}
}
}
// No 'Value' tags found. So ignore this key.
// TODO: More error handling required later for zero
// 'Value'tags.
continue;
}
}
// now reset values to prepare for the next AV pair.
}
return EMPTY_MAP;
} else {
return map;
}
}
/**
* Obtains a new instance of a DOM Document object
*
* @return a new instance of a DOM Document object
* @exception Exception
* if an error occurs while constructing a new document
*/
dbFactory.setNamespaceAware(true);
}
try {
.newInstance();
return (doc);
} catch (SAXParseException pe) {
} catch (SAXException sax) {
} catch (ParserConfigurationException pc) {
} catch (IOException ioe) {
}
}
return (null);
}
return (node);
}
return (null);
}
/**
* Checks if a node has a child of ELEMENT type.
*
* @param node
* a node
* @return true if the node has a child of ELEMENT type
*/
for (int i = 0; i < length; i++) {
return true;
}
}
return false;
}
/**
* Returns a child node that has the given node name and give attribute name
* and value.
*/
return (node);
}
}
return (null);
}
}
}
return (retVal);
}
/**
* Gets the value of an element. This method returns a concatenated String
* from all its TEXT children.
*
* @param element
* a DOM tree element.
* @return A String that contained in its TEXT children; or null if an error
* occurred.
*/
return null;
}
for (int i = 0; i < length; i++) {
}
}
}
/**
* Gets the value of an element. This method returns a concatenated String
* from all its TEXT children.
*
* @param element
* a DOM tree element.
* @return A String that contained in its TEXT children; or null if an error
* occurred or the input contain non Node.TEXT_NODE node.
*/
return null;
}
} else {
return null;
}
}
}
return (null);
return (null);
return (value.getNodeValue());
}
/**
* Gets attribute value of a node.
*
* @param node
* a node
* @param namespaceURI
* attribute namespace URI
* @param attrName
* attribute name
* @return attribute value
*/
return null;
}
return null;
}
return value.getNodeValue();
}
/**
* Method to get Values within AttributeValuePair as a java.util.Set
*/
return (null);
}
}
return (retVal);
}
/**
* Method to get the value of "Value" node
*/
}
}
/**
* This method searches children of Element element for element with tagName
* and namespaceURI nsName. It searchs one level down only.
*
* @param element
* The root element
* @param nsName
* NamespaceURI
* @param tagName
* A String representing the name of the tag to be searched for.
* @return A List of elements that meet the criterial.
*/
for (int i = 0; i < length; i++) {
}
}
}
return list;
}
/**
* Print SAML Attribute Element and replace its prefix with the input
* prefix.
*
* @param node
* A DOM tree Node
* @param prefix
* A String representing the new prefix
* @return An xml String representation of the DOM tree.
*/
return null;
}
for (int i = 0; i < length; i++) {
// xml.append(normalize(attr.getNodeValue()));
}
for (int i = 0; i < len; i++) {
}
}
}
/**
* Print a Node tree recursively.
*
* @param node
* A DOM tree Node
* @return An xml String representation of the DOM tree.
*/
return null;
}
try {
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* Replaces XML special character <code>&</code>, <code><</code>,
* <code>></code>, <code>"</code>, <code>'</code> with
* corresponding entity references.
*
* @return String with the special characters replaced with entity
* references.
*/
int len = 0;
}
int i = 0;
boolean specialCharacterFound = false;
for (; i < len; i++) {
if (c == '&' || c == '<' || c == '>' || c == '\'' || c == '\"'
|| c == '\n') {
specialCharacterFound = true;
break;
}
}
if (specialCharacterFound) {
sb = new StringBuffer();
for (; i < len; i++) {
switch (c) {
case '&':
break;
case '<':
break;
case '>':
break;
case '\"':
break;
case '\'':
break;
case '\n':
break;
default:
}
}
}
return escapedText;
}
}
class ValidationErrorHandler implements ErrorHandler {
}
}
}
}
}
}
}
}