nu.xom.ValidityException Java Examples

The following examples show how to use nu.xom.ValidityException. 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: XmlEntity.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Use the CacheXmlGenerator to create XML from the entity associated with
 * the current cache.
 * 
 * @param element Name of the XML element to search for.
 * @param attributes
 *          Attributes of the element that should match, for example "name" or
 *          "id" and the value they should equal.
 * 
 * @return XML string representation of the entity.
 */
private final String loadXmlDefinition(final String element, final Map<String, String> attributes) {
  final Cache cache = CacheFactory.getAnyInstance();
  Document document = null;

  try {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    CacheXmlGenerator.generate(cache, printWriter, false, false, false);
    printWriter.close();

    // Remove the DOCTYPE line when getting the string to prevent
    // errors when trying to locate the DTD.
    String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", "");
    document = new Builder(false).build(xml, null);

  } catch (ValidityException vex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", vex);

  } catch (ParsingException pex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", pex);
    
  } catch (IOException ioex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex);
  }
  
  Nodes nodes = document.query(createQueryString(element, attributes));
  if (nodes.size() != 0) {
    return nodes.get(0).toXML();
  }
  
  cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes);
  return null;
}
 
Example #2
Source File: XmlEntity.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Use the CacheXmlGenerator to create XML from the entity associated with
 * the current cache.
 * 
 * @param element Name of the XML element to search for.
 * @param attributes
 *          Attributes of the element that should match, for example "name" or
 *          "id" and the value they should equal.
 * 
 * @return XML string representation of the entity.
 */
private final String loadXmlDefinition(final String element, final Map<String, String> attributes) {
  final Cache cache = CacheFactory.getAnyInstance();
  Document document = null;

  try {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    CacheXmlGenerator.generate(cache, printWriter, false, false, false);
    printWriter.close();

    // Remove the DOCTYPE line when getting the string to prevent
    // errors when trying to locate the DTD.
    String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", "");
    document = new Builder(false).build(xml, null);

  } catch (ValidityException vex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", vex);

  } catch (ParsingException pex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", pex);
    
  } catch (IOException ioex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex);
  }
  
  Nodes nodes = document.query(createQueryString(element, attributes));
  if (nodes.size() != 0) {
    return nodes.get(0).toXML();
  }
  
  cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes);
  return null;
}
 
Example #3
Source File: HtmlBuilder.java    From caja with Apache License 2.0 3 votes vote down vote up
/**
 * Parse from <code>InputStream</code>.
 * @param stream the stream
 * @param uri the base URI
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.io.InputStream, java.lang.String)
 */
@Override
public Document build(InputStream stream, String uri)
        throws ParsingException, ValidityException, IOException {
    InputSource is = new InputSource(stream);
    is.setSystemId(uri);
    return build(is);
}
 
Example #4
Source File: HtmlBuilder.java    From caja with Apache License 2.0 3 votes vote down vote up
/**
 * Parse from <code>Reader</code>.
 * @param stream the reader
 * @param uri the base URI
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.io.Reader, java.lang.String)
 */
@Override
public Document build(Reader stream, String uri) throws ParsingException,
        ValidityException, IOException {
    InputSource is = new InputSource(stream);
    is.setSystemId(uri);
    return build(is);
}
 
Example #5
Source File: HtmlBuilder.java    From caja with Apache License 2.0 2 votes vote down vote up
/**
 * Parse from <code>File</code>.
 * @param file the file
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.io.File)
 */
@Override
public Document build(File file) throws ParsingException,
        ValidityException, IOException {
    return build(new FileInputStream(file), file.toURI().toASCIIString());
}
 
Example #6
Source File: HtmlBuilder.java    From caja with Apache License 2.0 2 votes vote down vote up
/**
 * Parse from <code>InputStream</code>.
 * @param stream the stream
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.io.InputStream)
 */
@Override
public Document build(InputStream stream) throws ParsingException,
        ValidityException, IOException {
    return build(new InputSource(stream));
}
 
Example #7
Source File: HtmlBuilder.java    From caja with Apache License 2.0 2 votes vote down vote up
/**
 * Parse from <code>Reader</code>.
 * @param stream the reader
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.io.Reader)
 */
@Override
public Document build(Reader stream) throws ParsingException,
        ValidityException, IOException {
    return build(new InputSource(stream));
}
 
Example #8
Source File: HtmlBuilder.java    From caja with Apache License 2.0 2 votes vote down vote up
/**
 * Parse from <code>String</code>.
 * @param content the HTML source as string
 * @param uri the base URI
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.lang.String, java.lang.String)
 */
@Override
public Document build(String content, String uri) throws ParsingException,
        ValidityException, IOException {
    return build(new StringReader(content), uri);
}
 
Example #9
Source File: HtmlBuilder.java    From caja with Apache License 2.0 2 votes vote down vote up
/**
 * Parse from URI.
 * @param uri the URI of the document
 * @return the document
 * @throws ParsingException in case of an XML violation
 * @throws IOException if IO goes wrang
 * @see nu.xom.Builder#build(java.lang.String)
 */
@Override
public Document build(String uri) throws ParsingException,
        ValidityException, IOException {
    return build(new InputSource(uri));
}