Search in sources :

Example 26 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.

the class ServiceBuilderDescriptorHelper method addDefaultEntity.

public IStatus addDefaultEntity() {
    IStatus status = Status.OK_STATUS;
    IFile descriptorFile = getDescriptorFile();
    if (descriptorFile != null) {
        DOMModelEditOperation editOperation = new DOMModelEditOperation(descriptorFile) {

            @Override
            protected IStatus doExecute(IDOMDocument document) {
                return doAddDefaultEntity(document);
            }
        };
        status = editOperation.execute();
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 27 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument in project liferay-ide by liferay.

the class ServiceBuilderDescriptorHelper method removeAllEntities.

public IStatus removeAllEntities() {
    IFile descriptorFile = getDescriptorFile();
    if (FileUtil.notExists(descriptorFile)) {
        return Status.OK_STATUS;
    }
    String tagName = "entity";
    DOMModelEditOperation editOperation = new DOMModelEditOperation(descriptorFile) {

        @Override
        protected IStatus doExecute(IDOMDocument document) {
            return removeAllElements(document, tagName);
        }
    };
    return editOperation.execute();
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Example 28 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 29 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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 30 with IDOMDocument

use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument 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

IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)176 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)109 IFile (org.eclipse.core.resources.IFile)48 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)39 Element (org.w3c.dom.Element)39 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)33 NodeList (org.w3c.dom.NodeList)27 IStatus (org.eclipse.core.runtime.IStatus)23 Node (org.w3c.dom.Node)21 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)14 IJsTranslation (org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation)14 JsTranslationAdapter (org.eclipse.wst.jsdt.web.core.javascript.JsTranslationAdapter)14 Document (org.w3c.dom.Document)14 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)12 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)12 IOException (java.io.IOException)11 CMDocument (org.eclipse.wst.xml.core.internal.contentmodel.CMDocument)11 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)10 IModelManager (org.eclipse.wst.sse.core.internal.provisional.IModelManager)9