Esempio n. 1
0
  private void bindContext(Context context, List<ConfigInput> inputs) {
    final XmlUtil xmlUtil = new XmlUtil();
    Document document = null;
    for (ConfigInput input : inputs) {
      try {
        if (input.getSource() != null) {
          if (input.getSource().startsWith("file:")) {
            File file = new File(input.getSource().replaceFirst("file:", ""));
            document = xmlUtil.getDocument(file);
          } else if (input.getSource().startsWith("http://")) {
            IOUtil ioUtil = new IOUtil();
            InputStream inputStream = ioUtil.getContent(input.getSource());
            document = xmlUtil.getDocument(inputStream);
          } else if (input.getSource().startsWith("classpath:")) {
            URL url =
                this.getClass()
                    .getClassLoader()
                    .getResource(input.getSource().replaceFirst("classpath:", ""));
            File file = new File(url.getPath());
            document = xmlUtil.getDocument(file);
          }
        }

        if (document != null) {
          context.put(input.getId(), new XmlTool(document.getFirstChild()));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Esempio n. 2
0
  /**
   * @param configuration
   * @throws FileNotFoundException
   */
  public void generate(final Configuration configuration) {

    IOUtil ioUtil = new IOUtil();

    for (ConfigOutput configOutput : configuration.getOutputs()) {

      Writer writer = null;
      try {
        writer = this.generate(configOutput, configuration);
      } catch (Exception e) {
        e.printStackTrace();
        continue;
      }

      // TODO tratar o getFilenamePattern quando é "pattern"
      File outputFile =
          new File(configuration.getOutputBaseDir() + configOutput.getFilenamePattern());
      // grava no file system
      try {
        ioUtil.writeTo(outputFile, new StringReader(writer.toString()), "UTF-8");
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }