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());
}
}
}
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)));
}
}
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;
}
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;
}
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;
}
Aggregations