Ejemplo n.º 1
0
  public void addTozip(ContentItem inContent, String inName, ZipOutputStream finalZip)
      throws IOException {
    InputStream is = inContent.getInputStream();
    if (is == null) {
      log.error("Couldn't add file to zip: " + inContent.getAbsolutePath());
      return;
    }
    ZipEntry entry = null;
    if (getFolderToStripOnZip() != null) {
      if (inName.contains(getFolderToStripOnZip())) {
        String stripped = inName.substring(getFolderToStripOnZip().length(), inName.length());
        entry = new ZipEntry(stripped);
      } else {
        entry = new ZipEntry(inName);
      }

    } else {

      entry = new ZipEntry(inName);
    }
    entry.setSize(inContent.getLength());
    entry.setTime(inContent.lastModified().getTime());

    finalZip.putNextEntry(entry);
    try {
      new OutputFiller().fill(is, finalZip);
    } finally {
      is.close();
    }
    finalZip.closeEntry();
  }
Ejemplo n.º 2
0
  protected XmlFile load(String inId, String path, String inElementName, ContentItem input)
      throws OpenEditException {
    // log.info("Loading " + path);
    boolean found = false;

    XmlFile element;
    Element root = null;
    if (!input.exists()) {
      if (inElementName == null) {
        root = DocumentHelper.createElement("root");
      } else {
        if (inElementName.endsWith("y")) {
          root =
              DocumentHelper.createElement(
                  inElementName.substring(0, inElementName.length() - 1) + "ies");
        } else {
          root = DocumentHelper.createElement(inElementName + "s");
        }
      }
    } else {
      found = true;
      InputStream in = input.getInputStream();
      try {
        root = getXmlUtil().getXml(in, "UTF-8");
      } catch (OpenEditException ex) {
        log.error("file problem: " + path, ex);
        throw ex;
      } finally {
        FileUtils.safeClose(in);
      }
    }
    element = new XmlFile();
    element.setRoot(root);
    element.setExist(found);
    element.setElementName(inElementName);
    element.setPath(path);
    element.setLastModified(input.lastModified().getTime());
    element.setId(inId);

    return element;
  }