Esempio n. 1
0
  private boolean closeFile() {
    boolean retval = false;
    if (data.OpenedNewFile) {
      try {
        // Close the parent element
        data.writer.write(
            ("</" + meta.getMainElement() + ">" + Const.CR)
                .toCharArray()); //$NON-NLS-1$ //$NON-NLS-2$

        if (meta.isZipped()) {
          // System.out.println("close zip entry ");
          data.zip.closeEntry();
          // System.out.println("finish file...");
          data.zip.finish();
          data.zip.close();
        } else {
          data.writer.close();
        }

        // System.out.println("Closed file...");

        retval = true;
      } catch (Exception e) {
      }
    }
    return retval;
  }
Esempio n. 2
0
  public boolean openNewFile() {
    boolean retval = false;
    data.writer = null;

    try {

      FileObject file = KettleVFS.getFileObject(buildFilename(true), getTransMeta());

      if (meta.isAddToResultFiles()) {
        // Add this to the result file names...
        ResultFile resultFile =
            new ResultFile(
                ResultFile.FILE_TYPE_GENERAL, file, getTransMeta().getName(), getStepname());
        resultFile.setComment("This file was created with a xml output step"); // $NON-NLS-1$
        addResultFile(resultFile);
      }

      OutputStream outputStream;
      if (meta.isZipped()) {
        OutputStream fos = KettleVFS.getOutputStream(file, false);
        data.zip = new ZipOutputStream(fos);
        File entry = new File(buildFilename(false));
        ZipEntry zipentry = new ZipEntry(entry.getName());
        zipentry.setComment("Compressed by Kettle"); // $NON-NLS-1$
        data.zip.putNextEntry(zipentry);
        outputStream = data.zip;
      } else {
        OutputStream fos = KettleVFS.getOutputStream(file, false);
        outputStream = fos;
      }
      if (meta.getEncoding() != null && meta.getEncoding().length() > 0) {
        logBasic("Opening output stream in encoding: " + meta.getEncoding()); // $NON-NLS-1$
        data.writer = new OutputStreamWriter(outputStream, meta.getEncoding());
        data.writer.write(XMLHandler.getXMLHeader(meta.getEncoding()).toCharArray());
      } else {
        logBasic(
            "Opening output stream in default encoding : " + Const.XML_ENCODING); // $NON-NLS-1$
        data.writer = new OutputStreamWriter(outputStream);
        data.writer.write(XMLHandler.getXMLHeader(Const.XML_ENCODING).toCharArray());
      }

      // Add the name space if defined
      StringBuffer nameSpace = new StringBuffer();
      if ((meta.getNameSpace() != null) && (!"".equals(meta.getNameSpace()))) { // $NON-NLS-1$
        nameSpace.append(" xmlns=\""); // $NON-NLS-1$
        nameSpace.append(meta.getNameSpace());
        nameSpace.append("\""); // $NON-NLS-1$
      }

      // OK, write the header & the parent element:
      data.writer.write(
          ("<" + meta.getMainElement() + nameSpace.toString() + ">" + Const.CR)
              .toCharArray()); //$NON-NLS-1$//$NON-NLS-2$

      retval = true;
    } catch (Exception e) {
      logError("Error opening new file : " + e.toString()); // $NON-NLS-1$
    }
    // System.out.println("end of newFile(), splitnr="+splitnr);

    data.splitnr++;

    return retval;
  }