Search in sources :

Example 1 with URIResolver

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;
}
Also used : InputSource(org.xml.sax.InputSource) LazyURLInputStream(org.eclipse.wst.xml.core.internal.validation.core.LazyURLInputStream) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)

Example 2 with URIResolver

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("");
    }
}
Also used : URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) ErrorMessage(org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage) DTDFile(org.eclipse.wst.dtd.core.internal.emf.DTDFile)

Example 3 with URIResolver

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;
}
Also used : Entry(org.eclipse.wst.common.core.search.document.Entry) ComponentDeclarationEntry(org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) FileReferenceEntry(org.eclipse.wst.common.core.search.document.FileReferenceEntry) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) XMLSearchDocument(org.eclipse.wst.xml.core.internal.search.impl.XMLSearchDocument) SearchDocument(org.eclipse.wst.common.core.search.document.SearchDocument)

Example 4 with URIResolver

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);
                    }
                }
            }
        }
    }
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URIResolver(org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver) List(java.util.List) NamespaceInfo(org.eclipse.wst.xml.core.internal.contentmodel.util.NamespaceInfo) IResource(org.eclipse.core.resources.IResource)

Example 5 with URIResolver

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

Aggregations

URIResolver (org.eclipse.wst.common.uriresolver.internal.provisional.URIResolver)9 IFile (org.eclipse.core.resources.IFile)4 IResource (org.eclipse.core.resources.IResource)4 IPath (org.eclipse.core.runtime.IPath)4 File (java.io.File)3 URI (java.net.URI)3 Path (org.eclipse.core.runtime.Path)3 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)3 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)3 CMDocumentCache (org.eclipse.wst.xml.core.internal.contentmodel.util.CMDocumentCache)3 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)3 XMLCatalogIdResolver (org.eclipse.wst.xml.core.internal.modelquery.XMLCatalogIdResolver)2 ModelQueryAdapterImpl (org.eclipse.wst.xml.core.internal.ssemodelquery.ModelQueryAdapterImpl)2 List (java.util.List)1 ComponentDeclarationEntry (org.eclipse.wst.common.core.search.document.ComponentDeclarationEntry)1 Entry (org.eclipse.wst.common.core.search.document.Entry)1 FileReferenceEntry (org.eclipse.wst.common.core.search.document.FileReferenceEntry)1 SearchDocument (org.eclipse.wst.common.core.search.document.SearchDocument)1 DTDFile (org.eclipse.wst.dtd.core.internal.emf.DTDFile)1 ErrorMessage (org.eclipse.wst.dtd.core.internal.saxparser.ErrorMessage)1