Search in sources :

Example 6 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testRecordCacheCountBetweenSessions.

/**
 * test caching from session-to-session
 */
public void testRecordCacheCountBetweenSessions() throws Exception {
    TaglibIndex.shutdown();
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject("testcache1", null, null);
    assertTrue(project.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/testcache1", "/testcache1");
    BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/testcache1/WebContent/WEB-INF/lib/sample_tld.jar");
    TaglibIndex.startup();
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match", 5, records.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    ITaglibRecord[] records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (1st restart)", records.length, records2.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (2nd restart)", records.length, records2.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache1/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (3rd restart)", records.length, records2.length);
}
Also used : Path(org.eclipse.core.runtime.Path) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IProject(org.eclipse.core.resources.IProject)

Example 7 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testAvailableAfterAddingJARToBuildPath.

public void testAvailableAfterAddingJARToBuildPath() throws Exception {
    String url = "http://example.com/sample2_for_118251-e";
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject("bug_118251-e", null, null);
    assertTrue(project.exists());
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-e"));
    assertEquals("wrong number of taglib records found before unpacking", 0, records.length);
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/bug_118251-e", "/bug_118251-e");
    // bug_118251-e/WebContent/WEB-INF/web.xml
    // bug_118251-e/WebContent/WEB-INF/tld/sample2_for_118251-e.tld
    // bug_118251-e/WebContent/META-INF/MANIFEST.MF
    // bug_118251-e/WebContent/test1.jsp
    // bug_118251-e/.classpath
    // bug_118251-e/.project
    ITaglibRecord taglibRecord = TaglibIndex.resolve("/bug_118251-e/WebContent/test1.jsp", url, false);
    assertNull("unexpected record found for " + url, taglibRecord);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-e/WebContent/"));
    assertEquals("wrong number of taglib records found after unpacking but before copying", 2, 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-e/WebContent/WEB-INF/sample_tld.jar");
    url = "http://example.com/sample-taglib";
    taglibRecord = TaglibIndex.resolve("/bug_118251-e/WebContent/test1.jsp", url, false);
    assertNotNull("expected record missing for " + url, taglibRecord);
    records = TaglibIndex.getAvailableTaglibRecords(new Path("/bug_118251-e/WebContent/"));
    assertEquals("wrong number of taglib records found after copying", 3, records.length);
}
Also used : Path(org.eclipse.core.runtime.Path) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IProject(org.eclipse.core.resources.IProject)

Example 8 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class TestIndex method testCachingWithAddingLibrary.

/**
 * test caching from session-to-session with an addition in one session
 */
public void testCachingWithAddingLibrary() throws Exception {
    // Create new project
    IProject project = BundleResourceUtil.createSimpleProject("testcache2", null, null);
    assertTrue(project.exists());
    BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/testcache2", "/testcache2");
    ITaglibRecord[] records = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache2/WebContent"));
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    ITaglibRecord[] records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (1st restart)", records.length, records2.length);
    BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/bug_118251-sample/sample_tld.jar", "/testcache2/WebContent/WEB-INF/lib/sample_tld.jar");
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (1st restart, added jar file)", records.length + 1, records2.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match (2nd restart)", records.length + 1, records2.length);
    BundleResourceUtil.addLibraryEntry(project, "WebContent/WEB-INF/lib/sample_tld.jar");
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    assertEquals("total ITaglibRecord count doesn't match (3nd restart)", records.length + 1, records2.length);
    TaglibIndex.shutdown();
    TaglibIndex.startup();
    records2 = TaglibIndex.getAvailableTaglibRecords(new Path("/testcache2/WebContent"));
    assertEquals("total ITaglibRecord count doesn't match changed value (4th restart, add jar to build path)", records.length + 2, records2.length);
}
Also used : Path(org.eclipse.core.runtime.Path) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IProject(org.eclipse.core.resources.IProject)

Example 9 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord in project webtools.sourceediting by eclipse.

the class JSPTaglibCompletionProposalComputer method addAttributeValueProposals.

/**
 * @see org.eclipse.wst.xml.ui.internal.contentassist.DefaultXMLCompletionProposalComputer#addAttributeValueProposals(org.eclipse.wst.xml.ui.internal.contentassist.ContentAssistRequest, org.eclipse.wst.sse.ui.contentassist.CompletionProposalInvocationContext)
 */
protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest, CompletionProposalInvocationContext context) {
    IPath basePath = getBasePath(contentAssistRequest);
    if (basePath != null) {
        IDOMNode node = (IDOMNode) contentAssistRequest.getNode();
        // only add attribute value proposals for specific elements
        if (node.getNodeName().equals(JSP11Namespace.ElementName.DIRECTIVE_TAGLIB)) {
            // Find the attribute name for which this position should have a value
            IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion();
            ITextRegionList openRegions = open.getRegions();
            int i = openRegions.indexOf(contentAssistRequest.getRegion());
            if (i < 0)
                return;
            ITextRegion nameRegion = null;
            while (i >= 0) {
                nameRegion = openRegions.get(i--);
                if (nameRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)
                    break;
            }
            String attributeName = null;
            if (nameRegion != null)
                attributeName = open.getText(nameRegion);
            String currentValue = null;
            if (contentAssistRequest.getRegion().getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE)
                currentValue = contentAssistRequest.getText();
            else
                // $NON-NLS-1$
                currentValue = "";
            String matchString = null;
            // fixups
            int start = contentAssistRequest.getReplacementBeginPosition();
            int length = contentAssistRequest.getReplacementLength();
            if (currentValue.length() > StringUtils.strip(currentValue).length() && // $NON-NLS-1$ //$NON-NLS-2$
            (currentValue.startsWith("\"") || currentValue.startsWith("'")) && contentAssistRequest.getMatchString().length() > 0) {
                matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length());
            } else {
                matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length());
            }
            boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer;
            if (existingComplicatedValue) {
                contentAssistRequest.getProposals().clear();
                contentAssistRequest.getMacros().clear();
            } else {
                String lowerCaseMatch = matchString.toLowerCase(Locale.US);
                if (attributeName.equals(JSP11Namespace.ATTR_NAME_URI)) {
                    ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
                    /*
						 * a simple enough way to remove duplicates (resolution at
						 * runtime would be nondeterministic anyway)
						 */
                    Map uriToRecords = new HashMap();
                    for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
                        ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
                        ITaglibDescriptor descriptor = taglibRecord.getDescriptor();
                        String uri = null;
                        switch(taglibRecord.getRecordType()) {
                            case ITaglibRecord.URL:
                                uri = descriptor.getURI();
                                uriToRecords.put(uri, taglibRecord);
                                break;
                            case ITaglibRecord.JAR:
                                {
                                    IPath location = ((IJarRecord) taglibRecord).getLocation();
                                    IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
                                    IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
                                    for (int fileNumber = 0; fileNumber < files.length; fileNumber++) {
                                        if (localContextRoot.isPrefixOf(files[fileNumber].getFullPath())) {
                                            uri = IPath.SEPARATOR + files[fileNumber].getFullPath().removeFirstSegments(localContextRoot.segmentCount()).toString();
                                            uriToRecords.put(uri, taglibRecord);
                                        } else {
                                            uri = FacetModuleCoreSupport.getRuntimePath(files[fileNumber].getFullPath()).toString();
                                            uriToRecords.put(uri, taglibRecord);
                                        }
                                    }
                                    break;
                                }
                            case ITaglibRecord.TLD:
                                {
                                    uri = descriptor.getURI();
                                    if (uri == null || uri.trim().length() == 0) {
                                        IPath path = ((ITLDRecord) taglibRecord).getPath();
                                        IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
                                        if (localContextRoot.isPrefixOf(path)) {
                                            uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
                                        } else {
                                            uri = FacetModuleCoreSupport.getRuntimePath(path).toString();
                                        }
                                    }
                                    uriToRecords.put(uri, taglibRecord);
                                    break;
                                }
                        }
                    }
                    /*
						 * use the records and their descriptors to construct
						 * proposals
						 */
                    Object[] uris = uriToRecords.keySet().toArray();
                    for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
                        String uri = uris[uriNumber].toString();
                        ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
                        ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
                        if (uri != null && uri.length() > 0 && (matchString.length() == 0 || uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
                            String url = getSmallImageURL(taglibRecord);
                            ImageDescriptor imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
                            if (imageDescriptor == null && url != null) {
                                URL imageURL;
                                try {
                                    imageURL = new URL(url);
                                    imageDescriptor = ImageDescriptor.createFromURL(imageURL);
                                    JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
                                } catch (MalformedURLException e) {
                                    Logger.logException(e);
                                }
                            }
                            String additionalInfo = // $NON-NLS-1$
                            descriptor.getDisplayName() + "<br/>" + descriptor.getDescription() + "<br/>" + // $NON-NLS-1$
                            descriptor.getTlibVersion();
                            Image image = null;
                            try {
                                image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
                            } catch (Exception e) {
                                Logger.logException(e);
                            }
                            if (image == null) {
                                image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                            }
                            CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
                            "\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
                            start, // $NON-NLS-1$ //$NON-NLS-2$
                            length, // $NON-NLS-1$ //$NON-NLS-2$
                            uri.length() + 2, image, uri, null, additionalInfo, IRelevanceConstants.R_NONE);
                            contentAssistRequest.addProposal(proposal);
                        }
                    }
                } else if (attributeName.equals(JSP20Namespace.ATTR_NAME_TAGDIR)) {
                    ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
                    /*
						 * a simple enough way to remove duplicates (resolution at
						 * runtime would be nondeterministic anyway)
						 */
                    Map uriToRecords = new HashMap();
                    IPath localContextRoot = FacetModuleCoreSupport.computeWebContentRootPath(basePath);
                    for (int taglibRecordNumber = 0; taglibRecordNumber < availableTaglibRecords.length; taglibRecordNumber++) {
                        ITaglibRecord taglibRecord = availableTaglibRecords[taglibRecordNumber];
                        String uri = null;
                        if (taglibRecord.getRecordType() == ITaglibRecord.TAGDIR) {
                            IPath path = ((ITagDirRecord) taglibRecord).getPath();
                            if (localContextRoot.isPrefixOf(path)) {
                                uri = IPath.SEPARATOR + path.removeFirstSegments(localContextRoot.segmentCount()).toString();
                                uriToRecords.put(uri, taglibRecord);
                            }
                        }
                    }
                    /*
						 * use the records and their descriptors to construct
						 * proposals
						 */
                    Object[] uris = uriToRecords.keySet().toArray();
                    for (int uriNumber = 0; uriNumber < uris.length; uriNumber++) {
                        String uri = uris[uriNumber].toString();
                        ITaglibRecord taglibRecord = (ITaglibRecord) uriToRecords.get(uri);
                        ITaglibDescriptor descriptor = (taglibRecord).getDescriptor();
                        if (uri != null && uri.length() > 0 && (matchString.length() == 0 || uri.toLowerCase(Locale.US).startsWith(lowerCaseMatch))) {
                            String url = getSmallImageURL(taglibRecord);
                            ImageDescriptor imageDescriptor = null;
                            if (url != null) {
                                imageDescriptor = JSPUIPlugin.getInstance().getImageRegistry().getDescriptor(url);
                            }
                            if (imageDescriptor == null && url != null) {
                                URL imageURL;
                                try {
                                    imageURL = new URL(url);
                                    imageDescriptor = ImageDescriptor.createFromURL(imageURL);
                                    JSPUIPlugin.getInstance().getImageRegistry().put(url, imageDescriptor);
                                } catch (MalformedURLException e) {
                                    Logger.logException(e);
                                }
                            }
                            // $NON-NLS-1$
                            String additionalInfo = descriptor.getDescription() + "<br/>" + descriptor.getTlibVersion();
                            Image image = null;
                            try {
                                image = JSPUIPlugin.getInstance().getImageRegistry().get(url);
                            } catch (Exception e) {
                                Logger.logException(e);
                            }
                            if (image == null) {
                                image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                            }
                            CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
                            "\"" + uri + "\"", // $NON-NLS-1$ //$NON-NLS-2$
                            start, // $NON-NLS-1$ //$NON-NLS-2$
                            length, // $NON-NLS-1$ //$NON-NLS-2$
                            uri.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
                            image, // $NON-NLS-1$ //$NON-NLS-2$
                            uri, null, additionalInfo, IRelevanceConstants.R_NONE);
                            contentAssistRequest.addProposal(proposal);
                        }
                    }
                } else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PREFIX)) {
                    Node uriAttr = node.getAttributes().getNamedItem(JSP11Namespace.ATTR_NAME_URI);
                    String uri = null;
                    if (uriAttr != null) {
                        uri = uriAttr.getNodeValue();
                        ITaglibRecord[] availableTaglibRecords = TaglibIndex.getAvailableTaglibRecords(basePath);
                        Map prefixMap = new HashMap();
                        for (int taglibrecordNumber = 0; taglibrecordNumber < availableTaglibRecords.length; taglibrecordNumber++) {
                            ITaglibDescriptor descriptor = availableTaglibRecords[taglibrecordNumber].getDescriptor();
                            if (isTaglibForURI(uri, basePath, availableTaglibRecords[taglibrecordNumber])) {
                                String shortName = descriptor.getShortName().trim();
                                if (shortName.length() > 0) {
                                    boolean valid = true;
                                    for (int character = 0; character < shortName.length(); character++) {
                                        valid = valid && !Character.isWhitespace(shortName.charAt(character));
                                    }
                                    if (valid) {
                                        prefixMap.put(shortName, descriptor);
                                    }
                                }
                            }
                        }
                        Object[] prefixes = prefixMap.keySet().toArray();
                        for (int j = 0; j < prefixes.length; j++) {
                            String prefix = (String) prefixes[j];
                            ITaglibDescriptor descriptor = (ITaglibDescriptor) prefixMap.get(prefix);
                            Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                            CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
                            "\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
                            start, // $NON-NLS-1$ //$NON-NLS-2$
                            length, // $NON-NLS-1$ //$NON-NLS-2$
                            prefix.length() + 2, // $NON-NLS-1$ //$NON-NLS-2$
                            image, prefix, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
                            contentAssistRequest.addProposal(proposal);
                        }
                    } else {
                        Node dirAttr = node.getAttributes().getNamedItem(JSP20Namespace.ATTR_NAME_TAGDIR);
                        if (dirAttr != null) {
                            String dir = dirAttr.getNodeValue();
                            if (dir != null) {
                                ITaglibRecord record = TaglibIndex.resolve(basePath.toString(), dir, false);
                                if (record != null) {
                                    ITaglibDescriptor descriptor = record.getDescriptor();
                                    if (descriptor != null) {
                                        String shortName = descriptor.getShortName();
                                        Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                                        CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
                                        "\"" + shortName + "\"", // $NON-NLS-1$ //$NON-NLS-2$
                                        start, // $NON-NLS-1$ //$NON-NLS-2$
                                        length, // $NON-NLS-1$ //$NON-NLS-2$
                                        shortName.length() + 2, image, shortName, null, descriptor.getDescription(), IRelevanceConstants.R_NONE);
                                        contentAssistRequest.addProposal(proposal);
                                    } else {
                                        if (dir.startsWith("/WEB-INF/")) {
                                            // $NON-NLS-1$
                                            dir = dir.substring(9);
                                        }
                                        // $NON-NLS-1$ //$NON-NLS-2$
                                        String prefix = StringUtils.replace(dir, "/", "-");
                                        Image image = XMLEditorPluginImageHelper.getInstance().getImage(XMLEditorPluginImages.IMG_OBJ_ATTRIBUTE);
                                        CustomCompletionProposal proposal = new CustomCompletionProposal(// $NON-NLS-1$ //$NON-NLS-2$
                                        "\"" + prefix + "\"", // $NON-NLS-1$ //$NON-NLS-2$
                                        start, // $NON-NLS-1$ //$NON-NLS-2$
                                        length, // $NON-NLS-1$ //$NON-NLS-2$
                                        prefix.length() + 2, image, prefix, null, null, IRelevanceConstants.R_NONE);
                                        contentAssistRequest.addProposal(proposal);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) MalformedURLException(java.net.MalformedURLException) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) CustomCompletionProposal(org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) Image(org.eclipse.swt.graphics.Image) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) ITaglibDescriptor(org.eclipse.jst.jsp.core.taglib.ITaglibDescriptor) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ITaglibRecord

use of org.eclipse.jst.jsp.core.taglib.ITaglibRecord 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);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IResourceVisitor(org.eclipse.core.resources.IResourceVisitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ITaglibRecord(org.eclipse.jst.jsp.core.taglib.ITaglibRecord) ITLDRecord(org.eclipse.jst.jsp.core.taglib.ITLDRecord) CoreException(org.eclipse.core.runtime.CoreException) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITagDirRecord(org.eclipse.jst.jsp.core.taglib.ITagDirRecord) IURLRecord(org.eclipse.jst.jsp.core.taglib.IURLRecord) IResource(org.eclipse.core.resources.IResource) IJarRecord(org.eclipse.jst.jsp.core.taglib.IJarRecord)

Aggregations

ITaglibRecord (org.eclipse.jst.jsp.core.taglib.ITaglibRecord)16 IProject (org.eclipse.core.resources.IProject)10 Path (org.eclipse.core.runtime.Path)10 IPath (org.eclipse.core.runtime.IPath)5 IFile (org.eclipse.core.resources.IFile)4 URL (java.net.URL)3 CMElementDeclarationImpl (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMElementDeclarationImpl)3 ITLDRecord (org.eclipse.jst.jsp.core.taglib.ITLDRecord)3 IURLRecord (org.eclipse.jst.jsp.core.taglib.IURLRecord)3 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)3 CoreException (org.eclipse.core.runtime.CoreException)2 CMDocumentFactoryTLD (org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentFactoryTLD)2 IJarRecord (org.eclipse.jst.jsp.core.taglib.IJarRecord)2 ITagDirRecord (org.eclipse.jst.jsp.core.taglib.ITagDirRecord)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)2 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)2 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)2 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)2 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2