use of org.eclipse.wst.xml.core.internal.document.DOMModelImpl in project webtools.sourceediting by eclipse.
the class StructuredDocumentToDOMUnitTests method testNodeDeletion.
/**
* Unit test -- tests basic parsing results of inserting a test string
* into an initial string.
*/
void testNodeDeletion() {
// String initialString =
// "<par><x>\ntextx\n</x>\n<y>\ntexty\n</y></par>";
// String initialString = "<par><x>textx</x><y>texty</y></par>";
// test cases for two text nodes left together (remove <b/>):
// first case works, second doesn't
// String initialString = "<a>a<b /></a>"; // -> <a>a</a>
// String initialString = "<a>a<b />b</a>"; // -> <a>ab</a>
// String initialString = getTestString1();
String initialString = getTestString2();
// print out what we always can
System.out.println();
System.out.println("----------------");
System.out.println("Test Node Deletion");
String outString = StringUtils.escape(initialString);
System.out.println("Initial String: " + outString);
// always start with fresh model
IStructuredDocument f = null;
IModelManager mm = StructuredModelManager.getModelManager();
try {
f = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
} catch (IOException e) {
// do nothing, since dummy
}
//
// we'll listen to structuredDocument events to print out diagnostics
f.addDocumentChangedListener(this);
//
IDOMModel tree = new DOMModelImpl();
f.addDocumentChangingListener((IStructuredDocumentListener) tree);
// set text to structuredDocument (which updates tree)
f.setText(null, initialString);
// dump initial structuredDocument
Debug.dump(f);
// dump initial dom
DebugDocument.dump(tree.getDocument());
//
//
// makeChange1(tree);
makeChange2(f);
// display resulting text
System.out.println("resultString (from structuredDocument): ");
System.out.println(StringUtils.escape(f.getText()));
//
//
// dump post change structuredDocument
Debug.dump(f);
// dump post change DOM
DebugDocument.dump(tree.getDocument());
//
}
use of org.eclipse.wst.xml.core.internal.document.DOMModelImpl in project webtools.sourceediting by eclipse.
the class UnitTests method setUpXML.
/**
* Set up an XML model
*/
protected void setUpXML() {
IModelManager mm = StructuredModelManager.getModelManager();
try {
fModel = mm.createStructuredDocumentFor("dummy.xml", (InputStream) null, null);
} catch (IOException e) {
// do nothing, since dummy
}
fModel.addDocumentChangedListener(proxy);
tree = new DOMModelImpl();
if (tree != null) {
fModel.addDocumentChangingListener((IStructuredDocumentListener) tree);
tree.setStructuredDocument(fModel);
}
}
use of org.eclipse.wst.xml.core.internal.document.DOMModelImpl in project webtools.sourceediting by eclipse.
the class UnitTests method setUpJSP.
/**
* Set up a JSP model
*/
protected void setUpJSP() {
IModelManager mm = StructuredModelManager.getModelManager();
try {
fModel = mm.createStructuredDocumentFor("dummy.jsp", (InputStream) null, null);
} catch (IOException e) {
// do nothing, since dummy
}
fModel = StructuredDocumentFactory.getNewStructuredDocumentInstance(new JSPSourceParser());
fModel.addDocumentChangedListener(proxy);
tree = new DOMModelImpl();
if (tree != null) {
fModel.addDocumentChangingListener((IStructuredDocumentListener) tree);
tree.setStructuredDocument(fModel);
}
}
use of org.eclipse.wst.xml.core.internal.document.DOMModelImpl in project webtools.sourceediting by eclipse.
the class CleanupProcessorXML method cleanupModel.
public void cleanupModel(IStructuredModel structuredModel) {
Preferences preferences = getModelPreferences();
if (preferences != null && preferences.getBoolean(XMLCorePreferenceNames.FIX_XML_DECLARATION)) {
IDOMDocument document = ((DOMModelImpl) structuredModel).getDocument();
if (!fixExistingXmlDecl(document)) {
String encoding = preferences.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
Node xml = document.createProcessingInstruction("xml", "version=\"1.0\" " + "encoding=\"" + encoding + "\"");
document.insertBefore(xml, document.getFirstChild());
}
}
super.cleanupModel(structuredModel);
}
use of org.eclipse.wst.xml.core.internal.document.DOMModelImpl in project webtools.sourceediting by eclipse.
the class DOMImplementationTests method testCreateDocumentWellformedQualifiedNames.
public void testCreateDocumentWellformedQualifiedNames() {
final DOMModelImpl model = (DOMModelImpl) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForXML.ContentTypeID_XML);
final String[] names = { "bar", "foo:bar" };
for (int i = 0; i < names.length; i++) {
try {
model.createDocument("http://eclipse.org", names[i], null);
} catch (DOMException e) {
fail("[" + names[i] + "] flagged as an invalid qualified name");
}
}
}
Aggregations