Exemplo n.º 1
0
  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);
  }