Ejemplo n.º 1
0
  public String exportAllData() {

    Identity.setSecurityEnabled(false);

    Collection<ContentItem> items = getContentItemService().getContentItems();

    File f = new File(pathToExportFile);
    OutputStream out = null;
    try {
      out = FileUtils.openOutputStream(f);
      exporter.exportItems(items, "application/x-kiwi", out);
    } catch (IOException ex) {
      log.error("Error by creating zip file #0", ex.getMessage());
    } finally {
      try {
        out.close();
      } catch (IOException ex) {
        log.error("Error by close outputstream #0", ex.getMessage());
      }
    }

    log.info("Create export file #0", f.getAbsolutePath());

    try {
      InputStream newIs = new FileInputStream(f);
      byte[] baBinary = new byte[newIs.available()];
      newIs.read(baBinary);

      HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();

      String contentType = "application/zip";
      String fileName = "export.kiwi";

      response.setContentType(contentType);
      response.addHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");

      ServletOutputStream os = response.getOutputStream();
      os.write(baBinary);
      os.flush();
      os.close();
      facesContext.responseComplete();
    } catch (Exception ex) {
      log.error("Error by downloading file #0", ex.getMessage());
    } finally {
      try {
        out.close();
      } catch (IOException ex) {
        log.error("Error by close outputstream #0", ex.getMessage());
      }
    }

    return null;
  }
Ejemplo n.º 2
0
  /**
   * Import data from the reader provided as argument into the KiWi database.
   *
   * @param reader the reader from which to read the data
   * @param types the set of types to associate with each generated content item
   * @param tags the set of content items to use as tags
   * @param user the user to use as author of all imported data
   */
  @Override
  public int importData(
      Reader reader,
      String format,
      final Set<KiWiUriResource> types,
      final Set<ContentItem> tags,
      final User user,
      final Collection<ContentItem> output) {
    SyndFeedInput input = new SyndFeedInput();

    int count = 0;
    try {
      final SyndFeed feed = input.build(reader);

      Identity.setSecurityEnabled(false);
      count = importData(feed, types, tags, user, output);

    } catch (FeedException ex) {
      log.error("RSS/Atom feed could not be parsed", ex);
    }
    return count;
  }
Ejemplo n.º 3
0
 @BeforeClass
 void beforeClass() {
   Identity.setSecurityEnabled(false);
 }