Пример #1
0
 /**
  * Write an XML serialized XWikiDocument to a ZipOutputStream
  *
  * @param doc the document to serialize
  * @param zos the ZipOutputStream to write to
  * @param withVersions if true, also serialize all document versions
  * @param context current XWikiContext
  * @throws XWikiException when an error occurs during documents access
  * @throws IOException when an error occurs during streaming operation
  * @since 4.1M2
  */
 private void addToZip(
     XWikiDocument doc, ZipArchiveOutputStream zos, boolean withVersions, XWikiContext context)
     throws XWikiException, IOException {
   String zipname = getPathFromDocument(doc, context);
   ZipArchiveEntry zipentry = new ZipArchiveEntry(zipname);
   zos.putArchiveEntry(zipentry);
   doc.toXML(zos, true, false, true, withVersions, context);
   zos.closeArchiveEntry();
 }
Пример #2
0
  public void addToDir(XWikiDocument doc, File dir, boolean withVersions, XWikiContext context)
      throws XWikiException {
    try {
      filter(doc, context);
      File spacedir = new File(dir, getDirectoryForDocument(doc));
      if (!spacedir.exists()) {
        if (!spacedir.mkdirs()) {
          Object[] args = new Object[1];
          args[0] = dir.toString();
          throw new XWikiException(
              XWikiException.MODULE_XWIKI,
              XWikiException.ERROR_XWIKI_MKDIR,
              "Error creating directory {0}",
              null,
              args);
        }
      }
      String filename = getFileNameFromDocument(doc, context);
      File file = new File(spacedir, filename);
      FileOutputStream fos = new FileOutputStream(file);
      doc.toXML(fos, true, false, true, withVersions, context);
      fos.flush();
      fos.close();
    } catch (ExcludeDocumentException e) {
      LOGGER.info("Skip the document " + doc.getDocumentReference());
    } catch (Exception e) {
      Object[] args = new Object[1];
      args[0] = doc.getDocumentReference();

      throw new XWikiException(
          XWikiException.MODULE_XWIKI_DOC,
          XWikiException.ERROR_XWIKI_DOC_EXPORT,
          "Error creating file {0}",
          e,
          args);
    }
  }