Exemplo n.º 1
0
 @Test
 public void testOutputDocTypeInternalSubset() {
   String dec = "<!DOCTYPE root [\ninternal]>";
   DocType dt = new DocType("root");
   dt.setInternalSubset("internal");
   checkOutput(dt, dec, dec, dec, dec, dec);
 }
Exemplo n.º 2
0
 @Test
 public void testDocTypeSimpleISS() {
   DocType content = new DocType("root");
   content.setInternalSubset("<!ENTITY name \"value\">");
   assertEquals("<!DOCTYPE root [\n<!ENTITY name \"value\">]>", outputString(fraw, content));
   assertEquals("<!DOCTYPE root [\n<!ENTITY name \"value\">]>", outputString(fcompact, content));
   assertEquals("<!DOCTYPE root [\n<!ENTITY name \"value\">]>", outputString(fpretty, content));
   assertEquals("<!DOCTYPE root [\n<!ENTITY name \"value\">]>", outputString(ftso, content));
   assertEquals("<!DOCTYPE root [\n<!ENTITY name \"value\">]>", outputString(ftfw, content));
 }
Exemplo n.º 3
0
 @Test
 public void testDocTypeSystemIDISS() {
   DocType content = new DocType("root", "sysid");
   content.setInternalSubset("internal");
   assertEquals("<!DOCTYPE root SYSTEM \"sysid\" [\ninternal]>", outputString(fraw, content));
   assertEquals("<!DOCTYPE root SYSTEM \"sysid\" [\ninternal]>", outputString(fcompact, content));
   assertEquals("<!DOCTYPE root SYSTEM \"sysid\" [\ninternal]>", outputString(fpretty, content));
   assertEquals("<!DOCTYPE root SYSTEM \"sysid\" [\ninternal]>", outputString(ftso, content));
   assertEquals("<!DOCTYPE root SYSTEM \"sysid\" [\ninternal]>", outputString(ftfw, content));
 }
 private void normalizeDTD(DocType dt) {
   if (dt == null) {
     return;
   }
   // do some tricks so that we can compare the results.
   // these may well break the actual syntax of DTD's but for testing
   // purposes it is OK.
   String internalss = dt.getInternalSubset().trim();
   // the spaceing in and around the internal subset is different between
   // our SAX parse, and the DOM parse.
   // make all whitespace a single space.
   internalss = internalss.replaceAll("\\s+", " ");
   // It seems the DOM parser internally quotes entities with single quote
   // but our sax parser uses double-quote.
   // simply replace all " with ' and be done with it.
   internalss = internalss.replaceAll("\"", "'");
   dt.setInternalSubset("\n" + internalss + "\n");
 }
Exemplo n.º 5
0
  /**
   * This method tells you the line of the XML file being parsed. For an in-memory document, it's
   * meaningless. The location is only valid for the current parsing lifecycle, but the document has
   * already been parsed. Therefore, it returns -1 for both line and column numbers.
   *
   * @param document JDOM <code>Document</code>.
   */
  private void documentLocator(Document document) {
    locator = new JDOMLocator();
    String publicID = null;
    String systemID = null;

    if (document != null) {
      DocType docType = document.getDocType();
      if (docType != null) {
        publicID = docType.getPublicID();
        systemID = docType.getSystemID();
      }
    }
    locator.setPublicId(publicID);
    locator.setSystemId(systemID);
    locator.setLineNumber(-1);
    locator.setColumnNumber(-1);

    contentHandler.setDocumentLocator(locator);
  }