/** * wchen Comment method "updateParameters". * * @param node * @param attrMap * @param statAndLogs */ private void updateParameters(final Node node, final NamedNodeMap attrMap, List statAndLogs) { boolean added = false; for (Object obj : statAndLogs) { ElementParameterType type = (ElementParameterType) obj; if (type.getName().equals(attrMap.getNamedItem("name").getTextContent())) { // $NON-NLS-1$ type.setValue(node.getTextContent()); added = true; } } // if there is no such parameter in current settings add one TalendFileFactory talendF = TalendFileFactory.eINSTANCE; if (added == false) { ElementParameterType type = talendF.createElementParameterType(); type.setName(attrMap.getNamedItem("name").getTextContent()); // $NON-NLS-1$ type.setValue(node.getTextContent()); statAndLogs.add(type); } }
/** * load project settings to no-opened process * * @param elemParam * @param projectPaType */ public static void loadElementParameters( ParametersType processType, ParametersType projectPaType, EParameterName paramName) { EList listParamType = projectPaType.getElementParameter(); for (int j = 0; j < listParamType.size(); j++) { ElementParameterType pType = (ElementParameterType) listParamType.get(j); EList processParameters = processType.getElementParameter(); ElementParameterType processParam = null; for (int i = 0; i < processParameters.size(); i++) { ElementParameterType paramType = (ElementParameterType) processParameters.get(i); if (paramType.getName().equals(pType.getName()) && paramType.getField() != null && paramType.getField().equals(pType.getField())) { processParam = paramType; } else if (pType.getName().contains(":")) { StringTokenizer token = new StringTokenizer(pType.getName(), ":"); // $NON-NLS-1$ String parentId = token.nextToken(); String childId = token.nextToken(); String[] split = paramType.getName().split(":"); if (split.length != 2) { continue; } String complexName = paramName + ":" + childId; if (complexName.equals(paramType.getName())) { processParam = paramType; } } if (processParam != null) { break; } } if (processParam != null) { processParam.setValue(pType.getValue()); } else { TalendFileFactory fileFact = TalendFileFactory.eINSTANCE; ElementParameterType processTypes = fileFact.createElementParameterType(); processTypes.setName(pType.getName()); processTypes.setField(pType.getField()); processTypes.setValue(pType.getValue()); processType.getElementParameter().add(processTypes); } } }
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() { public void error(final SAXParseException exception) throws SAXException { throw exception; } public void fatalError(final SAXParseException exception) throws SAXException { throw exception; } public void warning(final SAXParseException exception) throws SAXException { throw exception; } }); final Document document = analyseur.parse(file); final NodeList nodes = document.getElementsByTagName("exportParameter"); // $NON-NLS-1$ 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(); final Node typeAttr = attrMap.getNamedItem("type"); // $NON-NLS-1$ if ("technicalStatus".equals(typeAttr.getTextContent())) { // $NON-NLS-1$ updateStatus(node, attrMap, technical, "technicalStatus"); // $NON-NLS-1$ } else if ("documentationStatus".equals(typeAttr.getTextContent())) { // $NON-NLS-1$ updateStatus(node, attrMap, documentation, "documentationStatus"); // $NON-NLS-1$ } 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; String name = attrMap.getNamedItem("name").getTextContent(); // $NON-NLS-1$ final Node familyAttr = attrMap.getNamedItem("family"); // $NON-NLS-1$ 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); }