Example usage for org.dom4j DocumentType getInternalDeclarations

List of usage examples for org.dom4j DocumentType getInternalDeclarations

Introduction

In this page you can find the example usage for org.dom4j DocumentType getInternalDeclarations.

Prototype

List<Decl> getInternalDeclarations();

Source Link

Document

Returns a list of internal DTD declaration objects, defined in the org.dom4j.dtd package

Usage

From source file:com.cladonia.xml.ExchangerXMLWriter.java

License:Open Source License

protected void writeDocType(DocumentType docType) throws IOException {
    if (DEBUG)//from  w ww  .  java 2 s .c  o m
        System.out.println("ExchangerXMLWriter.writeDocType( " + docType + ")");

    if (docType != null) {
        List list = docType.getInternalDeclarations();

        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                Object internalDecl = list.get(i);

                if (internalDecl instanceof InternalEntityDecl) {
                    InternalEntityDecl decl = (InternalEntityDecl) internalDecl;
                    //                  System.out.println( "<!ENTITY "+decl.getName()+" \""+decl.getValue()+"\">");
                    String value = decl.getValue();
                    StringBuffer result = new StringBuffer("&");

                    int index = value.indexOf("&amp;");

                    if (index != -1 && value.length() > 5) {
                        if (index > 0) {
                            result.append(value.substring(0, index + 1));
                        }

                        result.append(value.substring(index + 5, value.length()));

                        decl.setValue(result.toString());
                    }
                } else if (internalDecl instanceof ExternalEntityDecl) {
                    ExternalEntityDecl decl = (ExternalEntityDecl) internalDecl;

                    //                  System.out.println( "<!ENTITY "+decl.getName()+" \""+decl.getPublicID()+"\" \""+decl.getSystemID()+"\">");

                    //                  System.out.println( internalDecl.getClass());
                    //                  System.out.println( internalDecl.toString());
                }
            }
        }

        docType.write(writer);

        writer.write(format.getLineSeparator());
        writer.write(format.getLineSeparator());
    }
}

From source file:com.cladonia.xml.XMLFormatter.java

License:Mozilla Public License

protected void writeDocType(DocumentType docType) throws IOException {
    if (DEBUG)/*w  ww.ja  v  a2  s  .c o  m*/
        System.out.println("XMLFormatter.writeDocType( " + docType + ")");

    if (docType != null) {
        List list = docType.getInternalDeclarations();

        if (list != null) {
            for (int i = 0; i < list.size(); i++) {
                Object internalDecl = list.get(i);

                if (internalDecl instanceof InternalEntityDecl) {
                    InternalEntityDecl decl = (InternalEntityDecl) internalDecl;
                    String value = decl.getValue();
                    StringBuffer result = new StringBuffer("&");

                    int index = value.indexOf("&amp;");

                    if (index != -1 && value.length() > 5) {
                        if (index > 0) {
                            result.append(value.substring(0, index + 1));
                        }

                        result.append(value.substring(index + 5, value.length()));

                        decl.setValue(result.toString());
                    }
                }
            }
        }

        docType.write(writer);

        writer.write(format.getLineSeparator());
        writer.write(format.getLineSeparator());
    }
}