use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project liferay-ide by liferay.
the class JSFLiferayPortletDescriptorHelper method addDescriptorOperations.
@Override
protected void addDescriptorOperations() {
super.addDescriptorOperations();
UpdateDescriptorVersionOperation operation = new UpdateDescriptorVersionOperation() {
@Override
public IStatus update(Version preVersion, Version postVersion) {
if ((CoreUtil.compareVersions(preVersion, ILiferayConstants.V620) >= 0) && (CoreUtil.compareVersions(postVersion, ILiferayConstants.V620) < 0)) {
IFile descriptorFile = getDescriptorFile();
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(descriptorFile);
IDOMDocument document = domModel.getDocument();
IStatus status = _downgradeJSFLiferayPortletXMLTo61(document);
if (!status.isOK()) {
return status;
}
domModel.save();
} catch (Exception e) {
PortletCore.logError("Error editing liferay-portlet.xml", e);
} finally {
if (domModel != null) {
domModel.releaseFromEdit();
}
}
}
return Status.OK_STATUS;
}
};
addDescriptorOperation(operation);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project liferay-ide by liferay.
the class BaseValidator method checkAllClassElements.
@SuppressWarnings("unchecked")
protected Map<String, Object>[] checkAllClassElements(Map<String, String> map, IJavaProject javaProject, IFile liferayDescriptorXml, String classExistPreferenceKey, String classHierarchyPreferenceKey, IScopeContext[] preferenceScopes, String preferenceNodeQualifier, List<Map<String, Object>> problems) throws CoreException {
IStructuredModel liferayDescriptorXmlModel = null;
IDOMDocument liferayDescriptorXmlDocument = null;
try {
liferayDescriptorXmlModel = StructuredModelManager.getModelManager().getModelForRead(liferayDescriptorXml);
if ((liferayDescriptorXmlModel != null) && liferayDescriptorXmlModel instanceof IDOMModel && (map != null)) {
liferayDescriptorXmlDocument = ((IDOMModel) liferayDescriptorXmlModel).getDocument();
for (String elementName : map.keySet()) {
checkClassElements(liferayDescriptorXmlDocument, javaProject, elementName, preferenceNodeQualifier, preferenceScopes, classExistPreferenceKey, classHierarchyPreferenceKey, problems, map.get(elementName));
}
}
} catch (IOException ioe) {
ProjectCore.logError(ioe);
} finally {
if (liferayDescriptorXmlModel != null) {
liferayDescriptorXmlModel.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 JSPFileWTP method createSearchResult.
@Override
protected SearchResult createSearchResult(String searchContext, int startOffset, int endOffset, int startLine, int endLine, boolean fullMatch) {
IDOMModel jspModel = null;
try {
int jspStartOffset = _translation.getJspOffset(startOffset);
int jspEndOffset = _translation.getJspOffset(endOffset);
jspModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(_translation.getJspFile());
IDOMDocument domDocument = jspModel.getDocument();
IStructuredDocument structuredDocument = domDocument.getStructuredDocument();
int jspStartLine = structuredDocument.getLineOfOffset(jspStartOffset) + 1;
int jspEndLine = structuredDocument.getLineOfOffset(jspEndOffset) + 1;
return super.createSearchResult(searchContext, jspStartOffset, jspEndOffset, jspStartLine, jspEndLine, fullMatch);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (jspModel != null) {
jspModel.releaseFromRead();
}
}
return super.createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, fullMatch);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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.IDOMModel 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;
}
Aggregations