use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class PortletContentAssistInfoProvider method doGetTextInfo.
@Override
protected String doGetTextInfo(IDOMElement portletNameElt) {
IDOMElement portletElt = (IDOMElement) portletNameElt.getParentNode();
StringBuilder buf = new StringBuilder();
buf.append("<b>------------------------ Portlet ------------------------</b> ");
// description
buf.append("<br><b>Portlet name:</b> ");
String portletName = _getTextContent(portletElt, "portlet-name");
if (portletName != null) {
buf.append(portletName);
}
// display-name
buf.append("<br><b>Display name:</b> ");
String displayName = _getTextContent(portletElt, "display-name");
if (displayName != null) {
buf.append(displayName);
}
// portlet-class
buf.append("<br><b>Portlet class:</b> ");
String portletClass = _getTextContent(portletElt, "portlet-class");
if (portletClass != null) {
buf.append(portletClass);
}
buf.append("<br><b>File:</b> ");
buf.append(portletElt.getModel().getBaseLocation());
return buf.toString();
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class MVCPortletClassInPortletXML method correctProblems.
@Override
public int correctProblems(File file, List<Problem> problems) throws AutoMigrateException {
int corrected = 0;
IFile xmlFile = getXmlFile(file);
IDOMModel xmlModel = null;
if (xmlFile != null) {
try {
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(xmlFile);
List<IDOMElement> elementsToCorrect = new ArrayList<>();
for (Problem problem : problems) {
if (_KEY.equals(problem.autoCorrectContext)) {
IndexedRegion region = xmlModel.getIndexedRegion(problem.startOffset);
if (region instanceof IDOMElement) {
IDOMElement element = (IDOMElement) region;
elementsToCorrect.add(element);
}
}
}
for (IDOMElement element : elementsToCorrect) {
xmlModel.aboutToChangeModel();
_removeChildren(element);
Text textContent = element.getOwnerDocument().createTextNode("com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet");
element.appendChild(textContent);
xmlModel.changedModel();
corrected++;
}
xmlModel.save();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (xmlModel != null) {
xmlModel.releaseFromEdit();
}
}
}
IPath location = xmlFile.getLocation();
if ((corrected > 0) && !location.toFile().equals(file)) {
try (InputStream xmlFileContent = xmlFile.getContents()) {
Files.copy(xmlFileContent, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new AutoMigrateException("Error writing corrected file.", e);
}
}
return corrected;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class LiferayMavenLegacyProjectUpdater method _getPluginsNode.
private Node _getPluginsNode(IDOMDocument document) {
NodeList buildList = document.getElementsByTagName("build");
if ((buildList != null) && (buildList.getLength() == 1)) {
IDOMElement buildNode = (IDOMElement) buildList.item(0);
NodeList pluginsList = buildNode.getElementsByTagName("plugins");
if ((pluginsList == null) || (pluginsList.getLength() != 1)) {
Element pluginsNode = document.createElement("plugins");
buildNode.appendChild(pluginsNode);
return pluginsNode;
} else {
return pluginsList.item(0);
}
} else {
Element buildNode = document.createElement("build");
Element pluginsNode = document.createElement("plugins");
buildNode.appendChild(pluginsNode);
Node node = document.getElementsByTagName("project").item(0);
node.appendChild(buildNode);
return pluginsNode;
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement in project liferay-ide by liferay.
the class LiferayMavenLegacyProjectUpdater method upgradePomFile.
@Override
public void upgradePomFile(IProject project, File outputFile) {
IFile pomFile = project.getFile("pom.xml");
IFile tempPomFile = project.getFile(".pom-tmp.xml");
boolean needUpgrade = isNeedUpgrade(pomFile);
if ((outputFile == null) && !needUpgrade) {
return;
}
IDOMModel domModel = null;
try {
if (outputFile != null) {
pomFile.copy(tempPomFile.getFullPath(), true, null);
pomFile = tempPomFile;
}
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(pomFile);
if (needUpgrade) {
IDOMDocument document = domModel.getDocument();
domModel.aboutToChangeModel();
NodeList elements = document.getElementsByTagName("artifactId");
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();
if (textContent.equals("liferay-maven-plugin")) {
IDOMElement liferayMavenPluginNode = (IDOMElement) element.getParentNode();
_removeChildren(liferayMavenPluginNode);
IDOMElement pluginsNode = (IDOMElement) liferayMavenPluginNode.getParentNode();
pluginsNode.removeChild(liferayMavenPluginNode);
} else if (textContent.equals("portal-service") || textContent.equals("util-java") || textContent.equals("util-bridges") || textContent.equals("util-taglib") || textContent.equals("util-slf4j")) {
IDOMElement dependencyElement = (IDOMElement) element.getParentNode();
String[] fixArtifactIdandVersion = _getFixedArtifactIdAndVersion(textContent);
_removeChildren(element);
Text artifactIdTextContent = element.getOwnerDocument().createTextNode(fixArtifactIdandVersion[0]);
element.appendChild(artifactIdTextContent);
NodeList versionList = dependencyElement.getElementsByTagName("version");
if ((versionList != null) && (versionList.getLength() == 1)) {
IDOMElement versionElement = (IDOMElement) versionList.item(0);
_removeChildren(versionElement);
Text versionTextContent = element.getOwnerDocument().createTextNode(fixArtifactIdandVersion[1]);
versionElement.appendChild(versionTextContent);
}
}
}
}
}
if (_isProtletProject(project)) {
_addCssBuilderPlugin(_getPluginsNode(document));
}
if (_isServiceBuilderProject(project)) {
_addServiceBuilderPlugin(_getPluginsNode(document), project.getName());
_addDependency(_getDependenciesNode(document), "biz.aQute.bnd", "biz.aQute.bnd.annotation", "3.2.0", "provided");
}
if (_isServiceBuildersubProject(project)) {
_addDependency(_getDependenciesNode(document), "biz.aQute.bnd", "biz.aQute.bnd.annotation", "3.2.0", "provided");
}
if (_isThemeProject(project)) {
_addProperties(_getPropertiesNode(document));
_addMavenThemePlugins(_getPluginsNode(document));
}
_cleanBuildNode(document);
domModel.changedModel();
}
if (FileUtil.exists(tempPomFile)) {
tempPomFile.delete(true, null);
}
if (outputFile != null) {
try (OutputStream fos = Files.newOutputStream(outputFile.toPath())) {
domModel.save(fos);
} catch (Exception e) {
}
} else {
domModel.save();
}
} catch (Exception e) {
LiferayMavenCore.logError("update pom file error", e);
} finally {
if (domModel != null) {
domModel.releaseFromRead();
}
}
}
Aggregations