コード例 #1
0
  /**
   * Persist the given Component or Page model by serializing it to JSON and writing it to the file
   * system
   *
   * @param model ComponentMeta or PageMeta to persist
   * @return ComponentMeta or PageMeta the persisted model
   */
  @Override
  public <T extends ItemMeta> T update(T model) {
    log.debug("Update model {}", model);

    TcmUri tcmUri = model.getTcmUri();
    String path = pathMapper.getModelAbsolutePath(tcmUri);
    File file = new File(path);

    if (!file.exists()) {
      File directory = file.getParentFile();
      if (!directory.exists()) {
        if (!directory.mkdirs()) {
          log.error("Directory {} was not created", directory);
        }
      }
    }

    serializer.serialize(file, model);
    log.debug("Done update model {} to file {}", tcmUri, file);

    return model;
  }