Search in sources :

Example 91 with DocumentType

use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.

the class DocumentImpl method getDocumentTypeId.

public String getDocumentTypeId() {
    DocumentType docType = getDocumentType();
    if (docType == null)
        return null;
    String id = docType.getPublicId();
    if (id == null)
        id = docType.getSystemId();
    return id;
}
Also used : DocumentType(org.w3c.dom.DocumentType)

Example 92 with DocumentType

use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.

the class DocumentImpl method getDocumentElement.

/**
 * getDocumentElement
 *
 * @return org.w3c.dom.Element From DOM 2 Spec: documentElement of type
 *         Element [p.62] , readonly This is a convenience [p.119]
 *         attribute that allows direct access to the child node that is
 *         the root element of the document. For HTML documents, this is
 *         the element with the tagName "HTML". Note: we differ from this
 *         definition a little in that we don't necessarily take the first
 *         child but also look to match the name. In a well formed
 *         document, of course, the result is the same, but not
 *         necessarily the same in an ill-formed document.
 */
public Element getDocumentElement() {
    String name = null;
    DocumentType docType = getDocumentType();
    if (docType != null) {
        name = docType.getName();
    }
    Element[] first = new Element[1];
    Element docElement = findDocumentElement(name, this, first, noMaxSearch);
    if (docElement == null) {
        docElement = first[0];
    }
    return docElement;
}
Also used : Element(org.w3c.dom.Element) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) DocumentType(org.w3c.dom.DocumentType)

Example 93 with DocumentType

use of org.w3c.dom.DocumentType in project liferay-ide by liferay.

the class HookUtil method getDTDVersion.

/**
 * A small utility method used to compute the DTD version
 *
 * @param document
 *            - the document that is loaded by the editor
 */
public static String getDTDVersion(Document document) {
    String dtdVersion = null;
    DocumentType docType = document.getDoctype();
    if (docType != null) {
        String publicId = docType.getPublicId();
        String systemId = docType.getSystemId();
        if ((publicId != null) && (systemId != null)) {
            if (publicId.contains("6.0.0") || systemId.contains("6.0.0")) {
                dtdVersion = "6.0.0";
            } else if (publicId.contains("6.1.0") || systemId.contains("6.1.0")) {
                dtdVersion = "6.1.0";
            }
        }
    }
    return dtdVersion;
}
Also used : DocumentType(org.w3c.dom.DocumentType)

Example 94 with DocumentType

use of org.w3c.dom.DocumentType in project liferay-ide by liferay.

the class VersionedDTDRootElementController method _checkDocType.

private boolean _checkDocType() {
    try {
        Document document = _getDocument();
        if (document == null) {
            return false;
        }
        DocumentType docType = document.getDoctype();
        if (docType == null) {
            return false;
        }
        Matcher publicIdMatcher = _publicIdPattern.matcher(docType.getPublicId());
        if (!publicIdMatcher.matches()) {
            return false;
        }
        String version = publicIdMatcher.group(1);
        if (version == null) {
            return false;
        }
        Matcher systemIdMatcher = _systemIdPattern.matcher(docType.getSystemId());
        if (!systemIdMatcher.matches()) {
            return false;
        }
        String systemIdVersion = systemIdMatcher.group(1);
        if (systemIdVersion == null) {
            return false;
        }
        systemIdVersion = systemIdVersion.replaceAll(StringPool.UNDERSCORE, StringPool.EMPTY);
        version = version.replaceAll("\\.", StringPool.EMPTY);
        if (systemIdVersion.equals(version)) {
            return true;
        }
    } catch (Exception e) {
    }
    return false;
}
Also used : Matcher(java.util.regex.Matcher) DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document)

Example 95 with DocumentType

use of org.w3c.dom.DocumentType in project liferay-ide by liferay.

the class DescriptorsPage method isNeedUpgrade.

@Override
protected boolean isNeedUpgrade(IFile srcFile) {
    IDOMModel domModel = null;
    try {
        domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(srcFile);
        domModel.aboutToChangeModel();
        IDOMDocument document = domModel.getDocument();
        DocumentType docType = document.getDoctype();
        if (docType != null) {
            final String publicId = docType.getPublicId();
            String oldPublicIdVersion = _getOldVersion(publicId, _publicidRegrex);
            final String systemId = docType.getSystemId();
            String oldSystemIdVersion = _getOldVersion(systemId, _systemidRegrex);
            if (((publicId != null) && !oldPublicIdVersion.equals("7.0.0")) || ((systemId != null) && !oldSystemIdVersion.equals("7_0_0"))) {
                return true;
            }
        }
    } catch (Exception e) {
        ProjectUI.logError(e);
    } finally {
        domModel.releaseFromRead();
    }
    return false;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DocumentType(org.w3c.dom.DocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

DocumentType (org.w3c.dom.DocumentType)107 Document (org.w3c.dom.Document)68 DOMImplementation (org.w3c.dom.DOMImplementation)34 Node (org.w3c.dom.Node)21 DOMException (org.w3c.dom.DOMException)19 Element (org.w3c.dom.Element)16 NamedNodeMap (org.w3c.dom.NamedNodeMap)14 NodeList (org.w3c.dom.NodeList)12 ArrayList (java.util.ArrayList)10 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)8 Entity (org.w3c.dom.Entity)8 IOException (java.io.IOException)7 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)5 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)4 Transformer (javax.xml.transform.Transformer)4 TransformerFactory (javax.xml.transform.TransformerFactory)4 DOMSource (javax.xml.transform.dom.DOMSource)4 StreamResult (javax.xml.transform.stream.StreamResult)4 Attr (org.w3c.dom.Attr)4