Search in sources :

Example 21 with ICatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog in project webtools.sourceediting by eclipse.

the class ProjectDescription method resolve.

/**
 * @param basePath
 * @param reference
 * @return
 */
ITaglibRecord resolve(String basePath, String reference) {
    ensureUpTodate();
    ITaglibRecord record = null;
    String path = null;
    try {
        float jspVersion = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(new Path(basePath));
        /**
         * http://bugs.eclipse.org/196177 - Support resolution in flexible
         * projects
         */
        IPath resourcePath = FacetModuleCoreSupport.resolve(new Path(basePath), reference);
        if (resourcePath.segmentCount() > 1) {
            String fileExtension = resourcePath.getFileExtension();
            if (fileExtension != null && fileExtension.toLowerCase(Locale.US).equals("tld")) {
                // $NON-NLS-1$
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(resourcePath);
                if (file.isAccessible()) {
                    path = resourcePath.toString();
                }
            } else if (fileExtension != null && fileExtension.toLowerCase(Locale.US).equals("jar")) {
                // $NON-NLS-1$
                IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(resourcePath);
                if (file.isAccessible()) {
                    path = resourcePath.toString();
                }
            } else {
                IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(resourcePath);
                if (folder.isAccessible()) {
                    path = resourcePath.toString();
                }
            }
        }
        LOCK.acquire();
        String localRoot = getLocalRoot(basePath);
        /**
         * Workaround for problem in URIHelper; uris starting with '/' are
         * returned as-is.
         */
        if (path == null) {
            if (reference.startsWith("/")) {
                // $NON-NLS-1$
                path = localRoot + reference;
            } else {
                path = URIHelper.normalize(reference, basePath, localRoot);
            }
        }
        // $NON-NLS-1$
        IPath localWebXML = new Path(localRoot).append("/WEB-INF/web.xml");
        WebXMLRecord webxmlRecord = (WebXMLRecord) fWebXMLReferences.get(localWebXML.toString());
        if (webxmlRecord != null) {
            for (int i = 0; i < webxmlRecord.tldRecords.size(); i++) {
                ITaglibRecord record2 = (ITaglibRecord) webxmlRecord.tldRecords.get(i);
                ITaglibDescriptor descriptor = record2.getDescriptor();
                if (reference.equals(descriptor.getURI())) {
                    record = record2;
                }
            }
        }
        if (record == null) {
            // order dictated by JSP spec 2.0 section 7.2.3
            record = (ITaglibRecord) fJARReferences.get(path);
            // only if 1.1 TLD was found
            if (jspVersion < 1.1 || (record instanceof JarRecord && !((JarRecord) record).has11TLD)) {
                record = null;
            }
        }
        if (record == null) {
            record = (ITaglibRecord) fTLDReferences.get(path);
        }
        if (record == null && jspVersion >= 1.2) {
            Object[] records = (Object[]) getImplicitReferences(basePath).get(reference);
            if (records != null && records.length > 0) {
                if (records.length > 1)
                    records = fTaglibSorter.sort(records);
                record = (ITaglibRecord) records[records.length - 1];
            }
        }
        if (record == null && jspVersion >= 2.0) {
            record = (ITaglibRecord) fTagDirReferences.get(path);
        }
        if (record == null && jspVersion >= 1.2) {
            record = (ITaglibRecord) fClasspathReferences.get(reference);
        }
        if (record == null && jspVersion >= 1.2) {
            Map buildPathReferences = new HashMap();
            List projectsProcessed = new ArrayList(fClasspathProjects.size() + 1);
            projectsProcessed.add(fProject);
            addBuildPathReferences(buildPathReferences, projectsProcessed, false);
            record = (ITaglibRecord) buildPathReferences.get(reference);
        }
        // Check the XML Catalog
        if (record == null) {
            ICatalog catalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
            if (catalog != null) {
                String resolvedString = null;
                try {
                    // Check as system reference first
                    resolvedString = catalog.resolveSystem(reference);
                    // Check as URI
                    if (resolvedString == null || resolvedString.trim().length() == 0) {
                        resolvedString = catalog.resolveURI(reference);
                    }
                    // Check as public ID
                    if (resolvedString == null || resolvedString.trim().length() == 0) {
                        resolvedString = catalog.resolvePublic(reference, basePath);
                    }
                } catch (Exception e) {
                    Logger.logException(e);
                }
                if (resolvedString != null && resolvedString.trim().length() > 0) {
                    record = createCatalogRecord(reference, resolvedString);
                }
            }
        }
        /*
			 * If no records were found and no local-root applies, check ALL
			 * of the web.xml files as a fallback
			 */
        if (record == null && fProject.getFullPath().toString().equals(localRoot)) {
            WebXMLRecord[] webxmls = (WebXMLRecord[]) fWebXMLReferences.values().toArray(new WebXMLRecord[0]);
            for (int i = 0; i < webxmls.length; i++) {
                if (record != null)
                    continue;
                Object[] records = (Object[]) getImplicitReferences(webxmls[i].path.toString()).get(reference);
                if (records != null && records.length > 0) {
                    if (records.length > 1)
                        records = fTaglibSorter.sort(records);
                    record = (ITaglibRecord) records[records.length - 1];
                }
            }
        }
        /*
			 * If no records were found, check the implicit references on the project itself as a fallback
			 */
        if (record == null && jspVersion >= 1.2) {
            Object[] records = (Object[]) getImplicitReferences(fProject.getFullPath().toString()).get(reference);
            if (records != null && records.length > 0) {
                if (records.length > 1)
                    records = fTaglibSorter.sort(records);
                record = (ITaglibRecord) records[records.length - 1];
            }
        }
    } finally {
        LOCK.release();
    }
    return record;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) ZipException(java.util.zip.ZipException) FileNotFoundException(java.io.FileNotFoundException) JavaModelException(org.eclipse.jdt.core.JavaModelException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) List(java.util.List) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) ArrayMap(org.eclipse.jst.jsp.core.internal.java.ArrayMap) Map(java.util.Map) HashMap(java.util.HashMap) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) IFolder(org.eclipse.core.resources.IFolder)

Example 22 with ICatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog in project webtools.sourceediting by eclipse.

the class Catalog method resolveSubordinateCatalogs.

protected String resolveSubordinateCatalogs(int entryType, String publicId, String systemId) throws MalformedURLException, IOException {
    String result = null;
    INextCatalog[] nextCatalogs = getNextCatalogs();
    for (int i = 0; i < nextCatalogs.length; i++) {
        INextCatalog nextCatalog = nextCatalogs[i];
        ICatalog catalog = nextCatalog.getReferencedCatalog();
        if (catalog != null) {
            switch(entryType) {
                case ICatalogEntry.ENTRY_TYPE_PUBLIC:
                    result = catalog.resolvePublic(publicId, systemId);
                    break;
                case ICatalogEntry.ENTRY_TYPE_SYSTEM:
                    result = catalog.resolveSystem(systemId);
                    break;
                case ICatalogEntry.ENTRY_TYPE_URI:
                    result = catalog.resolveURI(systemId);
                    break;
                default:
                    break;
            }
            if (result != null) {
                return result;
            }
        }
    }
    return null;
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 23 with ICatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog in project webtools.sourceediting by eclipse.

the class Catalog method addEntriesFromCatalog.

public void addEntriesFromCatalog(ICatalog catalog) {
    try {
        setNotificationEnabled(false);
        if (catalog != null) {
            ICatalogElement[] entries = ((Catalog) catalog).getCatalogElements();
            for (int i = 0; i < entries.length; i++) {
                CatalogElement clone = (CatalogElement) ((CatalogElement) entries[i]).clone();
                addCatalogElement(clone);
            }
        } else {
            // $NON-NLS-1$
            Logger.log(Logger.ERROR, "argument was null in Catalog.addEntriesFromCatalog");
        }
    } finally {
        setNotificationEnabled(true);
    }
    internalResolver = null;
    notifyChanged();
}
Also used : ICatalogElement(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement) ICatalogElement(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog) IDelegateCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog) INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)

Example 24 with ICatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog in project webtools.sourceediting by eclipse.

the class XMLCatalogURIResolverExtension method resolve.

public String resolve(IFile file, String baseLocation, String publicId, String systemId) {
    // if we have catalog in a project we may add it
    // to the catalog manager first
    ICatalog catalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    if (catalog == null) {
        Logger.log(Logger.ERROR_DEBUG, XMLCoreMessages.Catalog_resolution_null_catalog);
        return null;
    }
    String resolved = null;
    if (systemId != null) {
        try {
            resolved = catalog.resolveSystem(systemId);
            if (resolved == null) {
                resolved = catalog.resolveURI(systemId);
            }
        } catch (MalformedURLException me) {
            Logger.log(Logger.ERROR_DEBUG, XMLCoreMessages.Catalog_resolution_malformed_url);
            resolved = null;
        } catch (IOException ie) {
            Logger.log(Logger.ERROR_DEBUG, XMLCoreMessages.Catalog_resolution_io_exception);
            resolved = null;
        }
    }
    if (resolved == null) {
        if (publicId != null) {
            // 
            if (// $NON-NLS-1$
            !(systemId != null && systemId.endsWith(".xsd"))) {
                try {
                    resolved = catalog.resolvePublic(publicId, systemId);
                    if (resolved == null) {
                        resolved = catalog.resolveURI(publicId);
                    }
                } catch (MalformedURLException me) {
                    Logger.log(Logger.ERROR_DEBUG, XMLCoreMessages.Catalog_resolution_malformed_url);
                    resolved = null;
                } catch (IOException ie) {
                    Logger.log(Logger.ERROR_DEBUG, XMLCoreMessages.Catalog_resolution_io_exception);
                    resolved = null;
                }
            }
        }
    }
    return resolved;
}
Also used : MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Example 25 with ICatalog

use of org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog in project webtools.sourceediting by eclipse.

the class CategoryProvider method retrieveCatalog.

private void retrieveCatalog() {
    if (systemCatalog != null)
        return;
    ICatalog defaultCatalog = XMLCorePlugin.getDefault().getDefaultXMLCatalog();
    INextCatalog[] nextCatalogs = defaultCatalog.getNextCatalogs();
    for (int i = 0; i < nextCatalogs.length; i++) {
        INextCatalog catalog = nextCatalogs[i];
        ICatalog referencedCatalog = catalog.getReferencedCatalog();
        if (referencedCatalog != null) {
            if (XMLCorePlugin.SYSTEM_CATALOG_ID.equals(referencedCatalog.getId())) {
                systemCatalog = referencedCatalog;
            }
        }
    }
}
Also used : INextCatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog) ICatalog(org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)

Aggregations

ICatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog)32 INextCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.INextCatalog)14 ICatalogEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogEntry)8 List (java.util.List)6 IDelegateCatalog (org.eclipse.wst.xml.core.internal.catalog.provisional.IDelegateCatalog)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 IFile (org.eclipse.core.resources.IFile)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashMap (java.util.HashMap)2 Composite (org.eclipse.swt.widgets.Composite)2 Catalog (org.eclipse.wst.xml.core.internal.catalog.Catalog)2 CatalogSet (org.eclipse.wst.xml.core.internal.catalog.CatalogSet)2 IRewriteEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.IRewriteEntry)2 ISuffixEntry (org.eclipse.wst.xml.core.internal.catalog.provisional.ISuffixEntry)2 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)2 ContentModelManager (org.eclipse.wst.xml.core.internal.contentmodel.ContentModelManager)2 NodeList (org.w3c.dom.NodeList)2