Search in sources :

Example 1 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.

the class PortletURLHyperlinkDetector method detectHyperlinks.

public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
    IHyperlink[] retval = null;
    if (_shouldDetectHyperlinks(textViewer, region)) {
        IDocument document = textViewer.getDocument();
        int offset = region.getOffset();
        IDOMNode currentNode = DOMUtils.getNodeByOffset(document, offset);
        IRegion nodeRegion = new Region(currentNode.getStartOffset(), currentNode.getEndOffset() - currentNode.getStartOffset());
        if (_isActionURL(currentNode)) {
            Node name = currentNode.getAttributes().getNamedItem("name");
            if (name != null) {
                long modStamp = ((IDocumentExtension4) document).getModificationStamp();
                IFile file = DOMUtils.getFile(document);
                IMethod[] actionUrlMethods = null;
                if (file.equals(_lastFile) && (modStamp == _lastModStamp) && nodeRegion.equals(_lastNodeRegion)) {
                    actionUrlMethods = _lastActionUrlMethods;
                } else {
                    String nameValue = name.getNodeValue();
                    // search for this method in any portlet classes
                    actionUrlMethods = _findPortletMethods(document, nameValue);
                    _lastModStamp = modStamp;
                    _lastFile = file;
                    _lastNodeRegion = nodeRegion;
                    _lastActionUrlMethods = actionUrlMethods;
                }
                if (ListUtil.isNotEmpty(actionUrlMethods)) {
                    List<IHyperlink> links = new ArrayList<>();
                    for (IMethod method : actionUrlMethods) {
                        if (method.exists()) {
                            links.add(new BasicJavaElementHyperlink(nodeRegion, method));
                        }
                    }
                    if (ListUtil.isNotEmpty(links)) {
                        if (canShowMultipleHyperlinks) {
                            retval = links.toArray(new IHyperlink[0]);
                        } else {
                            retval = new IHyperlink[] { links.get(0) };
                        }
                    }
                }
            }
        }
    }
    return retval;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) IRegion(org.eclipse.jface.text.IRegion) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IMethod(org.eclipse.jdt.core.IMethod) IDocument(org.eclipse.jface.text.IDocument)

Example 2 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.

the class JSPFileWTP method findJSPTags.

@Override
public List<SearchResult> findJSPTags(String tagName, String[] attrNames) {
    if ((tagName == null) || tagName.isEmpty() || ListUtil.isEmpty(attrNames)) {
        throw new IllegalArgumentException("tagName can not be null or empty");
    }
    List<SearchResult> searchResults = new ArrayList<>();
    NodeList nodeList = _getTagNodes(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        IDOMNode domNode = (IDOMNode) nodeList.item(i);
        for (String attrName : attrNames) {
            IDOMNode attrNode = (IDOMNode) domNode.getAttributes().getNamedItem(attrName);
            if (attrNode != null) {
                int startOffset = attrNode.getStartOffset();
                int endOffset = startOffset + attrName.length();
                int jspStartLine = _getJspLine(startOffset);
                int jspEndLine = _getJspLine(endOffset);
                searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
            }
        }
    }
    return searchResults;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 3 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.

the class JSPFileWTP method findJSPTags.

@Override
public List<SearchResult> findJSPTags(String tagName) {
    if ((tagName == null) || tagName.isEmpty()) {
        throw new IllegalArgumentException("tagName can not be null or empty");
    }
    List<SearchResult> searchResults = new ArrayList<>();
    NodeList nodeList = _getTagNodes(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        IDOMNode domNode = (IDOMNode) nodeList.item(i);
        int startOffset = domNode.getStartOffset();
        int endOffset = domNode.getEndOffset();
        int jspStartLine = _getJspLine(startOffset);
        int jspEndLine = _getJspLine(endOffset);
        searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
    }
    return searchResults;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 4 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.

the class CUCacheWTP method _createJSPTranslation.

private JSPTranslationPrime _createJSPTranslation(File file) {
    IDOMModel jspModel = null;
    try {
        // try to find the file in the current workspace, if it can't find
        // it then fall back to copy
        IFile jspFile = getIFile(file);
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(jspFile);
        IDOMDocument domDocument = jspModel.getDocument();
        IDOMNode domNode = (IDOMNode) domDocument.getDocumentElement();
        IProgressMonitor npm = new NullProgressMonitor();
        JSPTranslator translator = new JSPTranslatorPrime();
        if (domNode != null) {
            translator.reset((IDOMNode) domDocument.getDocumentElement(), npm);
        } else {
            translator.reset((IDOMNode) domDocument.getFirstChild(), npm);
        }
        translator.translate();
        IJavaProject javaProject = JavaCore.create(jspFile.getProject());
        return new JSPTranslationPrime(javaProject, translator, jspFile);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) IJavaProject(org.eclipse.jdt.core.IJavaProject) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JSPTranslator(org.eclipse.jst.jsp.core.internal.java.JSPTranslator)

Example 5 with IDOMNode

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode in project liferay-ide by liferay.

the class ServiceBuilderDescriptorValidator method validateSyntax.

@Override
protected boolean validateSyntax(IXMLReference reference, IDOMNode node, IFile file, IValidator validator, IReporter reporter, boolean batchMode) {
    int severity = getServerity(ValidationType.SYNTAX_INVALID, file);
    if (severity != ValidationMessage.IGNORE) {
        String validationMsg = null;
        if (node.getNodeType() == Node.TEXT_NODE) {
            Node parentNode = node.getParentNode();
            if (parentNode.getNodeName().equals("namespace")) {
                String nodeValue = DOMUtils.getNodeValue(node);
                if (!ValidatorUtil.isValidNamespace(nodeValue)) {
                    validationMsg = getMessageText(ValidationType.SYNTAX_INVALID, node);
                }
            }
        } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
            if ("package-path".equals(node.getNodeName()) && "service-builder".equals(((Attr) node).getOwnerElement().getNodeName())) {
                String nodeValue = DOMUtils.getNodeValue(node);
                if (nodeValue != null) {
                    // Use standard java conventions to validate the package
                    // name
                    IStatus javaStatus = JavaConventions.validatePackageName(nodeValue, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
                    if ((javaStatus.getSeverity() == IStatus.ERROR) || (javaStatus.getSeverity() == IStatus.WARNING)) {
                        validationMsg = J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage();
                    }
                }
            }
        }
        if (validationMsg != null) {
            String liferayPluginValidationType = getLiferayPluginValidationType(ValidationType.SYNTAX_INVALID, file);
            addMessage(node, file, validator, reporter, batchMode, validationMsg, severity, liferayPluginValidationType);
            return false;
        }
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) Node(org.w3c.dom.Node) Attr(org.w3c.dom.Attr)

Aggregations

IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)250 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)91 Node (org.w3c.dom.Node)63 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)57 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)44 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)43 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)38 List (java.util.List)35 ArrayList (java.util.ArrayList)34 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)30 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)30 CMNode (org.eclipse.wst.xml.core.internal.contentmodel.CMNode)27 Element (org.w3c.dom.Element)27 NodeList (org.w3c.dom.NodeList)23 BadLocationException (org.eclipse.jface.text.BadLocationException)22 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)22 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)20 IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)19 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)18 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)18