Package pt.webdetails.cpf.repository.api

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


      // Set cache for 1 year, give or take.
      response.setHeader( "Cache-Control", "max-age=" + 60 * 60 * 24 * 365 );
      response.setHeader( "content-disposition", "inline; filename=\"" + path[ path.length - 1 ] + "\"" );

      IBasicFile file = Utils.getFileViaAppropriateReadAccess( resource );
      if ( file == null ) {
        logger.error( "resource not found:" + resource );
        response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
        return;
      }

      IOUtils.copy( file.getContents(), out );
      setCacheControl();
    } catch ( SecurityException e ) {
      response.sendError( HttpServletResponse.SC_FORBIDDEN );
    }
  }
View Full Code Here


  }

  private void readWidgetStubComponents( MetaModel.Builder model, XmlFsPluginThingReaderFactory factory )
      throws ThingReadException {
    Document doc = null;
    IBasicFile cdeXml = CdeEngine.getInstance().getEnvironment().getCdeXml();
    try {
      if ( cdeXml != null ) {
        doc = Utils.getDocFromFile( cdeXml, null );
      }
    } catch ( Exception e ) {
View Full Code Here

    }
  }

  protected void copyStdGlobalMessageFileToCache() throws IOException {

    IBasicFile globalMsgCacheFile = getGlobalMsgCacheFile();

    if ( globalMsgCacheFile != null && globalMsgCacheFile.getContents() != null ) {
      return;

    } else {

      String globalMsgFileName = BASE_GLOBAL_MESSAGE_SET_FILENAME + ".properties";

      IBasicFile globalMsgFile =
          CdeEnvironment.getPluginSystemReader( SYSTEM_PLUGIN_GLOBAL_LANGUAGES_DIR ).fetchFile( globalMsgFileName );

      CdeEnvironment.getPluginSystemWriter().saveFile(
          Utils.joinPath( BASE_CACHE_DIR, msgsRelativeDir, globalMsgFileName ), globalMsgFile.getContents() );
    }
  }
View Full Code Here

    // 1. Check existence and permissions to the original CDFDE file
    // NOTE: the cache is shared by all users.
    // The current user may not have access to a cache item previously
    // created by another user.
    IBasicFile cdeFile = Utils.getSystemOrUserReadAccess( cdeFilePath ).fetchFile( cdeFilePath );
    if ( cdeFile == null ) {
      throw new ThingReadException( new FileNotFoundException( cdeFilePath ) );
    }

    // 2. Get the Dashboard object
View Full Code Here

  private static CacheManager createWriteResultCacheManager() throws CacheException {
    // 'new CacheManager' used instead of 'CacheManager.create' to avoid overriding default cache
    String cacheConfigFile = CACHE_CFG_FILE;

    IBasicFile cfgFile = CdeEnvironment.getPluginSystemReader().fetchFile( cacheConfigFile );

    CacheManager cacheMgr = new CacheManager( cfgFile != null ? cfgFile.getFullPath() : null );

    // enableCacheProperShutdown
    System.setProperty( CacheManager.ENABLE_SHUTDOWN_HOOK_PROPERTY, "true" );

    return cacheMgr;
View Full Code Here

  @Path( "/get" )
  @Produces( "text/plain" )
  public void getResource( @QueryParam( "resource" ) @DefaultValue( "" ) String resource,
                           @Context HttpServletResponse response ) throws IOException {
    try {
      IBasicFile file = Utils.getFileViaAppropriateReadAccess( resource );

      if ( file == null ) {
        logger.error( "resource not found:" + resource );
        response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
        return;
      }

      IPluginResourceLoader resLoader = PentahoSystem.get( IPluginResourceLoader.class, null );
      String maxAge = resLoader.getPluginSetting( this.getClass(), "max-age" );

      String mimeType;
      try {
        mimeType = MimeTypeHandler.getMimeTypeFromExtension( file.getExtension() );
      } catch ( java.lang.IllegalArgumentException ex ) {
        mimeType = "";
      } catch ( EnumConstantNotPresentException ex ) {
        mimeType = "";
      }

      response.setHeader( "Content-Type", mimeType );
      response.setHeader( "content-disposition", "inline; filename=\"" + file.getName() + "\"" );

      if ( maxAge != null ) {
        response.setHeader( "Cache-Control", "max-age=" + maxAge );
      }

      byte[] contents = IOUtils.toByteArray( file.getContents() );

      IOUtils.write( contents, response.getOutputStream() );
      response.getOutputStream().flush();
    } catch ( SecurityException e ) {
      response.sendError( HttpServletResponse.SC_FORBIDDEN );
View Full Code Here

TOP

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

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.