Пример #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;
  }
Пример #2
0
 public void getResource(final OutputStream out, String resource) throws Exception {
   // String resource = requParam.getStringParameter("resource", null);
   resource = resource.startsWith("/") ? resource : "/" + resource;
   IRepositoryAccess repAccess = CdaEngine.getEnvironment().getRepositoryAccess();
   IRepositoryFile resFile = repAccess.getRepositoryFile(resource, FileAccess.READ);
   if (resFile != null && resFile.exists()) {
     out.write(resFile.getData());
   }
 }
Пример #3
0
  public boolean deleteCdaFile(final String path, final String solution, final String file)
      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)) {
      return repository.removeFileIfExists(relativePath);
    } else {
      throw new AccessDeniedException(relativePath, null);
    }
  }
Пример #4
0
  public String getResourceAsString(
      final String path, FileAccess access, IResponseTypeHandler response)
      throws IOException, AccessDeniedException {
    IRepositoryAccess repository = CdaEngine.getEnvironment().getRepositoryAccess();
    if (repository.hasAccess(path, access)) {
      HashMap<String, String> keys = new HashMap<String, String>();
      // Locale locale = LocaleHelper.getLocale();
      Locale locale = response.getLocale();

      if (logger.isDebugEnabled()) {
        logger.debug("Current user locale: " + locale.toString());
      }
      keys.put("#{LANGUAGE_CODE}", locale.toString());
      return getResourceAsString(path, keys);
    } else {
      throw new AccessDeniedException(path, null);
    }
  }
Пример #5
0
  // @Exposed(accessLevel = AccessLevel.PUBLIC)
  // TODO: this has to go into cda-pentaho or needs to be refactored
  @Deprecated
  public void editFile(
      final OutputStream out,
      final String path,
      final String solution,
      final String file,
      IResponseTypeHandler response)
      throws Exception {
    IRepositoryAccess repository = CdaEngine.getEnvironment().getRepositoryAccess();

    // Check if the file exists and we have permissions to write to it
    String relativePath = getRelativePath(path, solution, file);
    if (repository.canWrite(relativePath)) {
      boolean hasCde = repository.resourceExists("system/pentaho-cdf-dd");

      final String editorPath =
          "system/" + PLUGIN_NAME + (hasCde ? EXT_EDITOR_SOURCE : EDITOR_SOURCE);
      writeOut(out, getResourceAsString(editorPath, FileAccess.EXECUTE, response));
    } else {
      setResponseHeaders("text/plain");
      out.write("Access Denied".getBytes());
    }
  }
Пример #6
0
  public String getResourceAsString(final String path, final HashMap<String, String> tokens)
      throws IOException {
    // Read file
    IRepositoryAccess repository = CdaEngine.getEnvironment().getRepositoryAccess();
    String resourceContents = StringUtils.EMPTY;

    if (repository.resourceExists(path)) {
      InputStream in = null;
      try {
        in = repository.getResourceInputStream(path, FileAccess.READ);
        resourceContents = IOUtils.toString(in);
      } finally {
        IOUtils.closeQuietly(in);
      }
    }

    // Make replacement of tokens
    if (tokens != null) {
      for (final String key : tokens.keySet()) {
        resourceContents = StringUtils.replace(resourceContents, key, tokens.get(key));
      }
    }
    return resourceContents;
  }