Search in sources :

Example 1 with DocumentProvider

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;
}
Also used : CMDocument(org.eclipse.wst.xml.core.internal.contentmodel.CMDocument) DocumentProvider(org.eclipse.jst.jsp.core.internal.util.DocumentProvider)

Example 2 with DocumentProvider

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));
                }
            }
        }
    }
}
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) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) IDocument(org.eclipse.jface.text.IDocument) CoreException(org.eclipse.core.runtime.CoreException) DocumentProvider(org.eclipse.jst.jsp.core.internal.util.DocumentProvider)

Example 3 with DocumentProvider

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;
}
Also used : Node(org.w3c.dom.Node) DocumentProvider(org.eclipse.jst.jsp.core.internal.util.DocumentProvider)

Example 4 with DocumentProvider

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);
}
Also used : Node(org.w3c.dom.Node) DocumentProvider(org.eclipse.jst.jsp.core.internal.util.DocumentProvider)

Example 5 with DocumentProvider

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());
}
Also used : DocumentProvider(org.eclipse.jst.jsp.core.internal.util.DocumentProvider)

Aggregations

DocumentProvider (org.eclipse.jst.jsp.core.internal.util.DocumentProvider)5 Node (org.w3c.dom.Node)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 IDocument (org.eclipse.jface.text.IDocument)1 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)1 Document (org.w3c.dom.Document)1 NodeList (org.w3c.dom.NodeList)1