Search in sources :

Example 1 with IDOMElement

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

the class LayoutTplElementsFactory method newLayoutTplFromModel.

public LayoutTplElement newLayoutTplFromModel(IDOMModel model, Boolean bootstrapStyle, Boolean is62) {
    if (model == null) {
        return null;
    }
    LayoutTplElement layoutTpl = null;
    IDOMDocument rootDocument = model.getDocument();
    IDOMElement mainContentElement = LayoutTplUtil.findMainContentElement(rootDocument);
    if (mainContentElement != null) {
        layoutTpl = LayoutTplElement.TYPE.instantiate();
        layoutTpl.setBootstrapStyle(bootstrapStyle);
        layoutTpl.setClassName(mainContentElement.getAttribute("class"));
        layoutTpl.setIs62(is62);
        IDOMElement[] portletLayoutElements = LayoutTplUtil.findChildElementsByClassName(mainContentElement, "div", "portlet-layout");
        if (ListUtil.isNotEmpty(portletLayoutElements)) {
            for (IDOMElement portletLayoutElement : portletLayoutElements) {
                PortletLayoutElement portletLayout = layoutTpl.getPortletLayouts().insert();
                initPortletLayoutFromElement(portletLayout, portletLayoutElement);
            }
        }
    }
    return layoutTpl;
}
Also used : IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 2 with IDOMElement

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

the class SSEXMLFile method findElement.

@Override
public List<SearchResult> findElement(String tagName, String value) {
    List<SearchResult> results = new ArrayList<>();
    IFile xmlFile = getIFile(file);
    IDOMModel domModel = null;
    try {
        domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(xmlFile);
        IDOMDocument document = domModel.getDocument();
        NodeList elements = document.getElementsByTagName(tagName);
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                IDOMElement element = (IDOMElement) elements.item(i);
                String textContent = element.getTextContent();
                if ((textContent != null) && value.trim().equals(textContent.trim())) {
                    int startOffset = element.getStartOffset();
                    int endOffset = element.getEndOffset();
                    int startLine = document.getStructuredDocument().getLineOfOffset(startOffset) + 1;
                    int endLine = document.getStructuredDocument().getLineOfOffset(endOffset) + 1;
                    SearchResult result = new SearchResult(file, "startOffset:" + startOffset, startOffset, endOffset, startLine, endLine, true);
                    results.add(result);
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (domModel != null) {
            domModel.releaseFromRead();
        }
    }
    return results;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 3 with IDOMElement

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

the class UITestsUtils method getRegion.

public static IRegion getRegion(Node node) {
    if (node != null) {
        switch(node.getNodeType()) {
            case Node.ELEMENT_NODE:
                IDOMElement element = (IDOMElement) node;
                int endOffset;
                if (element.hasEndTag() && element.isClosed()) {
                    endOffset = element.getStartEndOffset();
                } else {
                    endOffset = element.getEndOffset();
                }
                if (element.getFirstChild() == null || element.getFirstChild().getTextContent().isEmpty()) {
                    return new Region(endOffset, 0);
                }
                return new Region(endOffset, element.getTextContent().length());
            case Node.ATTRIBUTE_NODE:
                IDOMAttr att = (IDOMAttr) node;
                int regOffset = att.getValueRegionStartOffset();
                int regLength = att.getValueRegionText().length();
                String attValue = att.getValueRegionText();
                if (StringUtil.isQuoted(attValue)) {
                    regOffset++;
                    regLength -= 2;
                }
                return new Region(regOffset, regLength);
            case Node.TEXT_NODE:
                IDOMText text = (IDOMText) node;
                int startOffset = text.getStartOffset();
                int length = text.getLength();
                return new Region(startOffset, length);
        }
    }
    return null;
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) IDOMText(org.eclipse.wst.xml.core.internal.provisional.document.IDOMText) Region(org.eclipse.jface.text.Region) IRegion(org.eclipse.jface.text.IRegion) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 4 with IDOMElement

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

the class LiferayMavenLegacyProjectUpdater method isNeedUpgrade.

@Override
public boolean isNeedUpgrade(IFile pomFile) {
    String tagName = "artifactId";
    String[] values = { "liferay-maven-plugin", "portal-service", "util-java", "util-bridges", "util-taglib", "util-slf4j" };
    IDOMModel domModel = null;
    boolean retval = false;
    try {
        domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(pomFile);
        IDOMDocument document = domModel.getDocument();
        NodeList elements = document.getElementsByTagName(tagName);
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                IDOMElement element = (IDOMElement) elements.item(i);
                String textContent = element.getTextContent();
                if (!CoreUtil.empty(textContent)) {
                    textContent = textContent.trim();
                    for (String str : values) {
                        if (textContent.equals(str)) {
                            retval = true;
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (domModel != null) {
            domModel.releaseFromRead();
        }
    }
    return retval;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with IDOMElement

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project webtools.sourceediting by eclipse.

the class HTMLAttributeValidator method getErrorSegment.

/**
 */
public static Segment getErrorSegment(IDOMNode errorNode, int regionType) {
    ITextRegion rgn = null;
    switch(regionType) {
        case REGION_NAME:
            rgn = errorNode.getNameRegion();
            break;
        case REGION_VALUE:
            rgn = errorNode.getValueRegion();
            break;
        default:
            // nothing to do.
            break;
    }
    if (rgn != null) {
        if (errorNode instanceof IDOMAttr) {
            IDOMElement ownerElement = (IDOMElement) ((IDOMAttr) errorNode).getOwnerElement();
            if (ownerElement != null) {
                // if editor closed during validation this could be null
                IStructuredDocumentRegion firstRegion = ownerElement.getFirstStructuredDocumentRegion();
                if (firstRegion != null) {
                    int regionStartOffset = firstRegion.getStartOffset(rgn);
                    int regionLength = rgn.getTextLength();
                    return new Segment(regionStartOffset, regionLength);
                }
            }
        }
    }
    return new Segment(errorNode.getStartOffset(), 1);
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Aggregations

IDOMElement (org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)59 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)20 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)19 Node (org.w3c.dom.Node)18 NodeList (org.w3c.dom.NodeList)13 Element (org.w3c.dom.Element)11 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)9 IDOMAttr (org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr)9 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)8 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)8 NamedNodeMap (org.w3c.dom.NamedNodeMap)8 ArrayList (java.util.ArrayList)7 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)7 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)7 IFile (org.eclipse.core.resources.IFile)6 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)6 List (java.util.List)5 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)5 Text (org.w3c.dom.Text)5 ModelQuery (org.eclipse.wst.xml.core.internal.contentmodel.modelquery.ModelQuery)4