use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project liferay-ide by liferay.
the class NewLiferayProfileMarkerResolution method promptUser.
@Override
protected int promptUser(IProject project, NewLiferayPluginProjectOp op) {
NewLiferayProfile newLiferayProfile = op.getNewLiferayProfiles().insert();
Reference<DialogDef> dialogRef = DefinitionLoader.sdef(NewLiferayPluginProjectWizard.class).dialog("NewLiferayProfile");
SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), newLiferayProfile, dialogRef);
dialog.setBlockOnOpen(true);
int result = dialog.open();
if (result == SapphireDialog.OK) {
IDOMModel domModel = null;
try {
IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME);
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(pomFile);
MavenUtil.createNewLiferayProfileNode(domModel.getDocument(), newLiferayProfile);
domModel.save();
} catch (Exception e) {
LiferayMavenCore.logError("Unable to save new Liferay profiles to project pom.", e);
} finally {
if (domModel != null) {
domModel.releaseFromEdit();
}
}
NewLiferayProfileActionHandler.addToActiveProfiles(op, newLiferayProfile);
} else {
op.getNewLiferayProfiles().remove(newLiferayProfile);
}
return result;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project liferay-ide by liferay.
the class UITestsUtils method getElementContentEndOffset.
public static int getElementContentEndOffset(IFile file, String elementName) throws Exception {
final IDOMModel model = getDOMModel(file, false);
final Node element = model.getDocument().getElementsByTagName(elementName).item(0);
final IRegion region = getRegion(element.getFirstChild());
int retval = region.getOffset() + region.getLength() - 1;
model.releaseFromRead();
return retval;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel 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.IDOMModel in project liferay-ide by liferay.
the class LiferayMavenProjectProvider method updateDtdVersion.
protected void updateDtdVersion(IProject project, String dtdVersion, String archetypeVesion) {
String tmpPublicId = dtdVersion;
String tmpSystemId = dtdVersion.replaceAll("\\.", "_");
IStructuredModel editModel = null;
IFile[] metaFiles = _getLiferayMetaFiles(project);
for (IFile file : metaFiles) {
try {
editModel = StructuredModelManager.getModelManager().getModelForEdit(file);
if ((editModel != null) && editModel instanceof IDOMModel) {
IDOMDocument xmlDocument = ((IDOMModel) editModel).getDocument();
DocumentTypeImpl docType = (DocumentTypeImpl) xmlDocument.getDoctype();
String publicId = docType.getPublicId();
String newPublicId = _getNewDoctTypeSetting(publicId, tmpPublicId, _publicid_pattern);
if (newPublicId != null) {
docType.setPublicId(newPublicId);
}
String systemId = docType.getSystemId();
String newSystemId = _getNewDoctTypeSetting(systemId, tmpSystemId, _systemid_pattern);
if (newSystemId != null) {
docType.setSystemId(newSystemId);
}
editModel.save();
}
} catch (Exception e) {
IStatus error = ProjectCore.createErrorStatus("Unable to upgrade deployment meta file for " + file.getName(), e);
ProjectCore.logError(error);
} finally {
if (editModel != null) {
editModel.releaseFromEdit();
}
}
}
ProjectCore.operate(project, UpdateDescriptorVersionOperation.class, archetypeVesion, dtdVersion);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project liferay-ide by liferay.
the class DescriptorsPage method doUpgrade.
@Override
protected void doUpgrade(IFile srcFile, IProject project) {
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(srcFile);
domModel.aboutToChangeModel();
IDOMDocument document = domModel.getDocument();
DocumentTypeImpl docType = (DocumentTypeImpl) document.getDoctype();
if (docType != null) {
final String publicId = docType.getPublicId();
final String newPublicId = _getNewDoctTypeSetting(publicId, "7.0.0", _publicidRegrex);
docType.setPublicId(newPublicId);
final String systemId = docType.getSystemId();
final String newSystemId = _getNewDoctTypeSetting(systemId, "7_0_0", _systemidRegrex);
docType.setSystemId(newSystemId);
}
_removeLayoutWapNode(srcFile, document);
domModel.save();
} catch (Exception e) {
ProjectUI.logError(e);
}
}
Aggregations