use of org.eclipse.jst.jsp.core.taglib.ITagDirRecord 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.ITagDirRecord in project webtools.sourceediting by eclipse.
the class TLDCMDocumentManager method getModificationStamp.
private long getModificationStamp(String reference) {
IPath currentParserPath = getCurrentParserPath();
if (currentParserPath == null) {
return IResource.NULL_STAMP;
}
ITaglibRecord record = TaglibIndex.resolve(currentParserPath.toString(), reference, false);
long modificationStamp = IResource.NULL_STAMP;
if (record != null) {
switch(record.getRecordType()) {
case (ITaglibRecord.TLD):
{
IFile tldfile = ResourcesPlugin.getWorkspace().getRoot().getFile(((ITLDRecord) record).getPath());
if (tldfile.isAccessible()) {
modificationStamp = tldfile.getModificationStamp();
}
}
break;
case (ITaglibRecord.JAR):
{
File jarfile = new File(((IJarRecord) record).getLocation().toOSString());
if (jarfile.exists()) {
try {
modificationStamp = jarfile.lastModified();
} catch (SecurityException e) {
modificationStamp = IResource.NULL_STAMP;
}
}
}
break;
case (ITaglibRecord.TAGDIR):
{
IFolder tagFolder = ResourcesPlugin.getWorkspace().getRoot().getFolder(((ITagDirRecord) record).getPath());
if (tagFolder.isAccessible()) {
IResource[] members;
try {
members = tagFolder.members();
for (int i = 0; i < members.length; i++) {
modificationStamp = Math.max(modificationStamp, members[i].getModificationStamp());
}
} catch (CoreException e) {
modificationStamp = IResource.NULL_STAMP;
}
}
}
break;
case (ITaglibRecord.URL):
{
String loc = ((IURLRecord) record).getBaseLocation();
if (loc != null && loc.endsWith(".jar")) {
// $NON-NLS-1$
File jarfile = new File(loc);
if (jarfile.exists()) {
try {
modificationStamp = jarfile.lastModified();
} catch (SecurityException e) {
modificationStamp = IResource.NULL_STAMP;
}
}
}
}
break;
default:
break;
}
}
return modificationStamp;
}
Aggregations