/**
   * store loaded data to xml file
   *
   * @throws SearchException
   */
  protected final synchronized void store() throws SearchException {
    // Collection.Key[] keys=collections.keys();
    Iterator<Key> it = collections.keyIterator();
    Key k;
    while (it.hasNext()) {
      k = it.next();
      Element collEl = getCollectionElement(k.getString());
      SearchCollection sc = getCollectionByName(k.getString());
      setAttributes(collEl, sc);
    }

    OutputFormat format = new OutputFormat(doc, null, true);
    format.setLineSeparator("\r\n");
    format.setLineWidth(72);
    OutputStream os = null;
    try {
      XMLSerializer serializer =
          new XMLSerializer(
              os = engine.getIOUtil().toBufferedOutputStream(searchFile.getOutputStream()), format);
      serializer.serialize(doc.getDocumentElement());
    } catch (IOException e) {
      throw new SearchException(e);
    } finally {
      engine.getIOUtil().closeSilent(os);
    }
  }
Esempio n. 2
0
  /**
   * gets a file from server and copy it local
   *
   * @return FTPCLient
   * @throws PageException
   * @throws IOException
   */
  private AFTPClient actionGetFile() throws PageException, IOException {
    required("remotefile", remotefile);
    required("localfile", localfile);

    AFTPClient client = getClient();
    Resource local =
        ResourceUtil.toResourceExistingParent(pageContext, localfile); // new File(localfile);
    pageContext.getConfig().getSecurityManager().checkFileLocation(local);
    if (failifexists && local.exists())
      throw new ApplicationException(
          "File ["
              + local
              + "] already exist, if you want to overwrite, set attribute failIfExists to false");
    OutputStream fos = null;
    client.setFileType(getType(local));
    boolean success = false;
    try {
      fos = IOUtil.toBufferedOutputStream(local.getOutputStream());
      success = client.retrieveFile(remotefile, fos);
    } finally {
      IOUtil.closeEL(fos);
      if (!success) local.delete();
    }
    writeCfftp(client);

    return client;
  }