Search in sources :

Example 11 with IDOMModel

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;
}
Also used : DialogDef(org.eclipse.sapphire.ui.forms.DialogDef) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NewLiferayProfile(com.liferay.ide.project.core.model.NewLiferayProfile) NewLiferayPluginProjectWizard(com.liferay.ide.project.ui.wizard.NewLiferayPluginProjectWizard) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog)

Example 12 with IDOMModel

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;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) Node(org.w3c.dom.Node) IRegion(org.eclipse.jface.text.IRegion)

Example 13 with IDOMModel

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;
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement) XmlPullParserException(org.codehaus.plexus.util.xml.pull.XmlPullParserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 14 with IDOMModel

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);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DocumentTypeImpl(org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) CoreException(org.eclipse.core.runtime.CoreException) VersionRangeResolutionException(org.eclipse.aether.resolution.VersionRangeResolutionException)

Example 15 with IDOMModel

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);
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) DocumentTypeImpl(org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)433 Document (org.w3c.dom.Document)123 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)120 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)110 Element (org.w3c.dom.Element)109 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)103 Node (org.w3c.dom.Node)57 IFile (org.eclipse.core.resources.IFile)56 NodeList (org.w3c.dom.NodeList)47 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)45 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)44 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)41 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)41 Text (org.w3c.dom.Text)39 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)35 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)28 IOException (java.io.IOException)26 CoreException (org.eclipse.core.runtime.CoreException)26 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)26 INodeAdapter (org.eclipse.wst.sse.core.internal.provisional.INodeAdapter)25