Package pt.webdetails.cpf.repository.api

Examples of pt.webdetails.cpf.repository.api.IRWAccess


    Locale locale = CdeEngine.getEnv().getLocale();

    IUserContentAccess userContentAccess =
        CdeEngine.getEnv().getContentAccessFactory().getUserContentAccess( msgsRelativeDir );
    IRWAccess systemWriter =
        CdeEngine.getEnv().getContentAccessFactory().getPluginSystemWriter(
            Utils.joinPath( BASE_CACHE_DIR, msgsRelativeDir ) );

    // If localized global message file doesn't exists then use the standard base global message file
    // and generate a fake global message file. So this way we're sure that we always have the file
    String localizedMsgGlobalName = BASE_GLOBAL_MESSAGE_SET_FILENAME + "_" + locale.getLanguage() + ".properties";

    if ( userContentAccess.fileExists( localizedMsgGlobalName ) ) {

      systemWriter.saveFile( localizedMsgGlobalName, userContentAccess.getFileInputStream( localizedMsgGlobalName ) );

    } else if ( globalBaseMessageFile != null ) {

      systemWriter.saveFile( localizedMsgGlobalName, globalBaseMessageFile.getContents() );
    }

    // Append specific message file only if it exists otherwise just use the global message files
    if ( sourceDashboardBaseMsgFile != null ) {

      systemWriter.saveFile( sourceDashboardBaseMsgFile.getName(), sourceDashboardBaseMsgFile.getContents() );

      String localizedMsgTargetName =
          FilenameUtils.getBaseName( sourceDashboardBaseMsgFile.getName() ) + "_" + locale.getLanguage()
              + ".properties";

      if ( userContentAccess.fileExists( localizedMsgTargetName ) ) {

        systemWriter.saveFile( localizedMsgTargetName, userContentAccess.getFileInputStream( localizedMsgTargetName ) );
      }
    }
  }
View Full Code Here



    logger.info( "Saving File:" + cdeFilePath );

    // 2. If not the CDE temp file, delete the temp file, if one exists
    IRWAccess access = Utils.getSystemOrUserRWAccess( cdeFilePath );


    // TODO:
    boolean isPreview = cdeFilePath.indexOf( "_tmp.cdfde" ) >= 0;
    if ( !isPreview ) {
      String cdeTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.cdfde" );
      access.deleteFile( cdeTempFilePath );

      String cdaTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.cda" );
      access.deleteFile( cdaTempFilePath );

      String wcdfTempFilePath = cdeFilePath.replace( ".cdfde", "_tmp.wcdf" );
      access.deleteFile( wcdfTempFilePath );
    }

    // 3. CDE


    if ( !access.saveFile( cdeFilePath, new ByteArrayInputStream( safeGetEncodedBytes( cdfdeJsText ) ) ) ) {
      throw new DashboardStructureException(
        Messages.getString( "DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION" ) );
    }

    // 3. CDA
    CdaRenderer cdaRenderer = new CdaRenderer( cdfdeJsText );

    String cdaFileName = cdeFilePath.replace( ".cdfde", ".cda" );

    // Any data sources?
    if ( cdaRenderer.isEmpty() ) {
      access.deleteFile( cdaFileName );

    } else {
      // throws Exception ????
      String cdaText = cdaRenderer.render();
      if ( !access.saveFile( cdaFileName, new ByteArrayInputStream( safeGetEncodedBytes( cdaText ) ) ) ) {
        throw new DashboardStructureException(
          Messages.getString( "DashboardStructure.ERROR_006_SAVE_FILE_ADD_FAIL_EXCEPTION" ) );
      }
    }
View Full Code Here

      instance.ensureBasicDirs();
    }
  }

  public void ensureBasicDirs() {
    IRWAccess repoBase = CdeEnvironment.getPluginRepositoryWriter();
    // TODO: better error messages
    if ( !ensureDirExists( repoBase, CdeConstants.SolutionFolders.COMPONENTS ) ) {
      logger.error( "Couldn't find or create CDE components dir." );
    }
    if ( !ensureDirExists( repoBase, CdeConstants.SolutionFolders.STYLES ) ) {
      logger.error( "Couldn't find or create CDE styles dir." );
    }
    if ( !ensureDirExists( repoBase, CdeConstants.SolutionFolders.TEMPLATES ) ) {
      logger.error( "Couldn't find or create CDE templates dir." );
    }

    // special case for widgets: copy widget samples into dir if creating dir for the first time
    if ( !repoBase.fileExists( CdeConstants.SolutionFolders.WIDGETS ) ) {
      if ( !ensureDirExists( repoBase, CdeConstants.SolutionFolders.WIDGETS ) ) {
        logger.error( "Couldn't find or create CDE widgets dir." );
      } else {
        IReadAccess sysPluginSamples = CdeEnvironment.getPluginSystemReader( "resources/samples/" );
        saveAndClose( repoBase, Util.joinPath( CdeConstants.SolutionFolders.WIDGETS, "sample.cdfde" ),
View Full Code Here

  public void deleteFile( @FormParam( MethodParams.PATH ) @DefaultValue( "" ) String path,
                          @Context HttpServletResponse response ) throws IOException {

    IResourceLoader loader = getResourceLoader( path );
    IACAccess access = loader.getAccessControl();
    IRWAccess writer = loader.getWriter();

    if ( access.hasAccess( path, FileAccess.DELETE ) && writer.deleteFile( path ) ) {
      logger.debug( "File: " + path + " removed" );
      JsonUtils.buildJsonResult( response.getOutputStream(), true, null );
    } else {
      logger.debug( "File: " + path + "not removed" );
      JsonUtils.buildJsonResult( response.getOutputStream(), false, null );
View Full Code Here

                           @FormParam( MethodParams.DATA ) @DefaultValue( "" ) String data,
                           @Context HttpServletResponse response ) throws IOException {

    IResourceLoader loader = getResourceLoader( path );
    IACAccess access = loader.getAccessControl();
    IRWAccess writer = loader.getWriter();

    String msg;
    if ( access.hasAccess( path, FileAccess.WRITE ) ) {
      if ( writer.saveFile( path, new ByteArrayInputStream( data.getBytes( CharsetHelper.getEncoding() ) ) ) ) {
        msg = "file '" + path + "' saved ok";
        logger.debug( msg );
      } else {
        msg = "error saving file " + path;
        logger.error( msg );
View Full Code Here

                            @FormParam( MethodParams.DATA ) @DefaultValue( "" ) String data,
                            @Context HttpServletResponse response ) throws IOException {

    IResourceLoader loader = getResourceLoader( path );
    IACAccess access = loader.getAccessControl();
    IRWAccess writer = loader.getWriter();

    String msg;
    if ( access.hasAccess( FilenameUtils.getFullPath( path ), FileAccess.WRITE ) ) {
      if ( writer.saveFile( path, new ByteArrayInputStream( data.getBytes( CharsetHelper.getEncoding() ) ) ) ) {
        msg = "file '" + path + "' saved ok";
        logger.debug( msg );
      } else {
        msg = "error saving file " + path;
        logger.error( msg );
View Full Code Here

  public String createFolder( @FormParam( MethodParams.PATH ) @DefaultValue( "" ) String path,
                              @Context HttpServletResponse response ) throws IOException {

    IResourceLoader loader = getResourceLoader( path );
    IReadAccess reader = loader.getReader();
    IRWAccess writer = loader.getWriter();
    IACAccess access = loader.getAccessControl();


    String msg;
    if ( access.hasAccess( path, FileAccess.WRITE ) ) {
      if ( reader.fileExists( path ) ) {
        msg = "already exists: " + path;
        logger.debug( msg );
      } else {
        if ( writer.createFolder( path ) ) {
          msg = path + "created ok";
          logger.debug( msg );
        } else {
          msg = "error creating folder " + path;
          logger.debug( msg );
View Full Code Here

TOP

Related Classes of pt.webdetails.cpf.repository.api.IRWAccess

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.