use of org.eclipse.jst.jsp.core.internal.util.DocumentProvider in project webtools.sourceediting by eclipse.
the class CMDocumentFactoryTLD method buildCMDocumentFromJar.
/**
* Builds a CMDocument
*
* @param jarFileName -
* the name of the containing JAR file
* @param contentFileName -
* the path within the JAR for a valid taglib descriptor
*/
protected CMDocument buildCMDocumentFromJar(String jarFileName, String contentFileName) {
// load the taglib descriptor file
DocumentProvider provider = new DocumentProvider();
provider.setValidating(false);
provider.setBaseReference(jarFileName);
provider.setRootElementName(JSP11TLDNames.TAGLIB);
provider.setJarFileName(jarFileName);
provider.setFileName(contentFileName);
// $NON-NLS-1$ //$NON-NLS-2$
CMDocument document = loadDocument("jar:file://" + jarFileName + "!" + contentFileName, provider.getRootElement());
// 8.4.1
return document;
}
use of org.eclipse.jst.jsp.core.internal.util.DocumentProvider in project webtools.sourceediting by eclipse.
the class ProjectDescription method updateWebXML.
void updateWebXML(IResource webxml, int deltaKind) {
if (webxml.getType() != IResource.FILE)
return;
InputStream webxmlContents = null;
Document document = null;
try {
webxmlContents = ((IFile) webxml).getContents(false);
DocumentProvider provider = new DocumentProvider();
provider.setInputStream(webxmlContents);
provider.setValidating(false);
// $NON-NLS-1$
provider.setRootElementName("web-app");
provider.setBaseReference(webxml.getParent().getFullPath().toString());
document = provider.getDocument(false);
} catch (CoreException e) {
// $NON-NLS-1$
Logger.log(Logger.ERROR_DEBUG, EMPTY_STRING, e);
} finally {
if (webxmlContents != null)
try {
webxmlContents.close();
} catch (IOException e1) {
// ignore
Logger.log(Logger.ERROR_DEBUG, null, e1);
}
}
if (document == null)
return;
if (_debugIndexCreation)
// $NON-NLS-1$
Logger.log(Logger.INFO, "creating records for " + webxml.getFullPath());
WebXMLRecord webxmlRecord = new WebXMLRecord();
webxmlRecord.path = webxml.getFullPath();
fWebXMLReferences.put(webxmlRecord.getWebXML().toString(), webxmlRecord);
NodeList taglibs = document.getElementsByTagName(JSP12TLDNames.TAGLIB);
for (int iTaglib = 0; iTaglib < taglibs.getLength(); iTaglib++) {
// $NON-NLS-1$
String taglibUri = readTextofChild(taglibs.item(iTaglib), "taglib-uri").trim();
// specified location is relative to root of the web-app
// $NON-NLS-1$
String taglibLocation = readTextofChild(taglibs.item(iTaglib), "taglib-location").trim();
IPath path = null;
if (taglibLocation.startsWith("/")) {
// $NON-NLS-1$
path = FacetModuleCoreSupport.resolve(new Path(webxml.getFullPath().toString()), taglibLocation);
} else {
path = new Path(URIHelper.normalize(taglibLocation, webxml.getFullPath().toString(), getLocalRoot(webxml.getFullPath().toString())));
}
if (path.segmentCount() > 1) {
IFile resource = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (resource.isAccessible()) {
ITaglibRecord record = null;
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=125960
*
* Also support mappings to .jar files
*/
if ("jar".equalsIgnoreCase(resource.getFileExtension())) {
// $NON-NLS-1$
JarRecord jarRecord = createJARRecord(resource);
String[] entries = JarUtilities.getEntryNames(resource);
for (int jEntry = 0; jEntry < entries.length; jEntry++) {
if (entries[jEntry].endsWith(".tld")) {
// $NON-NLS-1$
if (entries[jEntry].equals(JarUtilities.JSP11_TAGLIB)) {
jarRecord.has11TLD = true;
InputStream contents = JarUtilities.getInputStream(resource, entries[jEntry]);
if (contents != null) {
TaglibInfo info = extractInfo(resource.getFullPath().toString(), contents);
jarRecord.info = info;
try {
contents.close();
} catch (IOException e) {
Logger.log(Logger.ERROR_DEBUG, null, e);
}
}
}
}
}
record = jarRecord;
// the stored URI should reflect the web.xml's value
if (jarRecord.info == null) {
jarRecord.info = new TaglibInfo();
}
jarRecord.info.uri = taglibUri;
jarRecord.isMappedInWebXML = true;
if (_debugIndexCreation)
// $NON-NLS-1$ //$NON-NLS-2$
Logger.log(Logger.INFO, "created web.xml record for " + taglibUri + "@" + jarRecord.getLocation());
} else {
TLDRecord tldRecord = createTLDRecord(resource);
record = tldRecord;
// the stored URI should reflect the web.xml's value
if (tldRecord.info != null) {
tldRecord.info.uri = taglibUri;
}
if (_debugIndexCreation)
// $NON-NLS-1$ //$NON-NLS-2$
Logger.log(Logger.INFO, "created web.xml record for " + taglibUri + "@" + tldRecord.getPath());
}
if (record != null) {
webxmlRecord.tldRecords.add(record);
getImplicitReferences(webxml.getFullPath().toString()).put(taglibUri, record);
TaglibIndex.getInstance().addDelta(new TaglibIndexDelta(fProject, record, deltaKind));
}
}
}
}
}
use of org.eclipse.jst.jsp.core.internal.util.DocumentProvider in project webtools.sourceediting by eclipse.
the class ProjectDescription method extractInfo.
private TaglibInfo extractInfo(String basePath, InputStream tldContents) {
TaglibInfo info = new TaglibInfo();
if (tldContents != null) {
DocumentProvider provider = new DocumentProvider();
provider.setInputStream(tldContents);
provider.setValidating(false);
provider.setRootElementName(JSP12TLDNames.TAGLIB);
provider.setBaseReference(basePath);
Node child = provider.getRootElement();
if (child == null || child.getNodeType() != Node.ELEMENT_NODE || !child.getNodeName().equals(JSP12TLDNames.TAGLIB)) {
return null;
}
child = child.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals(JSP12TLDNames.URI)) {
info.uri = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.SHORT_NAME) || child.getNodeName().equals(JSP11TLDNames.SHORTNAME)) {
info.shortName = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.DESCRIPTION) || child.getNodeName().equals(JSP11TLDNames.INFO)) {
info.description = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.DISPLAY_NAME)) {
info.displayName = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.JSP_VERSION) || child.getNodeName().equals(JSP11TLDNames.JSPVERSION)) {
info.jspVersion = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.TLIB_VERSION) || child.getNodeName().equals(JSP11TLDNames.TLIBVERSION)) {
info.tlibVersion = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.SMALL_ICON)) {
info.smallIcon = getTextContents(child);
} else if (child.getNodeName().equals(JSP12TLDNames.LARGE_ICON)) {
info.largeIcon = getTextContents(child);
}
}
child = child.getNextSibling();
}
}
return info;
}
use of org.eclipse.jst.jsp.core.internal.util.DocumentProvider in project webtools.sourceediting by eclipse.
the class CMDocumentFactoryTLD method buildCMDocumentFromFile.
/**
* NOT API
*
* @param fileName
* @return
*/
protected CMDocument buildCMDocumentFromFile(String fileName) {
// load the taglib descriptor file
DocumentProvider provider = new DocumentProvider();
provider.setValidating(false);
provider.setBaseReference(fileName);
provider.setRootElementName(JSP11TLDNames.TAGLIB);
provider.setFileName(fileName);
Node rootElement = provider.getRootElement();
return loadDocument(fileName, rootElement);
}
use of org.eclipse.jst.jsp.core.internal.util.DocumentProvider in project webtools.sourceediting by eclipse.
the class CMDocumentFactoryTLD method buildCMDocument.
/**
* NOT API
*
* @param baselocation
* @param input
* @return
*/
public CMDocument buildCMDocument(String baselocation, InputStream input) {
DocumentProvider provider = new DocumentProvider();
provider.setValidating(false);
provider.setRootElementName(JSP11TLDNames.TAGLIB);
provider.setInputStream(input);
if (baselocation != null)
provider.setBaseReference(baselocation);
return loadDocument(baselocation, provider.getRootElement());
}
Aggregations