Search in sources :

Example 36 with DocumentType

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

the class VersionedDTDRootElementController method createRootElement.

@Override
public void createRootElement() {
    super.createRootElement();
    if (!_checkDocType()) {
        IProject project = resource().adapt(IProject.class);
        String defaultVersion = LiferayDescriptorHelper.getDescriptorVersion(project);
        DocumentType existingDocType = _getDocument().getDoctype();
        if (existingDocType != null) {
            _getDocument().removeChild(existingDocType);
        }
        String publicId = MessageFormat.format(_publicIdTemplate, defaultVersion);
        String systemId = MessageFormat.format(_systemIdTemplate, defaultVersion.replaceAll("\\.", "_"));
        DOMImplementation domImpl = _getDocument().getImplementation();
        DocumentType newDocType = domImpl.createDocumentType(_xmlBindingPath, publicId, systemId);
        if (newDocType != null) {
            _getDocument().insertBefore(newDocType, _getDocument().getDocumentElement());
        }
    }
}
Also used : DocumentType(org.w3c.dom.DocumentType) DOMImplementation(org.w3c.dom.DOMImplementation) IProject(org.eclipse.core.resources.IProject)

Example 37 with DocumentType

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

the class BaseNodeActionManager method contributeEditGrammarInformationActions.

protected void contributeEditGrammarInformationActions(IMenuManager menu, Node node) {
    Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node : node.getOwnerDocument();
    DocumentType doctype = getDoctype(node);
    if (doctype == null) {
        contributeAction(menu, createAddDoctypeAction(document, -1));
    }
    if (node.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        contributeAction(menu, createEditDoctypeAction((DocumentType) node));
    }
    if ((doctype == null) && (getRootElement(document) != null)) {
        contributeAction(menu, createEditSchemaInfoAction(getRootElement(document)));
    }
}
Also used : DocumentType(org.w3c.dom.DocumentType) Document(org.w3c.dom.Document) CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)

Example 38 with DocumentType

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

the class AbstractXMLModelQueryCompletionProposalComputer method getAvailableRootChildren.

/**
 * returns a list of CMElementDeclarations
 *
 * @param document
 * @param childIndex
 * @return
 */
private List getAvailableRootChildren(Document document, int childIndex) {
    List list = null;
    // extract the valid 'root' node name from the DocumentType Node
    DocumentType docType = document.getDoctype();
    String rootName = null;
    if (docType != null) {
        rootName = docType.getNodeName();
    }
    if (rootName == null) {
        return new ArrayList(0);
    }
    for (Node child = document.getFirstChild(); child != null; child = child.getNextSibling()) {
        // is it required to be an Element?
        if ((child.getNodeType() == Node.ELEMENT_NODE) && child.getNodeName().equalsIgnoreCase(rootName)) {
            // count it as present
            if ((child instanceof IDOMNode) && ((((IDOMNode) child).getStartStructuredDocumentRegion() == null) || (((IDOMNode) child).getEndStructuredDocumentRegion() == null))) {
                continue;
            }
            if (Debug.displayInfo) {
                // $NON-NLS-1$
                System.out.println(rootName + " already present!");
            }
            setErrorMessage(NLS.bind(XMLUIMessages.The_document_element__, (new Object[] { rootName })));
            return new ArrayList(0);
        }
    }
    list = new ArrayList(1);
    ModelQuery modelQuery = ModelQueryUtil.getModelQuery(document);
    if (modelQuery != null) {
        CMDocument cmdoc = modelQuery.getCorrespondingCMDocument(document);
        if (cmdoc != null) {
            if (rootName != null) {
                CMElementDeclaration rootDecl = (CMElementDeclaration) cmdoc.getElements().getNamedItem(rootName);
                if (rootDecl != null) {
                    list.add(rootDecl);
                } else {
                    // supply the given document name anyway, even if it
                    // is an error
                    list.add(new SimpleCMElementDeclaration(rootName));
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
                    if (location.length() > 0) {
                        setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for_in, (new Object[] { rootName, location })));
                    } else {
                        setErrorMessage(NLS.bind(XMLUIMessages.No_definition_for, (new Object[] { rootName })));
                    }
                }
            }
        } else {
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
            if (location.length() > 0) {
                setErrorMessage(NLS.bind(XMLUIMessages.No_content_model_for, (new Object[] { location })));
            } else {
                setErrorMessage(XMLUIMessages.No_content_model_found_UI_);
            }
        }
    }
    return list;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) DocumentType(org.w3c.dom.DocumentType) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)

Example 39 with DocumentType

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

the class EditDoctypeAction method createDoctype.

protected DocumentType createDoctype(EditDoctypeDialog dialog, Document document) {
    DocumentType result = null;
    if (document instanceof DocumentImpl) {
        IDOMDocument documentImpl = (IDOMDocument) document;
        IDOMDocumentType doctypeImpl = (IDOMDocumentType) documentImpl.createDoctype(dialog.getName());
        doctypeImpl.setPublicId(dialog.getPublicId());
        doctypeImpl.setSystemId(dialog.getSystemId());
        result = doctypeImpl;
    }
    return result;
}
Also used : IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) IDOMDocumentType(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType) DocumentType(org.w3c.dom.DocumentType) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) DocumentImpl(org.eclipse.wst.xml.core.internal.document.DocumentImpl)

Example 40 with DocumentType

use of org.w3c.dom.DocumentType in project nokogiri by sparklemotion.

the class XmlDocument method getInternalSubset.

public IRubyObject getInternalSubset(ThreadContext context) {
    IRubyObject dtd = (IRubyObject) node.getUserData(DTD_INTERNAL_SUBSET);
    if (dtd == null) {
        Document document = getDocument();
        if (document.getUserData(XmlDocument.DTD_RAW_DOCUMENT) != null) {
            dtd = XmlDtd.newFromInternalSubset(context.runtime, document);
        } else if (document.getDoctype() != null) {
            DocumentType docType = document.getDoctype();
            IRubyObject name, publicId, systemId;
            name = publicId = systemId = context.nil;
            if (docType.getName() != null) {
                name = context.runtime.newString(docType.getName());
            }
            if (docType.getPublicId() != null) {
                publicId = context.runtime.newString(docType.getPublicId());
            }
            if (docType.getSystemId() != null) {
                systemId = context.runtime.newString(docType.getSystemId());
            }
            dtd = XmlDtd.newEmpty(context.runtime, document, name, publicId, systemId);
        } else {
            dtd = context.nil;
        }
        setInternalSubset(dtd);
    }
    return dtd;
}
Also used : DocumentType(org.w3c.dom.DocumentType) IRubyObject(org.jruby.runtime.builtin.IRubyObject) Document(org.w3c.dom.Document)

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