use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.
the class ModelQueryImpl method getCMDocumentManager.
public CMDocumentManager getCMDocumentManager() {
CMDocumentManager result = null;
if (modelQueryAssociationProvider instanceof XMLAssociationProvider) {
XMLAssociationProvider xmlAssociationProvider = (XMLAssociationProvider) modelQueryAssociationProvider;
result = xmlAssociationProvider.getCMDocumentManager();
}
return result;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.
the class ModelQueryTester method testDTDLoadFromSystemID_1.
/**
* A short test to ensure that a DTD can be loaded from a system
* reference.
*
* Note: May require a functioning network connection for the references
* to be resolved properly.
*
* @throws IOException
*/
public void testDTDLoadFromSystemID_1() throws IOException {
if (testShippedDTDLookup) {
setUpXML();
URL installationPath = Platform.getBundle(JSPUITestsPlugin.ID).getEntry("/");
String diskLocation = null;
diskLocation = FileLocator.resolve(installationPath).toExternalForm();
assertTrue("failed to resolve plugin install path", diskLocation != null);
String content = "<?xml version=\"1.0\"?><!DOCTYPE html SYSTEM " + diskLocation + "TestFiles/DTDs/wapDTDs/WAP-2-0/wml20.dtd\"" + "><html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:wml=\"http://www.wapforum.org/2001/wml\"></html>";
fModel.getStructuredDocument().set(content);
CMDocumentManager documentManagaer = fModelQuery.getCMDocumentManager();
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, false);
documentManagaer.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, true);
Node domNode = (Node) fModel.getIndexedRegion(content.length() - 2);
CMNode node = fModelQuery.getCMNode(domNode);
assertTrue("wml20.dtd failed to load", node != null && node.getNodeName().equalsIgnoreCase("html"));
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.
the class XMLPropertySheetConfiguration method getInputSelection.
public ISelection getInputSelection(IWorkbenchPart selectingPart, ISelection selection) {
if (fSelectedNotifiers != null) {
for (int i = 0; i < fSelectedNotifiers.length; i++) {
fSelectedNotifiers[i].removeAdapter(fRefreshAdapter);
}
fSelectedNotifiers = null;
}
for (int i = 0; i < fSelectedCMDocumentManagers.length; i++) {
fSelectedCMDocumentManagers[i].removeListener(fCMDocumentManagerListener);
}
ISelection preferredSelection = selection;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSel = (IStructuredSelection) selection;
/*
* On Attr nodes, select the owner Element. On Text nodes, select
* the parent Element.
*/
Object[] selectedObjects = new Object[structuredSel.size()];
System.arraycopy(structuredSel.toArray(), 0, selectedObjects, 0, selectedObjects.length);
for (int i = 0; i < selectedObjects.length; i++) {
Object inode = selectedObjects[i];
if (inode instanceof Node) {
Node node = (Node) inode;
// replace Attribute Node with its owner
Node parentNode = node.getParentNode();
if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
Element ownerElement = ((Attr) node).getOwnerElement();
selectedObjects[i] = ownerElement;
} else // replace Text Node with its parent
if (((node.getNodeType() == Node.TEXT_NODE) || (node.getNodeType() == Node.CDATA_SECTION_NODE)) && (parentNode != null)) {
selectedObjects[i] = parentNode;
}
}
}
if (selectedObjects.length > 0) {
Set managers = new HashSet(1);
Set selectedNotifiers = new HashSet(1);
for (int i = 0; i < selectedObjects.length; i++) {
if (selectedObjects[i] instanceof Node) {
ModelQuery query = ModelQueryUtil.getModelQuery(((Node) selectedObjects[i]).getOwnerDocument());
if (query != null) {
CMDocumentManager mgr = query.getCMDocumentManager();
if (mgr != null) {
managers.add(mgr);
mgr.addListener(fCMDocumentManagerListener);
}
}
}
/*
* Add UI refresh adapters and remember notifiers for
* later removal
*/
if (selectedObjects[i] instanceof INodeNotifier) {
selectedNotifiers.add(selectedObjects[i]);
((INodeNotifier) selectedObjects[i]).addAdapter(fRefreshAdapter);
}
}
fSelectedCMDocumentManagers = (CMDocumentManager[]) managers.toArray(new CMDocumentManager[managers.size()]);
fSelectedNotifiers = (INodeNotifier[]) selectedNotifiers.toArray(new INodeNotifier[selectedNotifiers.size()]);
}
preferredSelection = new StructuredSelection(selectedObjects);
}
return preferredSelection;
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.
the class AdapterFactoryProviderForXML method addContentBasedFactories.
protected void addContentBasedFactories(IStructuredModel structuredModel) {
FactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry();
// $NON-NLS-1$
Assert.isNotNull(factoryRegistry, "Program Error: client caller must ensure model has factory registry");
INodeAdapterFactory factory = null;
factory = factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class);
if (factory == null) {
factory = new JFaceNodeAdapterFactory();
factoryRegistry.addFactory(factory);
}
//
if (structuredModel != null) {
ModelQuery modelQuery = ModelQueryUtil.getModelQuery(structuredModel);
if (modelQuery != null) {
CMDocumentManager documentManager = modelQuery.getCMDocumentManager();
if (documentManager != null) {
IPreferenceStore store = XMLUIPlugin.getDefault().getPreferenceStore();
boolean useInferredGrammar = (store != null) ? store.getBoolean(XMLUIPreferenceNames.USE_INFERRED_GRAMMAR) : true;
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_ASYNC_LOAD, true);
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_AUTO_LOAD, false);
documentManager.setPropertyEnabled(CMDocumentManager.PROPERTY_USE_CACHED_RESOLVED_URI, true);
DOMObserver domObserver = new DOMObserver(structuredModel);
domObserver.setGrammarInferenceEnabled(useInferredGrammar);
domObserver.init();
}
}
}
}
use of org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager in project webtools.sourceediting by eclipse.
the class ModelQueryAdapterFactoryForXML method createAdapter.
/**
* createAdapter method comment.
*/
protected INodeAdapter createAdapter(INodeNotifier target) {
if (org.eclipse.wst.sse.core.internal.util.Debug.displayInfo)
// $NON-NLS-1$
System.out.println("-----------------------ModelQueryAdapterFactoryForXML.createAdapter" + target);
if (modelQueryAdapterImpl == null) {
if (target instanceof IDOMNode) {
IDOMNode xmlNode = (IDOMNode) target;
IStructuredModel model = xmlNode.getModel();
stateNotifier = xmlNode.getModel();
stateNotifier.addModelStateListener(getInternalModelStateListener());
org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
if (Debug.displayInfo)
// $NON-NLS-1$
System.out.println("----------------ModelQueryAdapterFactoryForXML... baseLocation : " + resolver.getFileBaseLocation());
/**
* XMLCatalogIdResolver currently requires a filesystem
* location string. Customarily this will be what is in the
* deprecated SSE URIResolver and required by the Common URI
* Resolver.
*/
URIResolver idResolver = null;
if (resolver != null) {
idResolver = new XMLCatalogIdResolver(resolver.getFileBaseLocation(), resolver);
} else {
/*
* 203649 - this block may be necessary due to ordering of
* setting the resolver into the model
*/
String baseLocation = null;
String modelsBaseLocation = model.getBaseLocation();
if (modelsBaseLocation != null) {
File file = new Path(modelsBaseLocation).toFile();
if (file.exists()) {
baseLocation = file.getAbsolutePath();
} else {
IPath basePath = new Path(model.getBaseLocation());
IResource derivedResource = null;
if (basePath.segmentCount() > 1)
derivedResource = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
else
derivedResource = ResourcesPlugin.getWorkspace().getRoot().getProject(basePath.segment(0));
IPath derivedPath = derivedResource.getLocation();
if (derivedPath != null) {
baseLocation = derivedPath.toString();
} else {
URI uri = derivedResource.getLocationURI();
if (uri != null) {
baseLocation = uri.toString();
}
}
}
if (baseLocation == null) {
baseLocation = modelsBaseLocation;
}
}
idResolver = new XMLCatalogIdResolver(baseLocation, null);
}
CMDocumentCache cmDocumentCache = new CMDocumentCache();
ModelQuery modelQuery = new XMLModelQueryImpl(cmDocumentCache, idResolver);
// cs todo...
// for now we create a CMDocumentCache on a 'per editor' basis
// in the future we need to support a CMDocumentCache that is
// shared between editors
// nsd comment: may not be appropriate depending on
CMDocumentManager documentManager = modelQuery.getCMDocumentManager();
if (documentManager != null) {
configureDocumentManager(documentManager);
}
modelQueryAdapterImpl = new ModelQueryAdapterImpl(cmDocumentCache, modelQuery, idResolver);
}
}
return modelQueryAdapterImpl;
}
Aggregations