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()));
}
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);
}
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;
}
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;
}
Aggregations