use of org.eclipse.jst.jsp.core.taglib.IURLRecord in project webtools.sourceediting by eclipse.
the class JSPDirectiveValidator method processTaglibDirective.
private void processTaglibDirective(IReporter reporter, IFile file, IStructuredDocument sDoc, ITextRegionCollection documentRegion) {
ITextRegion prefixValueRegion = null;
ITextRegion uriValueRegion = getAttributeValueRegion(documentRegion, JSP11Namespace.ATTR_NAME_URI);
ITextRegion tagdirValueRegion = getAttributeValueRegion(documentRegion, JSP20Namespace.ATTR_NAME_TAGDIR);
if (uriValueRegion != null) {
// URI is specified
String uri = documentRegion.getText(uriValueRegion);
if (file != null) {
uri = StringUtils.stripQuotes(uri);
if (uri.length() > 0) {
ITaglibRecord reference = TaglibIndex.resolve(file.getFullPath().toString(), uri, false);
if (reference != null) {
switch(reference.getRecordType()) {
case (ITaglibRecord.TLD):
{
ITLDRecord record = (ITLDRecord) reference;
IResource tldfile = ResourcesPlugin.getWorkspace().getRoot().getFile(record.getPath());
addDependsOn(tldfile);
}
break;
case (ITaglibRecord.JAR):
{
IJarRecord record = (IJarRecord) reference;
IFile[] foundFilesForLocation = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(record.getLocation());
for (int i = 0; i < foundFilesForLocation.length; i++) {
addDependsOn(foundFilesForLocation[i]);
}
}
break;
case (ITaglibRecord.TAGDIR):
{
ITagDirRecord record = (ITagDirRecord) reference;
IPath path = record.getPath();
IResource found = ResourcesPlugin.getWorkspace().getRoot().findMember(path, false);
try {
found.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource.getType() == IResource.FILE) {
addDependsOn(resource);
}
return true;
}
});
} catch (CoreException e) {
Logger.logException(e);
}
}
break;
case (ITaglibRecord.URL):
{
IURLRecord record = (IURLRecord) reference;
String baseLocation = record.getBaseLocation();
if (baseLocation != null && baseLocation.indexOf("://") < 0) {
// $NON-NLS-1$
IResource found = ResourcesPlugin.getWorkspace().getRoot().findMember(baseLocation, false);
if (found != null) {
try {
found.accept(new IResourceVisitor() {
public boolean visit(IResource resource) throws CoreException {
if (resource.getType() == IResource.FILE) {
addDependsOn(resource);
}
return true;
}
});
} catch (CoreException e) {
Logger.logException(e);
}
} else {
IFile externalJar = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(baseLocation));
if (externalJar != null) {
addDependsOn(externalJar);
}
}
}
}
break;
}
}
if (reference == null && fSeverityTaglibUnresolvableURI != ValidationMessage.IGNORE) {
// URI specified but does not resolve
String msgText = null;
// provide better messages for typical "http:*" URIs
final float version = DeploymentDescriptorPropertyCache.getInstance().getJSPVersion(file.getFullPath());
if (uri.startsWith("http:") && version < 1.2) {
// $NON-NLS-1$
if (FacetModuleCoreSupport.isDynamicWebProject(file.getProject())) {
msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_9, new Object[] { uri, new Float(version) });
} else {
msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_10, uri);
}
} else {
msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_1, uri);
}
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibUnresolvableURI, msgText, file);
int start = documentRegion.getStartOffset(uriValueRegion);
int length = uriValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
// $NON-NLS-1$
message.setAttribute("PROBLEM_ID", new Integer(611));
reporter.addMessage(fMessageOriginator, message);
}
} else if (fSeverityTaglibMissingURI != ValidationMessage.IGNORE) {
// URI specified but empty string
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_3, JSP11Namespace.ATTR_NAME_URI);
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibMissingURI, msgText, file);
int start = documentRegion.getStartOffset(uriValueRegion);
int length = uriValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
}
} else if (tagdirValueRegion != null) {
// URI is specified
String tagdir = documentRegion.getText(tagdirValueRegion);
if (file != null) {
tagdir = StringUtils.stripQuotes(tagdir);
if (tagdir.length() <= 0 && fSeverityTaglibMissingURI != ValidationMessage.IGNORE) {
// tagdir specified but empty string
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_3, JSP20Namespace.ATTR_NAME_TAGDIR);
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibMissingURI, msgText, file);
int start = documentRegion.getStartOffset(tagdirValueRegion);
int length = tagdirValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
} else if (TaglibIndex.resolve(file.getFullPath().toString(), tagdir, false) == null && fSeverityTagdirUnresolvableURI != ValidationMessage.IGNORE) {
// URI specified but does not resolve
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_11, tagdir);
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibUnresolvableURI, msgText, file);
int start = documentRegion.getStartOffset(tagdirValueRegion);
int length = tagdirValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
}
} else if (fSeverityTaglibMissingURI != ValidationMessage.IGNORE) {
// URI not specified or empty string
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_7, new String[] { JSP20Namespace.ATTR_NAME_TAGDIR, JSP11Namespace.ATTR_NAME_URI });
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibMissingURI, msgText, file);
int start = documentRegion.getStartOffset();
int length = documentRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
prefixValueRegion = getAttributeValueRegion(documentRegion, JSP11Namespace.ATTR_NAME_PREFIX);
if (prefixValueRegion != null) {
// prefix specified
String taglibPrefix = documentRegion.getText(prefixValueRegion);
taglibPrefix = StringUtils.stripQuotes(taglibPrefix);
collectTaglibPrefix(documentRegion, prefixValueRegion, taglibPrefix);
if (isReservedTaglibPrefix(taglibPrefix)) {
// prefix is a reserved prefix
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_0, taglibPrefix);
int sev = IMessage.HIGH_SEVERITY;
LocalizedMessage message = (file == null ? new LocalizedMessage(sev, msgText) : new LocalizedMessage(sev, msgText, file));
int start = documentRegion.getStartOffset(prefixValueRegion);
int length = prefixValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
if (taglibPrefix.length() == 0 && fSeverityTaglibMissingPrefix != ValidationMessage.IGNORE) {
// prefix is specified but empty
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_3, JSP11Namespace.ATTR_NAME_PREFIX);
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibMissingPrefix, msgText, file);
int start = documentRegion.getStartOffset(prefixValueRegion);
int length = prefixValueRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
} else if (fSeverityTaglibMissingPrefix != ValidationMessage.IGNORE) {
// prefix is not specified
String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_3, JSP11Namespace.ATTR_NAME_PREFIX);
LocalizedMessage message = new LocalizedMessage(fSeverityTaglibMissingPrefix, msgText, file);
int start = documentRegion.getStartOffset();
int length = documentRegion.getTextLength();
int lineNo = sDoc.getLineOfOffset(start);
message.setLineNo(lineNo + 1);
message.setOffset(start);
message.setLength(length);
reporter.addMessage(fMessageOriginator, message);
}
}
use of org.eclipse.jst.jsp.core.taglib.IURLRecord in project webtools.sourceediting by eclipse.
the class TestIndex method testAvailableAfterCopyingJARIntoProject.
public void testAvailableAfterCopyingJARIntoProject() throws Exception {
// Create new project
IProject project = BundleResourceUtil.createSimpleProject("bug_118251-f", null, null);
assertTrue(project.exists());
ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f"));
assertEquals("wrong number of taglib records found before unpacking", 0, records.length);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug_118251-f", "/bug_118251-f");
// bug_118251-f/WebContent/WEB-INF/web.xml
// bug_118251-f/WebContent/WEB-INF/tld/sample2_for_118251-e.tld
// bug_118251-f/WebContent/META-INF/MANIFEST.MF
// bug_118251-f/WebContent/test1.jsp
// bug_118251-f/.classpath
// bug_118251-f/.project
String url = "http://example.com/sample-taglib";
ITaglibRecord taglibRecord = TaglibIndex.resolve("/bug_118251-f/WebContent/test1.jsp", url, false);
assertNull("unexpected record found for " + url, taglibRecord);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/"));
assertEquals("wrong number of taglib records found after unpacking but before copying", 3, records.length);
/*
* increase by <b>one</b> for the URL to the TLD in the jar (one
* implicit for the TLD in the jar as a resource and another implicit
* overwriting it with the same URL to the TLD in the jar on the
* classpath)
*/
BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/bug_118251-f/WebContent/WEB-INF/lib/sample_tld.jar");
taglibRecord = TaglibIndex.resolve("/bug_118251-f/WebContent/test1.jsp", url, false);
assertNotNull("no record found for " + url, taglibRecord);
assertTrue("record found was wrong type", taglibRecord instanceof IURLRecord);
assertNotNull("record has no base location", ((IURLRecord) taglibRecord).getBaseLocation());
assertEquals("record has wrong short name", "sample", ((IURLRecord) taglibRecord).getShortName());
assertEquals("record has wrong URI", url, ((IURLRecord) taglibRecord).getDescriptor().getURI());
URL recordURL = ((IURLRecord) taglibRecord).getURL();
assertNotNull("record has no URL", recordURL);
assertTrue("record has wrong URL", recordURL.toString().length() > 4);
assertEquals("record has wrong URL protocol", "jar:", recordURL.toString().substring(0, 4));
assertEquals("record has wrong URL", "/bug_118251-f/WebContent/WEB-INF/lib/sample_tld.jar!/folder/sample_for_118251.tld", recordURL.toString().substring(recordURL.toString().length() - 81));
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/WEB-INF"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-f/WebContent/WEB-INF/web.xml"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
}
use of org.eclipse.jst.jsp.core.taglib.IURLRecord in project webtools.sourceediting by eclipse.
the class TestIndex method testAvailableAfterCopyingJARIntoProject2.
public void testAvailableAfterCopyingJARIntoProject2() throws Exception {
// Create new project
IProject project = BundleResourceUtil.createSimpleProject("bug_118251-g", null, null);
assertTrue(project.exists());
ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g"));
assertEquals("wrong number of taglib records found before unpacking", 0, records.length);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug_118251-g", "/bug_118251-g");
// bug_118251-g/Web Content/WEB-INF/web.xml
// bug_118251-g/Web Content/WEB-INF/tld/sample2_for_118251-e.tld
// bug_118251-g/Web Content/META-INF/MANIFEST.MF
// bug_118251-g/Web Content/test1.jsp
// bug_118251-g/.classpath
// bug_118251-g/.project
String url = "http://example.com/sample-taglib";
ITaglibRecord taglibRecord = TaglibIndex.resolve("/bug_118251-g/Web Content/test1.jsp", url, false);
assertNull("unexpected record found for " + url, taglibRecord);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/"));
assertEquals("wrong number of taglib records found after unpacking but before copying", 3, records.length);
/*
* increase by <b>one</b> for the URL to the TLD in the jar (one
* implicit for the TLD in the jar as a resource and another implicit
* overwriting it with the same URL to the TLD in the jar on the
* classpath)
*/
BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/bug_118251-g/Web Content/WEB-INF/lib/sample_tld.jar");
taglibRecord = TaglibIndex.resolve("/bug_118251-g/Web Content/test1.jsp", url, false);
assertNotNull("no record found for " + url, taglibRecord);
assertTrue("record found was wrong type", taglibRecord instanceof IURLRecord);
assertNotNull("record has no base location", ((IURLRecord) taglibRecord).getBaseLocation());
assertEquals("record has wrong short name", "sample", ((IURLRecord) taglibRecord).getShortName());
assertEquals("record has wrong URI", url, ((IURLRecord) taglibRecord).getDescriptor().getURI());
URL recordURL = ((IURLRecord) taglibRecord).getURL();
assertNotNull("record has no URL", recordURL);
assertTrue("record has wrong URL", recordURL.toString().length() > 4);
assertEquals("record has wrong URL protocol", "jar:", recordURL.toString().substring(0, 4));
assertEquals("record has wrong URL", "/bug_118251-g/Web Content/WEB-INF/lib/sample_tld.jar!/folder/sample_for_118251.tld", recordURL.toString().substring(recordURL.toString().length() - 82));
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/WEB-INF"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-g/Web Content/WEB-INF/web.xml"));
assertEquals("wrong number of taglib records found after copying", 4, records.length);
}
Aggregations