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