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