Search in sources :

Example 1 with DocumentTypeImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl 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 2 with DocumentTypeImpl

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

Example 3 with DocumentTypeImpl

use of org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl in project webtools.sourceediting by eclipse.

the class EMF2DOMSSERenderer method replaceDocumentType.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jem.internal.util.emf.xml.EMF2DOMRenderer#replaceDocumentType(java.lang.String,
	 *      java.lang.String, java.lang.String)
	 */
public void replaceDocumentType(String docTypeName, String publicId, String systemId) {
    if (document == null)
        return;
    DocumentTypeImpl docType = (DocumentTypeImpl) document.getDoctype();
    if (docType == null)
        return;
    if (publicId == null && systemId == null)
        document.removeChild(docType);
    else {
        docType.setPublicId(publicId);
        docType.setSystemId(systemId);
    }
}
Also used : DocumentTypeImpl(org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl)

Example 4 with DocumentTypeImpl

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

the class UpgradeMetadataHandler method execute.

@Override
public Status execute(IProject project, String runtimeName, IProgressMonitor monitor, int perUnit) {
    Status retval = Status.createOkStatus();
    try {
        int worked = 0;
        IProgressMonitor submon = CoreUtil.newSubMonitor(monitor, 25);
        submon.subTask("Prograde Upgrade Update DTD Header");
        IFile[] metaFiles = _getUpgradeDTDFiles(project);
        for (IFile file : metaFiles) {
            IStructuredModel editModel = StructuredModelManager.getModelManager().getModelForEdit(file);
            try {
                if ((editModel != null) && (editModel instanceof IDOMModel)) {
                    worked = worked + perUnit;
                    submon.worked(worked);
                    IDOMDocument xmlDocument = ((IDOMModel) editModel).getDocument();
                    DocumentTypeImpl docType = (DocumentTypeImpl) xmlDocument.getDoctype();
                    String publicId = docType.getPublicId();
                    String newPublicId = _getNewDoctTypeSetting(publicId, "6.2.0", _publicid_regrex);
                    if (newPublicId != null) {
                        docType.setPublicId(newPublicId);
                    }
                    worked = worked + perUnit;
                    submon.worked(worked);
                    String systemId = docType.getSystemId();
                    String newSystemId = _getNewDoctTypeSetting(systemId, "6_2_0", _systemid_regrex);
                    if (newSystemId != null) {
                        docType.setSystemId(newSystemId);
                    }
                    editModel.save();
                    worked = worked + perUnit;
                    submon.worked(worked);
                } else {
                    _updateProperties(file, "liferay-versions", "6.2.0+");
                }
            } finally {
                editModel.releaseFromEdit();
            }
        }
    } catch (Exception e) {
        IStatus error = ProjectCore.createErrorStatus("Unable to upgrade deployment meta file for " + project.getName(), e);
        ProjectCore.logError(error);
        retval = StatusBridge.create(error);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) 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)

Example 5 with DocumentTypeImpl

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

the class DescriptorsPage method createTempFile.

@Override
protected void createTempFile(IFile srcFile, File templateFile, String projectName) {
    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);
        OutputStream tmpOutputStream = Files.newOutputStream(templateFile.toPath(), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE_NEW);
        domModel.save(tmpOutputStream);
    } catch (Exception e) {
        ProjectCore.logError(e);
    } finally {
        domModel.releaseFromEdit();
    }
}
Also used : IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OutputStream(java.io.OutputStream) DocumentTypeImpl(org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)

Aggregations

DocumentTypeImpl (org.eclipse.wst.xml.core.internal.document.DocumentTypeImpl)5 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)4 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)4 IFile (org.eclipse.core.resources.IFile)2 IStatus (org.eclipse.core.runtime.IStatus)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 OutputStream (java.io.OutputStream)1 VersionRangeResolutionException (org.eclipse.aether.resolution.VersionRangeResolutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Status (org.eclipse.sapphire.modeling.Status)1