use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getDoctypeInfo.
public static String[] getDoctypeInfo(Document document) {
String[] result = null;
DocumentType doctype = document.getDoctype();
// so that the implict DTD (if any) can be used
if (doctype != null && (doctype.getPublicId() != null || doctype.getSystemId() != null)) {
result = new String[2];
result[0] = doctype.getPublicId();
result[1] = doctype.getSystemId();
} else if (getImplictDoctype(document) != null) {
result = getImplictDoctype(document);
}
return result;
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class XMLAssociationProvider method getCMDocumentReferences.
/**
* This method returns a list of CMDocumentReferences associated with a particular node or subtree
*/
public List getCMDocumentReferences(Node node, boolean deep) {
List result = new ArrayList();
Document document = (node.getNodeType() == Node.DOCUMENT_NODE) ? (Document) node : node.getOwnerDocument();
DocumentType doctype = document.getDoctype();
// so that the implict DTD (if any) can be used
if (doctype != null && (doctype.getPublicId() != null || doctype.getSystemId() != null)) {
String uri = resolveGrammarURI(document, doctype.getPublicId(), doctype.getSystemId());
result.add(new CMDocumentReferenceImpl(doctype.getPublicId(), uri));
} else if (getImplictDoctype(document) != null) {
String[] implicitDoctype = getImplictDoctype(document);
String uri = resolveGrammarURI(document, implicitDoctype[0], implicitDoctype[1]);
result.add(new CMDocumentReferenceImpl(implicitDoctype[0], uri));
} else {
NamespaceTable namespaceTable = new NamespaceTable(document);
if (node.getNodeType() == Node.ELEMENT_NODE) {
namespaceTable.addElement((Element) node);
}
if (deep) {
addChildElementsToNamespaceTable(node, namespaceTable);
}
List list = namespaceTable.getNamespaceInfoList();
for (Iterator i = list.iterator(); i.hasNext(); ) {
NamespaceInfo info = (NamespaceInfo) i.next();
String uri = resolveGrammarURI(document, info.uri, info.locationHint);
result.add(new CMDocumentReferenceImpl(info.uri, uri));
}
}
return result;
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class ModelQueryActionHelper method getInsertActions.
public void getInsertActions(Document parent, CMDocument cmDocument, int index, int includeOptions, int validityChecking, List actionList) {
// get the root element and doctype index (if any)
//
int doctypeIndex = -1;
DocumentType doctype = null;
Element rootElement = null;
NodeList nodeList = parent.getChildNodes();
int nodeListLength = nodeList.getLength();
for (int i = 0; i < nodeListLength; i++) {
Node childNode = nodeList.item(i);
if (childNode.getNodeType() == Node.ELEMENT_NODE) {
rootElement = (Element) childNode;
break;
} else if (childNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
doctype = (DocumentType) childNode;
doctypeIndex = i;
}
}
// make sure that root elements are only added after the doctype (if any)
if (rootElement == null && index > doctypeIndex) {
CMNamedNodeMap map = cmDocument.getElements();
int mapLength = map.getLength();
for (int i = 0; i < mapLength; i++) {
CMNode cmNode = map.item(i);
boolean canAdd = true;
if (validityChecking == ModelQuery.VALIDITY_STRICT) {
canAdd = doctype == null || doctype.getName().equals(cmNode.getNodeName());
}
if (canAdd) {
Action action = new Action(ModelQueryAction.INSERT, parent, cmNode, index, index);
actionList.add(action);
}
}
}
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class DOMContentBuilderImpl method createDefaultRootContent.
public void createDefaultRootContent(CMDocument cmDocument, CMElementDeclaration rootCMElementDeclaration) throws Exception {
String grammarFileName = cmDocument.getNodeName();
if (!supressCreationOfDoctypeAndXMLDeclaration) {
// TODO cs... investigate to see if this code path is ever used,
// doesn't seem to be
// for now I'm setting the encoding to UTF-8 just incase this code
// path is used somewhere
//
// $NON-NLS-1$
String piValue = "version=\"1.0\"";
// $NON-NLS-1$
String encoding = "UTF-8";
// $NON-NLS-1$ //$NON-NLS-2$
piValue += " encoding=\"" + encoding + "\"";
// $NON-NLS-1$
ProcessingInstruction pi = document.createProcessingInstruction("xml", piValue);
document.appendChild(pi);
//
if (// $NON-NLS-1$
grammarFileName != null && grammarFileName.endsWith("dtd")) {
DOMImplementation domImpl = document.getImplementation();
DocumentType documentType = domImpl.createDocumentType(rootCMElementDeclaration.getElementName(), grammarFileName, grammarFileName);
document.appendChild(documentType);
}
}
//
if (// $NON-NLS-1$
grammarFileName != null && grammarFileName.endsWith("xsd") && namespaceInfoList != null) {
DOMNamespaceInfoManager manager = new DOMNamespaceInfoManager();
String name = rootCMElementDeclaration.getNodeName();
if (namespaceInfoList.size() > 0) {
NamespaceInfo info = (NamespaceInfo) namespaceInfoList.get(0);
if (info.prefix != null && info.prefix.length() > 0) {
// $NON-NLS-1$
name = info.prefix + ":" + name;
}
}
rootElement = createElement(rootCMElementDeclaration, name, document);
manager.addNamespaceInfo(rootElement, namespaceInfoList, true);
}
createDefaultContent(document, rootCMElementDeclaration);
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class HTMLTagsCompletionProposalComputer method isXHTMLNode.
/**
* Determine if this Document is an XHTML Document. Operates solely off of
* the Document Type declaration
*/
private static boolean isXHTMLNode(Node node) {
if (node == null) {
return false;
}
Document doc = null;
if (node.getNodeType() != Node.DOCUMENT_NODE)
doc = node.getOwnerDocument();
else
doc = ((Document) node);
if (doc instanceof IDOMDocument) {
return ((IDOMDocument) doc).isXMLType();
}
if (doc instanceof INodeNotifier) {
ModelQueryAdapter adapter = (ModelQueryAdapter) ((INodeNotifier) doc).getAdapterFor(ModelQueryAdapter.class);
CMDocument cmdoc = null;
if (adapter != null && adapter.getModelQuery() != null)
cmdoc = adapter.getModelQuery().getCorrespondingCMDocument(doc);
if (cmdoc != null) {
// model
if (cmdoc instanceof HTMLCMDocument)
return false;
if (cmdoc.supports(HTMLCMProperties.IS_XHTML))
return Boolean.TRUE.equals(cmdoc.getProperty(HTMLCMProperties.IS_XHTML));
}
}
// this should never be reached
DocumentType docType = doc.getDoctype();
// $NON-NLS-1$
return docType != null && docType.getPublicId() != null && docType.getPublicId().indexOf("-//W3C//DTD XHTML ") == 0;
}
Aggregations