Example #1
0
  protected Document loadConfiguration(String configLocation) {
    logger.debug("[IMPORT] loading " + configLocation);
    InputStream in = null;
    try {
      in = new FileInputStream(configLocation);
      if (in != null) {
        return ContentUtils.convertStreamToXml(in);
      }
    } catch (FileNotFoundException e) {
      logger.error("[IMPORT] failed to load configuration.", e);

    } catch (DocumentException e) {
      logger.error("[IMPORT] failed to load configuration.", e);

    } finally {
      ContentUtils.release(in);
    }
    return null;
  }
Example #2
0
  /**
   * write content
   *
   * @param site
   * @param importedPaths
   * @param importedFullPaths
   * @param fileRoot
   * @param parentPath
   * @param name
   * @param overWrite
   */
  protected void writeContent(
      String site,
      Set<String> importedPaths,
      List<String> importedFullPaths,
      String fileRoot,
      String targetRoot,
      String parentPath,
      String name,
      boolean overWrite) {
    boolean isXml = true;
    String processChain = this.xmlChainName;
    if (!name.endsWith(".xml")) {
      isXml = false;
      processChain = this.assetChainName;
    }
    InputStream in = null;
    String filePath = parentPath + "/" + name;
    String fileSystemPath = fileRoot + "/" + name;
    logger.info(
        "[IMPORT] writeContent: fileRoot ["
            + fileRoot
            + "] fullPath ["
            + filePath
            + "] overwrite["
            + overWrite
            + "] process chain [ "
            + processChain
            + "]");
    long startTimeWrite = System.currentTimeMillis();
    logger.debug("[IMPORT] writing file: " + parentPath + "/" + name);

    try {
      File file = new File(fileSystemPath);
      if (file.exists()) {
        in = new FileInputStream(file);
        String currentPath = parentPath + "/" + name;
        boolean contentExists = contentService.contentExists(site, currentPath);
        // create parameters
        Map<String, String> params = createParams(site, isXml, targetRoot, parentPath, name);
        String id = site + ":" + filePath + ":" + name;
        // write content only it is new or overwrite is set to true for
        // existing
        if (!contentExists || overWrite) {
          String fullPath = targetRoot + filePath;
          objectStateService.setSystemProcessing(site, currentPath, true);
          // write the content
          contentService.processContent(id, in, isXml, params, processChain);
          ContentItemTO item = contentService.getContentItem(site, currentPath);
          // update state
          if (item != null) {
            objectStateService.transition(site, item, TransitionEvent.SAVE);
            objectStateService.setSystemProcessing(site, currentPath, false);
          } else {
            ObjectState state = objectStateService.getObjectState(site, currentPath);
            if (state == null) {
              objectStateService.insertNewEntry(site, currentPath);
            }
          }

          importedPaths.add(filePath);
          importedFullPaths.add(fullPath);
        } else {
          logger.debug(
              "[IMPORT] " + filePath + " exists and set to not to overrwite. skipping this file.");
        }
      }
    } catch (FileNotFoundException e) {
      logger.warn("[IMPORT] " + filePath + " does not exist.");

    } catch (ServiceException e) {
      logger.error("[IMPORT] failed to import " + filePath, e);
    } finally {
      ContentUtils.release(in);
    }
    logger.debug(
        "[IMPORT] done writing file: "
            + parentPath
            + "/"
            + name
            + ", time: "
            + (System.currentTimeMillis() - startTimeWrite));
  }