use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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.IDOMDocument 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.IDOMDocument in project liferay-ide by liferay.
the class KaleoEdits method insertAt.
public static Element insertAt(Element newElement, int offset) {
Document doc = newElement.getOwnerDocument();
if (doc instanceof IDOMDocument) {
IDOMDocument domDoc = (IDOMDocument) doc;
IndexedRegion ir = domDoc.getModel().getIndexedRegion(offset);
Node parent = ((Node) ir).getParentNode();
if (ir instanceof Text) {
Text txt = (Text) ir;
String data = txt.getData();
int dataSplitIndex = offset - ir.getStartOffset();
String beforeText = data.substring(0, dataSplitIndex);
String afterText = data.substring(dataSplitIndex);
Text after = doc.createTextNode(afterText);
Text before = doc.createTextNode(beforeText);
parent.replaceChild(after, txt);
parent.insertBefore(newElement, after);
parent.insertBefore(before, newElement);
} else if (ir instanceof Element) {
((Element) ir).appendChild(newElement);
} else {
throw new IllegalArgumentException();
}
} else {
throw new IllegalArgumentException();
}
return newElement;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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);
}
Aggregations