Esempio n. 1
0
  // @Exposed(accessLevel = AccessLevel.PUBLIC, outputType = MimeType.PLAIN_TEXT)
  public boolean writeCdaFile(
      final OutputStream out,
      final String path,
      final String solution,
      final String file,
      final String data)
      throws Exception {
    // TODO: Validate the filename in some way, shape or form!
    IRepositoryAccess repository = CdaEngine.getEnvironment().getRepositoryAccess();
    // final ICommonParameterProvider requestParams = requParam;
    // Check if the file exists and we have permissions to write to it
    String relativePath = getRelativePath(path, solution, file);

    if (repository.canWrite(relativePath) && data != null) {
      // TODO: this is really to write anything here
      switch (repository.publishFile(relativePath, data.getBytes(ENCODING), true)) {
        case OK:
          SettingsManager.getInstance().clearCache();
          writeOut(out, "File saved.");
          return true;
        case FAIL:
          writeOut(out, "Save unsuccessful!");
          logger.error("writeCdaFile: saving " + relativePath);
          break;
      }
    } else {
      throw new AccessDeniedException(relativePath, null);
    }
    return false;
  }