Search in sources :

Example 1 with XMLCatalogIdResolver

use of org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver in project webtools.sourceediting by eclipse.

the class ModelQueryAdapterFactoryForJSP method updateResolver.

protected void updateResolver(IStructuredModel model) {
    String baseLocation = model.getBaseLocation();
    IFile baseFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(model.getBaseLocation()));
    if (baseFile != null) {
        if (baseFile.getLocation() != null) {
            baseLocation = baseFile.getLocation().toString();
        }
        if (baseLocation == null && baseFile.getLocationURI() != null) {
            baseLocation = baseFile.getLocationURI().toString();
        }
        if (baseLocation == null) {
            baseLocation = baseFile.getFullPath().toString();
        }
    } else {
        baseLocation = model.getBaseLocation();
    }
    modelQueryAdapterImpl.setIdResolver(new XMLCatalogIdResolver(baseLocation, model.getResolver()));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) XMLCatalogIdResolver(org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver)

Example 2 with XMLCatalogIdResolver

use of org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver in project webtools.sourceediting by eclipse.

the class TestCatalogRetrivalAndModelCreation method testXHTML11_xmlresolver.

/**
 * We expect the XMLCatalogResolver and XMLCatalogIdResolver
 * to resolve to the same URI given a public id in our catalog.
 *
 * @throws MalformedURLException
 * @throws IOException
 */
public void testXHTML11_xmlresolver() throws MalformedURLException, IOException {
    String EXPECTED_PUBLICID = "-//W3C//DTD XHTML 1.1//EN";
    // bug 117424, here ewe make up a base location to satisfy the resolver API
    // that expects a non-null base location
    String baseLocation = "http://www.example.org/testXHTML11.xml";
    XMLCatalogIdResolver resolver = new XMLCatalogIdResolver(baseLocation, null);
    String resolvedXML_Id = resolver.resolve(baseLocation, EXPECTED_PUBLICID, null);
    ICatalog xmlCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    String resolvedXL_Cat = xmlCatalog.resolvePublic(EXPECTED_PUBLICID, null);
    assertEquals(resolvedXL_Cat, resolvedXML_Id);
}
Also used : XMLCatalogIdResolver(org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 3 with XMLCatalogIdResolver

use of org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver in project webtools.sourceediting by eclipse.

the class ModelQueryAdapterFactoryForJSP method createAdapter.

/**
 * createAdapter method comment.
 */
protected INodeAdapter createAdapter(INodeNotifier target) {
    if (Debug.displayInfo)
        // $NON-NLS-1$
        System.out.println("-----------------------ModelQueryAdapterFactoryForJSP.createAdapter" + target);
    if (modelQueryAdapterImpl == null) {
        if (target instanceof IDOMNode) {
            IDOMNode xmlNode = (IDOMNode) target;
            IStructuredModel model = stateNotifier = xmlNode.getModel();
            if (model.getBaseLocation() != null) {
                stateNotifier.addModelStateListener(this);
            }
            org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
            if (Debug.displayInfo)
                // $NON-NLS-1$
                System.out.println("----------------ModelQueryAdapterFactoryForJSP... 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);
            }
            ModelQuery modelQuery = createModelQuery(model, idResolver);
            modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
            modelQueryAdapterImpl = new JSPModelQueryAdapterImpl(new CMDocumentCache(), modelQuery, idResolver);
        }
    }
    return modelQueryAdapterImpl;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) XMLCatalogIdResolver(org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver) IPath(org.eclipse.core.runtime.IPath) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) 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)

Example 4 with XMLCatalogIdResolver

use of org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver in project webtools.sourceediting by eclipse.

the class ModelQueryAdapterFactoryForHTML method createAdapter.

/**
 * createAdapter method comment.
 *
 * XXX: we must make this method more independent of 'location' (at least
 * provide some fall-back method).
 */
protected INodeAdapter createAdapter(INodeNotifier target) {
    if (Debug.displayInfo) {
        // $NON-NLS-1$
        Logger.log(Logger.INFO_DEBUG, "-----------------------ModelQueryAdapterFactoryForHTML.createAdapter" + target);
    }
    if (modelQueryAdapter == null) {
        if (target instanceof IDOMNode) {
            IDOMNode xmlNode = (IDOMNode) target;
            modelStateNotifier = xmlNode.getModel();
            modelStateNotifier.addModelStateListener(getInternalModelStateListener());
            IStructuredModel model = xmlNode.getModel();
            org.eclipse.wst.sse.core.internal.util.URIResolver resolver = model.getResolver();
            if (Debug.displayInfo)
                // $NON-NLS-1$
                System.out.println("----------------ModelQueryAdapterFactoryForHTML... 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 documentCache = new CMDocumentCache();
            ModelQuery modelQuery = new HTMLModelQueryImpl(documentCache, idResolver);
            modelQuery.setEditMode(ModelQuery.EDIT_MODE_UNCONSTRAINED);
            modelQueryAdapter = new ModelQueryAdapterImpl(documentCache, modelQuery, idResolver);
        }
    }
    return modelQueryAdapter;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) XMLCatalogIdResolver(org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver) IPath(org.eclipse.core.runtime.IPath) 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

XMLCatalogIdResolver (org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver)4 IFile (org.eclipse.core.resources.IFile)3 IPath (org.eclipse.core.runtime.IPath)3 Path (org.eclipse.core.runtime.Path)3 File (java.io.File)2 URI (java.net.URI)2 IResource (org.eclipse.core.resources.IResource)2 URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)2 CMDocumentCache (org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)1 ModelQueryAdapterImpl (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapterImpl)1