Search in sources :

Example 1 with CMDocumentManager

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;
}
Also used : CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager)

Example 2 with CMDocumentManager

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"));
    }
}
Also used : CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) Node(org.w3c.dom.Node) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) CMNode(org.eclipse.wst.xml.core.internal.contentmodel.CMNode) URL(java.net.URL)

Example 3 with CMDocumentManager

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Attr(org.w3c.dom.Attr) ISelection(org.eclipse.jface.viewers.ISelection) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier) HashSet(java.util.HashSet)

Example 4 with CMDocumentManager

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();
            }
        }
    }
}
Also used : CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) FactoryRegistry(org.eclipse.wst.sse.core.internal.model.FactoryRegistry) DOMObserver(org.eclipse.wst.xml.ui.internal.DOMObserver) JFaceNodeAdapterFactory(org.eclipse.wst.xml.ui.internal.contentoutline.JFaceNodeAdapterFactory) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IJFaceNodeAdapter(org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 5 with CMDocumentManager

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) CMDocumentManager(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) ModelQueryAdapterImpl(org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapterImpl) URI(java.net.URI) CMDocumentCache(org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ModelQuery(org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource)

Aggregations

CMDocumentManager (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.CMDocumentManager)8 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)5 Node (org.w3c.dom.Node)3 URL (java.net.URL)2 IFile (org.eclipse.core.resources.IFile)2 Path (org.eclipse.core.runtime.Path)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 FactoryRegistry (org.eclipse.wst.sse.core.internal.model.FactoryRegistry)2 INodeAdapterFactory (org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IJFaceNodeAdapter (org.eclipse.wst.sse.ui.internal.contentoutline.IJFaceNodeAdapter)2 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 DOMObserver (org.eclipse.wst.xml.ui.internal.DOMObserver)2 File (java.io.File)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1