use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class AbstractStyleSheetAdapter method styleUpdate.
/**
* @param srcModel com.ibm.sed.css.model.interfaces.ICSSModel
*/
public void styleUpdate(ICSSModel srcModel) {
IDOMNode node = (IDOMNode) getElement();
if (node == null)
return;
IDOMModel model = node.getModel();
if (model == null)
return;
XMLModelNotifier notifier = model.getModelNotifier();
if (notifier == null)
return;
// before updating, all sub-models should be loaded!
DocumentStyle document = (DocumentStyle) model.getDocument();
StyleSheetList styles = document.getStyleSheets();
if (styles != null) {
int n = styles.getLength();
ImportedCollector trav = new ImportedCollector();
for (int i = 0; i < n; i++) {
org.w3c.dom.stylesheets.StyleSheet sheet = styles.item(i);
if (sheet instanceof ICSSNode)
trav.apply((ICSSNode) sheet);
}
}
// flash style changed events
if (styleChangedNodes != null) {
Object[] elements = styleChangedNodes.toArray();
for (int i = 0; elements != null && i < elements.length; i++) notifyStyleChanged((Element) elements[i]);
styleChangedNodes.clear();
}
// to notify GEF tree
if (document instanceof INodeNotifier) {
Collection adapters = ((INodeNotifier) document).getAdapters();
if (adapters == null)
return;
Iterator it = adapters.iterator();
if (it == null)
return;
while (it.hasNext()) {
INodeAdapter adapter = (INodeAdapter) it.next();
if (adapter instanceof ICSSStyleListener) {
((ICSSStyleListener) adapter).styleUpdate(srcModel);
}
}
}
notifier.propertyChanged(node);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class LinkElementAdapter method retrieveModel.
/**
*/
private ICSSModel retrieveModel() {
if (!isValidAttribute()) {
return null;
}
// null,attr check is done in isValidAttribute()
Element element = getElement();
// $NON-NLS-1$
String href = element.getAttribute("href");
IDOMModel baseModel = ((IDOMNode) element).getModel();
if (baseModel == null)
return null;
Object id = baseModel.getId();
if (!(id instanceof String))
return null;
// String base = (String)id;
// get ModelProvideAdapter
IModelProvideAdapter adapter = (IModelProvideAdapter) ((INodeNotifier) getElement()).getAdapterFor(ModelProvideAdapterClass);
URLModelProvider provider = new URLModelProvider();
try {
IStructuredModel newModel = provider.getModelForRead(baseModel, href);
if (newModel == null)
return null;
if (!(newModel instanceof ICSSModel)) {
newModel.releaseFromRead();
return null;
}
// notify adapter
if (adapter != null)
adapter.modelProvided(newModel);
return (ICSSModel) newModel;
} catch (UnsupportedEncodingException e) {
} catch (IOException e) {
}
return null;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testLeadingXMLComment.
public void testLeadingXMLComment() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "0<script> <!--12</script>3");
assertNotNull("missing test model", structuredModel);
// do translation
JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
IJsTranslation translation = translationAdapter.getJsTranslation(false);
String translated = translation.getJsText();
assertEquals("script with leading comment but no new line should be empty", " ", translated);
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleServerSide1InJSCheckProblems.
// public void testMangleOverlappingTagAndServerSideInJS() {
// // get model
// String fileName = getName() + ".html";
// IStructuredModel structuredModel = getSharedModel(fileName, "<script> var a = <%= 4 %>5;\nif(a < <custom:tag attr=\"<%=%>\"/>) {} ; </script>");
// assertNotNull("missing test model", structuredModel);
//
// // do translation
// JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
// JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
// IJsTranslation translation = translationAdapter.getJsTranslation(false);
// String translated = translation.getJsText();
// assertTrue("server-side script block included\n" + translated, translated.indexOf("<%") < 0);
// assertTrue("server-side script block included\n" + translated, translated.indexOf("%>") < 0);
// assertTrue("tag included\n" + translated, translated.indexOf("custom") < 0);
// assertTrue("tag included\n" + translated, translated.indexOf("/>") < 0);
// assertTrue("var dropped\n" + translated, translated.indexOf("var a = ") > -1);
// assertTrue("if dropped\n" + translated, translated.indexOf("5;\nif(a < ") > -1);
// assertTrue("block dropped\n" + translated, translated.indexOf(") {} ; ") > -1);
//
// assertTrue("problems found in translation ", translation.getProblems().isEmpty());
//
// // release model
// structuredModel.releaseFromRead();
// }
public void testMangleServerSide1InJSCheckProblems() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <%= javaObject.getText() %>; </script>");
assertNotNull("missing test model", structuredModel);
// do translation
JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
IJsTranslation translation = translationAdapter.getJsTranslation(false);
String translated = translation.getJsText();
assertTrue("translation empty", translated.length() > 5);
assertTrue("server-side script block included", translated.indexOf("<%") < 0);
assertTrue("server-side script block included", translated.indexOf("%>") < 0);
assertTrue("var dropped", translated.indexOf("var text = ") > -1);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestHtmlTranslation method testMangleMultipleServerSide2InJSCheckProblems.
public void testMangleMultipleServerSide2InJSCheckProblems() {
// get model
String fileName = getName() + ".html";
IStructuredModel structuredModel = getSharedModel(fileName, "<script> var text = <? serverObject.getText() ?>; <? serverObject.getText() ?></script>");
assertNotNull("missing test model", structuredModel);
// do translation
JsTranslationAdapterFactory.setupAdapterFactory(structuredModel);
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) ((IDOMModel) structuredModel).getDocument().getAdapterFor(IJsTranslation.class);
IJsTranslation translation = translationAdapter.getJsTranslation(false);
String translated = translation.getJsText();
assertTrue("translation empty", translated.length() > 5);
assertTrue("server-side script block included", translated.indexOf("<?") < 0);
assertTrue("server-side script block included", translated.indexOf("?>") < 0);
assertTrue("var dropped", translated.indexOf("var text = ") > -1);
assertTrue("problems found in translation ", translation.getProblems().isEmpty());
// release model
structuredModel.releaseFromRead();
}
Aggregations