Java Code Examples for org.w3c.dom.Document#getInputEncoding()

The following examples show how to use org.w3c.dom.Document#getInputEncoding() . These examples are extracted from open source projects. 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
/**
 * Assertion testing
 * for public String getInputEncoding(),
 * Encoding is not specified. getInputEncoding returns null..
 */
@Test
public void testGetInputEncoding002() {
    Document doc = null;
    try {
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        doc = db.newDocument();
    } catch (ParserConfigurationException e) {
        Assert.fail(e.toString());
    }

    String encoding = doc.getInputEncoding();
    if (encoding != null) {
        Assert.fail("expected encoding: null, returned: " + encoding);
    }

    System.out.println("OK");
}
 
Example 2
Source Project: Bytecoder   File: DOMSerializerImpl.java    License: Apache License 2.0 5 votes vote down vote up
private String _getInputEncoding(Node node) {
    Document doc = (node.getNodeType() == Node.DOCUMENT_NODE)
            ? (Document) node : node.getOwnerDocument();
    if (doc != null) {
        try {
            return doc.getInputEncoding();
        } // The VM ran out of memory or there was some other serious problem. Re-throw.
        catch (VirtualMachineError | ThreadDeath vme) {
            throw vme;
        } // Ignore all other exceptions and errors
        catch (Throwable t) {
        }
    }
    return null;
}
 
Example 3
private String _getInputEncoding(Node node) {
    Document doc = (node.getNodeType() == Node.DOCUMENT_NODE)
            ? (Document) node : node.getOwnerDocument();
    if (doc != null) {
        try {
            return doc.getInputEncoding();
        } // The VM ran out of memory or there was some other serious problem. Re-throw.
        catch (VirtualMachineError | ThreadDeath vme) {
            throw vme;
        } // Ignore all other exceptions and errors
        catch (Throwable t) {
        }
    }
    return null;
}
 
Example 4
/**
 * Constructs a new object from a grammar node. This constructor is intended
 * to be used to capture inline grammars in a VoiceXML document.
 * 
 * @param node
 *            the grammar node
 * @throws UnsupportedEncodingException 
 *          the node contains a grammar with an invalid character set
 */
public InternalGrammarDocument(final Grammar node)
        throws UnsupportedEncodingException {
    // Try getting the encoding of the owner document
    final Document owner = node.getOwnerDocument();
    final String ownerEncoding = owner.getInputEncoding();
    if (ownerEncoding == null) {
        charset = System.getProperty("file.encoding");
    } else {
        charset = ownerEncoding;
    }
    document = null;
    buffer = node.toString().getBytes(charset);
    grammar = node;
}
 
Example 5
Source Project: java-client-api   File: DOMWriter.java    License: Apache License 2.0 5 votes vote down vote up
public void serializeDocument(Document document) throws XMLStreamException {
 
  String encoding = document.getInputEncoding();
  String version  = document.getXmlVersion();
  if (encoding != null) {
    serializer.writeStartDocument(encoding, version);
  } else {
    serializer.writeStartDocument(version);
  }
  if (document.hasChildNodes()) {
    serializeNodeList(document.getChildNodes());
  }
  serializer.writeEndDocument();
}
 
Example 6
public static String serializeToString(Document doc) throws IOException {
	String encoding = doc.getInputEncoding();
	if(encoding == null) encoding = "UTF-8";
	
	return serializeToString(doc, encoding);
}
 
Example 7
Source Project: icafe   File: XMLUtils.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public static String serializeToString(Document doc) throws IOException {
	String encoding = doc.getInputEncoding();
	if(encoding == null) encoding = "UTF-8";
	
	return serializeToString(doc, encoding);
}
 
Example 8
/**
 * Serialize XML Document to string using DOM Level 3 Load/Save
 * 
 * @param doc XML Document
 * @param node the Node to serialize
 * @return String representation of the Document
 * @throws IOException
 */
public static String serializeToStringLS(Document doc, Node node) throws IOException {
	String encoding = doc.getInputEncoding();
       if(encoding == null) encoding = "UTF-8";
       
       return serializeToStringLS(doc, node, encoding);
}
 
Example 9
Source Project: icafe   File: XMLUtils.java    License: Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Serialize XML Document to string using DOM Level 3 Load/Save
 * 
 * @param doc XML Document
 * @param node the Node to serialize
 * @return String representation of the Document
 * @throws IOException
 */
public static String serializeToStringLS(Document doc, Node node) throws IOException {
	String encoding = doc.getInputEncoding();
       if(encoding == null) encoding = "UTF-8";
       
       return serializeToStringLS(doc, node, encoding);
}