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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations