Search in sources :

Example 11 with StatAndLogsSettings

use of org.talend.core.model.properties.StatAndLogsSettings in project tdi-studio-se by Talend.

the class ImportProjectSettings method updateProjectSettings.

public void updateProjectSettings() throws ParserConfigurationException, SAXException, IOException {
    if (this.path == null) {
        return;
    }
    File file = new File(path);
    org.talend.core.model.properties.Project project = pro.getEmfProject();
    final DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();
    DocumentBuilder analyseur = fabrique.newDocumentBuilder();
    analyseur.setErrorHandler(new ErrorHandler() {

        @Override
        public void error(final SAXParseException exception) throws SAXException {
            throw exception;
        }

        @Override
        public void fatalError(final SAXParseException exception) throws SAXException {
            throw exception;
        }

        @Override
        public void warning(final SAXParseException exception) throws SAXException {
            throw exception;
        }
    });
    final Document document = analyseur.parse(file);
    // PTODO, if need, get the version from the imported file.
    // NodeList exportParametersNodes = document.getElementsByTagName("exportParameters");
    // String importStudioVersion=null;
    //$NON-NLS-1$
    final NodeList nodes = document.getElementsByTagName("exportParameter");
    List addedComponentSetting = new ArrayList();
    List technical = project.getTechnicalStatus();
    List documentation = project.getDocumentationStatus();
    technical.clear();
    documentation.clear();
    for (int i = 0; i < nodes.getLength(); i++) {
        final Node node = nodes.item(i);
        final NamedNodeMap attrMap = node.getAttributes();
        //$NON-NLS-1$
        final Node typeAttr = attrMap.getNamedItem("type");
        if ("technicalStatus".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            updateStatus(node, attrMap, technical, "technicalStatus");
        } else if ("documentationStatus".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            updateStatus(node, attrMap, documentation, "documentationStatus");
        } else if ("security".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            project.isHidePassword();
            project.setHidePassword(Boolean.valueOf(node.getTextContent()));
        } else if ("statAndLogs".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            if (project.getStatAndLogsSettings() == null) {
                TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
                StatAndLogsSettings stats = PropertiesFactory.eINSTANCE.createStatAndLogsSettings();
                project.setStatAndLogsSettings(stats);
                stats.setParameters(talendF.createParametersType());
            }
            List statAndLogs = project.getStatAndLogsSettings().getParameters().getElementParameter();
            updateParameters(node, attrMap, statAndLogs);
        } else if ("implicitContext".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            if (project.getImplicitContextSettings() == null) {
                TalendFileFactory talendF = TalendFileFactory.eINSTANCE;
                ImplicitContextSettings implicit = PropertiesFactory.eINSTANCE.createImplicitContextSettings();
                project.setImplicitContextSettings(implicit);
                implicit.setParameters(talendF.createParametersType());
            }
            List implicitContexts = project.getImplicitContextSettings().getParameters().getElementParameter();
            updateParameters(node, attrMap, implicitContexts);
        } else if ("palette".equals(typeAttr.getTextContent())) {
            //$NON-NLS-1$
            List componentSettings = project.getComponentsSettings();
            boolean existed = false;
            //$NON-NLS-1$
            String name = attrMap.getNamedItem("name").getTextContent();
            //$NON-NLS-1$
            final Node familyAttr = attrMap.getNamedItem("family");
            Boolean hide = Boolean.valueOf(node.getTextContent());
            for (Object obj : componentSettings) {
                ComponentSetting setting = (ComponentSetting) obj;
                if (setting.getName().equals(name)) {
                    if (familyAttr != null && familyAttr.getTextContent().equals(setting.getFamily())) {
                        existed = true;
                        setting.setHidden(hide);
                    }
                }
            }
            if (!existed && familyAttr != null) {
                ComponentSetting setting = PropertiesFactory.eINSTANCE.createComponentSetting();
                setting.setFamily(familyAttr.getTextContent());
                setting.setName(name);
                setting.setHidden(hide);
                addedComponentSetting.add(setting);
            }
        }
    }
    project.getComponentsSettings().addAll(addedComponentSetting);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory) SAXParseException(org.xml.sax.SAXParseException) StatAndLogsSettings(org.talend.core.model.properties.StatAndLogsSettings) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) ErrorHandler(org.xml.sax.ErrorHandler) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) ComponentSetting(org.talend.core.model.properties.ComponentSetting) ImplicitContextSettings(org.talend.core.model.properties.ImplicitContextSettings) DocumentBuilder(javax.xml.parsers.DocumentBuilder) File(java.io.File)

Aggregations

StatAndLogsSettings (org.talend.core.model.properties.StatAndLogsSettings)11 ImplicitContextSettings (org.talend.core.model.properties.ImplicitContextSettings)9 List (java.util.List)6 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)6 PersistenceException (org.talend.commons.exception.PersistenceException)5 ElementParameterTypeImpl (org.talend.designer.core.model.utils.emf.talendfile.impl.ElementParameterTypeImpl)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)4 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)2 TalendFileFactory (org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 EList (org.eclipse.emf.common.util.EList)1 Element (org.talend.core.model.process.Element)1 IElement (org.talend.core.model.process.IElement)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 ComponentSetting (org.talend.core.model.properties.ComponentSetting)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1