use of org.w3c.dom.DocumentType in project webservices-axiom by apache.
the class TestWithParser1 method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().parse(TestWithParser1.class.getResource("test1.xml").toString());
DocumentType doctype = document.getDoctype();
assertEquals("root", doctype.getName());
assertNull(doctype.getPublicId());
assertNull(doctype.getSystemId());
assertEquals("<!ELEMENT root (#PCDATA)>", doctype.getInternalSubset().trim());
}
use of org.w3c.dom.DocumentType in project webservices-axiom by apache.
the class TestWithParser2 method runTest.
protected void runTest() throws Throwable {
Document document = dbf.newDocumentBuilder().parse(TestWithParser2.class.getResource("test2.xml").toString());
DocumentType doctype = document.getDoctype();
assertEquals("root", doctype.getName());
assertEquals("dummy", doctype.getPublicId());
assertEquals("test.dtd", doctype.getSystemId());
assertNull(doctype.getInternalSubset());
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class AbstractContentAssistProcessor method getAvailableRootChildren.
// returns a list of CMElementDeclarations
protected 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) && stringsEqual(child.getNodeName(), 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));
if (Debug.displayInfo || Debug.displayWarnings) {
// $NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
System.out.println("No definition found for " + rootName + " in " + docType.getPublicId() + "/" + docType.getSystemId());
}
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
// $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
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 {
if (Debug.displayInfo || Debug.displayWarnings) {
// $NON-NLS-1$
System.out.println("No content model found.");
}
// $NON-NLS-1$
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String location = "" + (docType.getPublicId() != null ? docType.getPublicId() + "/" : "") + (docType.getSystemId() != null ? docType.getSystemId() : "");
// $NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$
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 updateDoctype.
protected void updateDoctype(EditDoctypeDialog dialog, DocumentType doctype) {
if (doctype instanceof IDOMDocumentType) {
IDOMDocumentType doctypeImpl = (IDOMDocumentType) doctype;
if (doctypeImpl.getName().equals(dialog.getName())) {
doctypeImpl.setPublicId(dialog.getPublicId());
doctypeImpl.setSystemId(dialog.getSystemId());
} else {
// we need to create a new one and remove the old
//
Document document = doctype.getOwnerDocument();
DocumentType newDoctype = createDoctype(dialog, document);
document.insertBefore(newDoctype, doctype);
document.removeChild(doctype);
// manager.reformat(newDoctype, false);
}
}
}
use of org.w3c.dom.DocumentType in project webtools.sourceediting by eclipse.
the class EditDoctypeAction method run.
public void run() {
Shell shell = getDisplay().getActiveShell();
if (validateEdit(model, shell)) {
model.beginRecording(this, getUndoDescription());
// Shell shell =
// XMLCommonUIPlugin.getInstance().getWorkbench().getActiveWorkbenchWindow().getShell();
EditDoctypeDialog dialog = showEditDoctypeDialog(shell);
if (dialog.getReturnCode() == Window.OK) {
if (doctype != null) {
updateDoctype(dialog, doctype);
} else if (document != null) {
DocumentType doctype = createDoctype(dialog, document);
if (doctype != null) {
insertDoctype(doctype, document);
}
}
}
model.endRecording(this);
}
}
Aggregations