use of org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver in project webtools.sourceediting by eclipse.
the class DTDParser method resolveEntity.
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
InputSource result = null;
URIResolver idResolver = URIResolverPlugin.createResolver();
String logicalURI = idResolver.resolve(currentDTD.getName(), publicId, systemId);
// bug 113537, ensure physical resolution gets done here
// right before we attempt to open a stream
String physicalURI = idResolver.resolvePhysicalLocation(currentDTD.getName(), publicId, logicalURI);
result = new InputSource(logicalURI);
if (// $NON-NLS-1$
!(physicalURI == null || physicalURI.equals("") || URIHelper.hasProtocol(physicalURI))) {
// $NON-NLS-1$
physicalURI = "file:///" + physicalURI;
}
result.setByteStream(new LazyURLInputStream(physicalURI));
return result;
}
use of org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver in project webtools.sourceediting by eclipse.
the class DTDModelBuilder method updateSystemID.
/**
* The SystemID attribute is set to whatever the user enters e.g.
* com/ibm/b2b/xmimodels/xxx.dtd.xmi
*
* In the unparse() method, parse out the DTD file name from the classpath
* name. e.g. returns xxx.dtd
*/
private void updateSystemID(DTDExternalEntity extEntity, EntityDecl entityDecl) {
String systemId = entityDecl.getSystemId();
String publicId = entityDecl.getPublicId();
if (systemId != null) {
URIResolver idResolver = URIResolverPlugin.createResolver();
String uri = idResolver.resolve(dtd.getName(), publicId, systemId);
ExternalDTDModel ed = dtdUtil.getExternalDTDModel(resources, uri);
if (ed != null) {
DTDFile referenceDtdFile = ed.getExternalDTDFile();
extEntity.setEntityReferencedFromAnotherFile(referenceDtdFile);
extEntity.setSystemID(systemId);
} else {
if (entityDecl.getErrorMessage() == null) {
ErrorMessage dtdError = new ErrorMessage();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
dtdError.setErrorMessage(DTDCoreMessages._ERROR_INCL_FILE_LOAD_FAILURE + " '" + systemId + "'");
addErrorMessage(dtdError, extEntity.getDTDEntity());
}
if (systemId != null) {
extEntity.setSystemID(systemId);
} else {
// $NON-NLS-1$
extEntity.setSystemID("");
}
}
} else // end of if ()
{
// set the system id to be ""
// $NON-NLS-1$
extEntity.setSystemID("");
}
}
use of org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver in project webtools.sourceediting by eclipse.
the class XMLSearchParticipant method isLinked.
private boolean isLinked(SearchDocumentSet set, String source, String target, HashMap visited) {
if (source.equals(target))
return true;
// $NON-NLS-1$
String fileProtocol = "file:///";
// Fix for bug 204174 - Begin
if (// $NON-NLS-1$
target.charAt(fileProtocol.length()) == '/') {
target = fileProtocol + target.substring(fileProtocol.length() + 1);
}
if (source.startsWith(fileProtocol)) {
SearchDocument document = set._tempGetSearchDocumetn(source.substring(fileProtocol.length()));
if (document != null) {
URIResolver uriResolver = URIResolverPlugin.createResolver();
Entry[] entries = document.getEntries(IXMLSearchConstants.REF, null, 0);
String[] resolveEntry = new String[entries.length];
for (int j = 0; j < entries.length; j++) {
Entry entry = entries[j];
if (entry instanceof FileReferenceEntry) {
FileReferenceEntry fileReferenceEntry = (FileReferenceEntry) entry;
//
if (fileReferenceEntry.getRelativeFilePath() != null) {
String resolvedURI = uriResolver.resolve(source, null, fileReferenceEntry.getRelativeFilePath());
resolveEntry[j] = resolvedURI;
if (resolvedURI.equals(target)) {
return true;
}
}
}
}
// we keep track of the nodes we've already visited to avoid cycles
if (visited.get(source) == null) {
visited.put(source, Boolean.TRUE);
for (int j = 0; j < entries.length; j++) {
String resolvedURI = resolveEntry[j];
if (resolvedURI != null && isLinked(set, resolveEntry[j], target, visited))
return true;
}
}
}
}
return false;
}
use of org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver in project webtools.sourceediting by eclipse.
the class EditNamespaceInfoDialog method performBrowse.
protected void performBrowse() {
// $NON-NLS-1$
String[] extensions = { ".xsd" };
SelectFileOrXMLCatalogIdDialog dialog = new SelectFileOrXMLCatalogIdDialog(getShell(), extensions);
dialog.create();
dialog.getShell().setText(XMLUIMessages._UI_LABEL_SELECT_FILE);
dialog.setBlockOnOpen(true);
dialog.open();
if (dialog.getReturnCode() == Window.OK) {
String grammarURI = null;
IFile file = dialog.getFile();
String id = dialog.getId();
if (file != null) {
String uri = null;
if (resourceLocation != null) {
IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourceLocation);
if (resource != null) {
IPath location = resource.getLocation();
if (location != null) {
uri = URIHelper.getRelativeURI(file.getLocation(), location);
}
} else {
uri = URIHelper.getRelativeURI(file.getLocation(), resourceLocation);
}
grammarURI = file.getLocation().toOSString();
} else {
uri = file.getLocation().toOSString();
grammarURI = uri;
}
locationHintField.setText(uri);
} else if (id != null) {
locationHintField.setText(id);
URIResolver resolver = URIResolverPlugin.createResolver();
grammarURI = resolver.resolve(null, id, id);
}
// $NON-NLS-1$
CMDocument document = ContentModelManager.getInstance().createCMDocument(URIHelper.getURIForFilePath(grammarURI), "xsd");
if (document != null) {
// $NON-NLS-1$
List namespaceInfoList = (List) document.getProperty("http://org.eclipse.wst/cm/properties/namespaceInfo");
if (namespaceInfoList != null) {
NamespaceInfo info = (NamespaceInfo) namespaceInfoList.get(0);
if (info != null) {
if ((uriField.getText().trim().length() == 0) && (info.uri != null)) {
uriField.setText(info.uri);
}
if ((prefixField.getText().trim().length() == 0) && (info.prefix != null)) {
prefixField.setText(info.prefix);
}
}
}
}
}
}
use of org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver 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;
}
Aggregations