Java Code Examples for org.w3c.dom.DOMException#getMessage()

The following examples show how to use org.w3c.dom.DOMException#getMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NodeCreateRule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Appends a {@link org.w3c.dom.Text Text} node to the current node
 * if the content reported by the parser is not purely whitespace.
 */
private void addTextIfPresent() throws SAXException {
    if (topText.length() > 0) {
        String str = topText.toString();
        topText.setLength(0);

        if (str.trim().length() > 0) {
            // The contained text is not *pure* whitespace, so create
            // a text node to hold it. Note that the "untrimmed" text
            // is stored in the node.
            try {
                top.appendChild(doc.createTextNode(str));
            } catch (DOMException e) {
                throw new SAXException(e.getMessage());
            }
        }
    }
}
 
Example 2
Source File: DAOUtility.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
public org.w3c.dom.Document buildNewDOM() throws DAOException {
    org.w3c.dom.Document document = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (ParserConfigurationException pce) {
        logger.error(pce.getLocalizedMessage());
        throw new DAOException(pce.getMessage());
    } catch (DOMException doe) {
        logger.error(doe.getLocalizedMessage());
        throw new DAOException(doe.getMessage());
    }
    return document;
}
 
Example 3
Source File: XMLReader.java    From oopsla15-artifact with Eclipse Public License 1.0 6 votes vote down vote up
public IValue read(IValueFactory factory, TypeStore store, Type type, Reader stream)
		throws FactTypeUseException, IOException {
	this.vf = factory;
	this.ts = store;
	
	try {
		Document doc = domFactory.newDocumentBuilder().parse(new InputSource(stream));
		return parse(doc.getDocumentElement(), type);
	} catch (SAXException se) {
		throw new IOException("Parsing of value failed because XML was invalid: " + se.getMessage());
	} catch (ParserConfigurationException pce) {
		throw new IOException("Parsing of value failed because XML configuration is wrong: " + pce.getMessage());
	} catch (DOMException de) {
		throw new IOException("Parsing of value failed because of a XML document failure: " + de.getMessage());
	} catch (NumberFormatException nfe) {
		throw new FactParseError("Expected a number, got something different", nfe);
	}
}
 
Example 4
Source File: NodeCreateRule.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether control needs to be returned to Digester.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void endElement(String namespaceURI, String localName,
                       String qName)
    throws SAXException {
    
    try {
        if (depth == 0) {
            getDigester().getXMLReader().setContentHandler(
                oldContentHandler);
            getDigester().push(root);
            getDigester().endElement(namespaceURI, localName, qName);
        }
    
        top = top.getParentNode();
        depth--;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 5
Source File: NodeCreateRule.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks whether control needs to be returned to Digester.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void endElement(String namespaceURI, String localName,
                       String qName)
    throws SAXException {
    
    addTextIfPresent();

    try {
        if (depth == 0) {
            getDigester().setCustomContentHandler(oldContentHandler);
            getDigester().push(root);
            getDigester().endElement(namespaceURI, localName, qName);
        }
    
        top = top.getParentNode();
        depth--;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage());
    }

}
 
Example 6
Source File: STSServiceWsTrustImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Element getToken(Credential headerCredentials, Credential bodyCredentials, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, String authenticationMethod, String nameQualifier, String value, String subjectConfirmationMethod, int validity) throws TechnicalConnectorException {
   try {
      Element issuePayload = null;
      if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(subjectConfirmationMethod)) {
         issuePayload = this.issueHokToken(bodyCredentials, attributes, designators, validity);
      } else {
         if (!"urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(subjectConfirmationMethod)) {
            throw new UnsupportedOperationException("SubjectConfirmationMethod [" + subjectConfirmationMethod + "] not supported.");
         }

         SAMLNameIdentifier nameId = this.generateNameIdentifier(bodyCredentials, nameQualifier, value);
         issuePayload = this.issueSVToken(nameId, authenticationMethod, attributes, designators, validity);
      }

      return this.processRequest(headerCredentials, bodyCredentials, issuePayload);
   } catch (SOAPException var12) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var12, new Object[]{var12.getMessage()});
   } catch (DOMException var13) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var13, new Object[]{var13.getMessage()});
   }
}
 
Example 7
Source File: NodeCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Checks whether control needs to be returned to Digester.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void endElement(String namespaceURI, String localName,
                       String qName)
    throws SAXException {
    
    try {
        if (depth == 0) {
            getDigester().getXMLReader().setContentHandler(
                oldContentHandler);
            getDigester().push(root);
            getDigester().endElement(namespaceURI, localName, qName);
        }
    
        top = top.getParentNode();
        depth--;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 8
Source File: STSServiceWsTrustImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Element getToken(@NotNull Credential headerCredentials, @NotNull Credential bodyCredentials, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, String authenticationMethod, String nameQualifier, String value, String subjectConfirmationMethod, int validity) throws TechnicalConnectorException {
   try {
      Element issuePayload = null;
      if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(subjectConfirmationMethod)) {
         issuePayload = this.issueHokToken(bodyCredentials, attributes, designators, validity);
      } else {
         if (!"urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(subjectConfirmationMethod)) {
            throw new UnsupportedOperationException("SubjectConfirmationMethod [" + subjectConfirmationMethod + "] not supported.");
         }

         SAMLNameIdentifier nameId = this.generateNameIdentifier(bodyCredentials, nameQualifier, value);
         issuePayload = this.issueSVToken(nameId, authenticationMethod, attributes, designators, validity);
      }

      return this.processRequest(headerCredentials, bodyCredentials, issuePayload);
   } catch (SOAPException var12) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var12, new Object[]{var12.getMessage()});
   } catch (DOMException var13) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var13, new Object[]{var13.getMessage()});
   }
}
 
Example 9
Source File: STSServiceWsTrustImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Element getToken(Credential headerCredentials, Credential bodyCredentials, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, String authenticationMethod, String nameQualifier, String value, String subjectConfirmationMethod, int validity) throws TechnicalConnectorException {
   try {
      Element issuePayload = null;
      if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(subjectConfirmationMethod)) {
         issuePayload = this.issueHokToken(bodyCredentials, attributes, designators, validity);
      } else {
         if (!"urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(subjectConfirmationMethod)) {
            throw new UnsupportedOperationException("SubjectConfirmationMethod [" + subjectConfirmationMethod + "] not supported.");
         }

         SAMLNameIdentifier nameId = this.generateNameIdentifier(bodyCredentials, nameQualifier, value);
         issuePayload = this.issueSVToken(nameId, authenticationMethod, attributes, designators, validity);
      }

      return this.processRequest(headerCredentials, bodyCredentials, issuePayload);
   } catch (SOAPException var12) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var12, new Object[]{var12.getMessage()});
   } catch (DOMException var13) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var13, new Object[]{var13.getMessage()});
   }
}
 
Example 10
Source File: STSServiceWsTrustImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Element getToken(Credential headerCredentials, Credential bodyCredentials, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, String authenticationMethod, String nameQualifier, String value, String subjectConfirmationMethod, int validity) throws TechnicalConnectorException {
   try {
      Element issuePayload = null;
      if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(subjectConfirmationMethod)) {
         issuePayload = this.issueHokToken(bodyCredentials, attributes, designators, validity);
      } else {
         if (!"urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(subjectConfirmationMethod)) {
            throw new UnsupportedOperationException("SubjectConfirmationMethod [" + subjectConfirmationMethod + "] not supported.");
         }

         SAMLNameIdentifier nameId = this.generateNameIdentifier(bodyCredentials, nameQualifier, value);
         issuePayload = this.issueSVToken(nameId, authenticationMethod, attributes, designators, validity);
      }

      return this.processRequest(headerCredentials, bodyCredentials, issuePayload);
   } catch (SOAPException var12) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var12, new Object[]{var12.getMessage()});
   } catch (DOMException var13) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var13, new Object[]{var13.getMessage()});
   }
}
 
Example 11
Source File: STSServiceWsTrustImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public Element getToken(Credential headerCredentials, Credential bodyCredentials, List<SAMLAttribute> attributes, List<SAMLAttributeDesignator> designators, String authenticationMethod, String nameQualifier, String value, String subjectConfirmationMethod, int validity) throws TechnicalConnectorException {
   try {
      Element issuePayload = null;
      if ("urn:oasis:names:tc:SAML:1.0:cm:holder-of-key".equals(subjectConfirmationMethod)) {
         issuePayload = this.issueHokToken(bodyCredentials, attributes, designators, validity);
      } else {
         if (!"urn:oasis:names:tc:SAML:1.0:cm:sender-vouches".equals(subjectConfirmationMethod)) {
            throw new UnsupportedOperationException("SubjectConfirmationMethod [" + subjectConfirmationMethod + "] not supported.");
         }

         SAMLNameIdentifier nameId = this.generateNameIdentifier(bodyCredentials, nameQualifier, value);
         issuePayload = this.issueSVToken(nameId, authenticationMethod, attributes, designators, validity);
      }

      return this.processRequest(headerCredentials, bodyCredentials, issuePayload);
   } catch (SOAPException var12) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var12, new Object[]{var12.getMessage()});
   } catch (DOMException var13) {
      throw new TechnicalConnectorException(TechnicalConnectorExceptionValues.ERROR_WS, var13, new Object[]{var13.getMessage()});
   }
}
 
Example 12
Source File: NodeCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new
 * {@link org.w3c.dom.ProcessingInstruction ProcessingInstruction} to 
 * the current node.
 * 
 * @param target the processing instruction target
 * @param data the processing instruction data, or null if none was 
 *   supplied
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void processingInstruction(String target, String data)
    throws SAXException {
    
    try {
        top.appendChild(doc.createProcessingInstruction(target, data));
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 13
Source File: NodeCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 14
Source File: NodeCreateRule.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a {@link org.w3c.dom.Text Text} node to the current node.
 * 
 * @param ch the characters from the XML document
 * @param start the start position in the array
 * @param length the number of characters to read from the array
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void characters(char[] ch, int start, int length)
    throws SAXException {

    try {
        String str = new String(ch, start, length);
        if (str.trim().length() > 0) { 
            top.appendChild(doc.createTextNode(str));
        }
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 15
Source File: NodeCreateRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new
 * {@link org.w3c.dom.ProcessingInstruction ProcessingInstruction} to 
 * the current node.
 * 
 * @param target the processing instruction target
 * @param data the processing instruction data, or null if none was 
 *   supplied
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void processingInstruction(String target, String data)
    throws SAXException {
    
    try {
        top.appendChild(doc.createProcessingInstruction(target, data));
    } catch (DOMException e) {
        throw new SAXException(e.getMessage());
    }

}
 
Example 16
Source File: NodeCreateRule.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    addTextIfPresent();

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage());
    }

}
 
Example 17
Source File: NodeCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a {@link org.w3c.dom.Text Text} node to the current node.
 * 
 * @param ch the characters from the XML document
 * @param start the start position in the array
 * @param length the number of characters to read from the array
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void characters(char[] ch, int start, int length)
    throws SAXException {

    try {
        String str = new String(ch, start, length);
        if (str.trim().length() > 0) { 
            top.appendChild(doc.createTextNode(str));
        }
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 18
Source File: NodeCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new
 * {@link org.w3c.dom.ProcessingInstruction ProcessingInstruction} to 
 * the current node.
 * 
 * @param target the processing instruction target
 * @param data the processing instruction data, or null if none was 
 *   supplied
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void processingInstruction(String target, String data)
    throws SAXException {
    
    try {
        top.appendChild(doc.createProcessingInstruction(target, data));
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}
 
Example 19
Source File: NodeCreateRule.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new child {@link org.w3c.dom.Element Element} to the current
 * node.
 * 
 * @param namespaceURI the namespace URI
 * @param localName the local name
 * @param qName the qualified (prefixed) name
 * @param atts the list of attributes
 * @throws SAXException if the DOM implementation throws an exception
 */
@Override
public void startElement(String namespaceURI, String localName,
                         String qName, Attributes atts)
    throws SAXException {

    try {
        Node previousTop = top;
        if ((localName == null) || (localName.length() == 0)) { 
            top = doc.createElement(qName);
        } else {
            top = doc.createElementNS(namespaceURI, localName);
        }
        for (int i = 0; i < atts.getLength(); i++) {
            Attr attr = null;
            if ((atts.getLocalName(i) == null) ||
                (atts.getLocalName(i).length() == 0)) {
                attr = doc.createAttribute(atts.getQName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNode(attr);
            } else {
                attr = doc.createAttributeNS(atts.getURI(i),
                                             atts.getLocalName(i));
                attr.setNodeValue(atts.getValue(i));
                ((Element)top).setAttributeNodeNS(attr);
            }
        }
        previousTop.appendChild(top);
        depth++;
    } catch (DOMException e) {
        throw new SAXException(e.getMessage(), e);
    }

}