Search in sources :

Example 6 with IDOMModel

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

the class JSPFileWTP method _getJspLine.

private int _getJspLine(int offset) {
    IFile jspFile = _translation.getJspFile();
    IDOMModel jspModel = null;
    IDOMDocument domDocument = null;
    try {
        jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(jspFile);
        domDocument = jspModel.getDocument();
        return domDocument.getStructuredDocument().getLineOfOffset(offset) + 1;
    } catch (CoreException | IOException e) {
        e.printStackTrace();
    } finally {
        if (jspModel != null) {
            jspModel.releaseFromRead();
        }
    }
    return 0;
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IOException(java.io.IOException)

Example 7 with IDOMModel

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

the class LiferayLanguageFileEncodingTests method removeSpecifiedNode.

private void removeSpecifiedNode(IFile file, String nodeName, String content) throws Exception {
    final IStructuredModel model = StructuredModelManager.getModelManager().getModelForEdit(file);
    final IDOMDocument document = ((IDOMModel) model).getDocument();
    final NodeList elements = document.getElementsByTagName(nodeName);
    for (int i = 0; i < elements.getLength(); i++) {
        Node node = elements.item(i);
        if (content.equals(node.getTextContent())) {
            node.getParentNode().removeChild(node);
            break;
        }
    }
    model.save(file);
    model.releaseFromEdit();
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 8 with IDOMModel

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

the class WorkflowDefinitionValidator method detectProblems.

@SuppressWarnings("unchecked")
public Map<String, Object>[] detectProblems(IFile workflowDefinitionXml, IScopeContext[] preferenceScopes) throws CoreException {
    List<Map<String, Object>> problems = new ArrayList<>();
    IStructuredModel model = null;
    try {
        IModelManager modelManage = StructuredModelManager.getModelManager();
        model = modelManage.getModelForRead(workflowDefinitionXml);
        if ((model != null) && model instanceof IDOMModel) {
            IDOMDocument document = ((IDOMModel) model).getDocument();
            try {
                IWorkflowValidation workflowValidation = KaleoCore.getWorkflowValidation(ServerUtil.getRuntime(workflowDefinitionXml.getProject()));
                Exception error = workflowValidation.validate(workflowDefinitionXml.getContents());
                if ((error != null) && !CoreUtil.isNullOrEmpty(error.getMessage())) {
                    Map<String, Object> problem = createMarkerValues(PREFERENCE_NODE_QUALIFIER, preferenceScopes, WORKFLOW_DEFINITION_VALIDATE, (IDOMNode) document.getFirstChild(), error.getMessage());
                    problems.add(problem);
                }
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
    } finally {
        if (model != null) {
            model.releaseFromRead();
        }
    }
    Map<String, Object>[] retval = new Map[problems.size()];
    return (Map<String, Object>[]) problems.toArray(retval);
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) IModelManager(org.eclipse.wst.sse.core.internal.provisional.IModelManager) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) CoreException(org.eclipse.core.runtime.CoreException) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) Map(java.util.Map)

Example 9 with IDOMModel

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

the class XmlSearchTestsUtils method getAttrValueOffset.

public static int getAttrValueOffset(IFile file, String elementName, String attrName) throws Exception {
    final IDOMModel domModel = getDOMModel(file, false);
    final Node attrNode = domModel.getDocument().getElementsByTagName(elementName).item(0).getAttributes().getNamedItem(attrName);
    int retval = getRegion(attrNode).getOffset();
    domModel.releaseFromRead();
    return retval;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node)

Example 10 with IDOMModel

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

the class XmlSearchTestsUtils method getProposals.

private static ICompletionProposal[] getProposals(IFile file, int nodeType, String... nodeNames) throws Exception {
    Node targetNode = null;
    IDOMModel domModel = null;
    final StructuredTextViewer viewer = getEditor(file).getTextViewer();
    final SourceViewerConfiguration srcViewConf = getSourceViewerConfiguraionFromExtensionPoint(file);
    viewer.refresh();
    if (nodeType == Node.ELEMENT_NODE) {
        String elementName = nodeNames[0];
        domModel = getDOMModel(file, false);
        targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0);
    } else if (nodeType == Node.ATTRIBUTE_NODE) {
        String elementName = nodeNames[0];
        String attrName = nodeNames[1];
        domModel = getDOMModel(file, false);
        NodeList elements = domModel.getDocument().getElementsByTagName(elementName);
        Element element = getElementByAttr(elements, attrName);
        targetNode = element.getAttributes().getNamedItem(attrName);
    }
    if (nodeType == Node.TEXT_NODE) {
        String elementName = nodeNames[0];
        domModel = getDOMModel(file, false);
        targetNode = domModel.getDocument().getElementsByTagName(elementName).item(0).getFirstChild();
    }
    int offset = getRegion(targetNode).getOffset() + getRegion(targetNode).getLength();
    final ContentAssistant contentAssistant = (ContentAssistant) srcViewConf.getContentAssistant(viewer);
    // viewer.configure( srcViewConf );
    // viewer.setSelectedRange( offset, 0 );
    // get the processor
    final String partitionTypeID = viewer.getDocument().getPartition(offset).getType();
    final IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID);
    // get content assist suggestions
    final ICompletionProposal[] proposals = processor.computeCompletionProposals(viewer, offset);
    domModel.releaseFromRead();
    return proposals;
}
Also used : SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IContentAssistProcessor(org.eclipse.jface.text.contentassist.IContentAssistProcessor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) StructuredTextViewer(org.eclipse.wst.sse.ui.internal.StructuredTextViewer)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25