Example #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();
  }
 /**
  * This only works if inSourcePath has an extension, i.e. newassets/admin/118/picture.jpg
  *
  * @param inSourcePath
  * @return
  */
 public String getDataAssetsPath(String inSourcePath) {
   String prefix = "/WEB-INF/data" + getMediaArchive().getCatalogHome() + "/originals/";
   String path = prefix + inSourcePath;
   Page page = getPageManager().getPage(path);
   ContentItem content = page.getContentItem();
   return content.getAbsolutePath();
 }
Example #3
0
 public long getLastModified(String inPath) throws OpenEditException {
   if (inPath.startsWith("/WEB-INF/data")) {
     ContentItem input = getPageManager().getRepository().get(inPath);
     return input.getLastModified();
   } else {
     return getPageManager().getPage(inPath).lastModified();
   }
 }
Example #4
0
    public boolean acceptFile(ContentItem inFileItem) {
      String openeditpath = inFileItem.getPath(); // .replace('\\', '/');
      // // Windows
      // replace
      if (inFileItem.isFolder() && !openeditpath.endsWith("/")) {
        openeditpath = openeditpath + "/"; // Make sure we leave the /
        // on there for directories
      }

      return isValidEntry(openeditpath);
    }
Example #5
0
    public void processFile(ContentItem inContent, User inUser) throws OpenEditException {
      String path = inContent.getPath();
      // if (inContent instanceof FileItem)
      // {
      // String abs = ((FileItem) inContent).getAbsolutePath();
      // if (getRoot() != null)
      // {
      // String root = getRoot().getAbsolutePath();
      // if (abs.contains(getRoot().getAbsolutePath()))
      // {
      // path = abs.substring(root.length());
      // }
      // }
      // }

      // The zip entry can't begin with any slashes
      while (path.startsWith("/")) {
        path = path.substring(1, path.length());
      }

      try {
        addTozip(inContent, path, zipOutputStream);
      } catch (Exception e) {
        if (e.getMessage().startsWith("duplicate")) {
          return;
        }
        throw new OpenEditException(e);
      }
    }
Example #6
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;
  }
Example #7
0
  public void saveXml(XmlFile inFile, User inUser, Lock lock) throws OpenEditException {

    // Lock lock = getLockManager().lock("system", inFile.getPath(), null ); //this will retry 10
    // times then timeout and throw an exception

    Page page = getPageManager().getPage(inFile.getPath(), false);

    ContentItem tmp = getPageManager().getRepository().getStub(inFile.getPath() + ".tmp.xml");
    tmp.setMakeVersion(false);
    getXmlUtil().saveXml(inFile.getRoot(), tmp.getOutputStream(), page.getCharacterEncoding());

    ContentItem xmlcontent = getPageManager().getRepository().getStub(inFile.getPath());
    xmlcontent.setMakeVersion(false);
    getPageManager()
        .getRepository()
        .remove(xmlcontent); // might be a little faster to remove it first
    getPageManager().getRepository().move(tmp, xmlcontent);
    getPageManager().firePageModified(page);

    xmlcontent = getPageManager().getRepository().getStub(inFile.getPath());
    inFile.setLastModified(xmlcontent.getLastModified());
    inFile.setExist(true);
    // log.info("Save " + inFile.getPath());

  }