Example usage for org.apache.commons.io IOUtils IOUtils

List of usage examples for org.apache.commons.io IOUtils IOUtils

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils IOUtils.

Prototype

public IOUtils() 

Source Link

Document

Instances should NOT be constructed in standard programming.

Usage

From source file:com.sap.dirigible.runtime.scripting.AbstractScriptExecutor.java

protected void registerDefaultVariables(HttpServletRequest request, HttpServletResponse response, Object input,
        Map<Object, Object> executionContext, IRepository repository, Object scope) {
    // put the execution context
    registerDefaultVariable(scope, "context", executionContext); //$NON-NLS-1$
    // put the system out
    registerDefaultVariable(scope, "out", System.out); //$NON-NLS-1$
    // put the default data source
    DataSource dataSource = null;
    if (repository instanceof DBRepository) {
        dataSource = ((DBRepository) repository).getDataSource();
    } else {//w w  w  . jav  a2s .  c  om
        dataSource = RepositoryFacade.getInstance().getDataSource();
    }
    registerDefaultVariable(scope, "datasource", dataSource); //$NON-NLS-1$
    // put request
    registerDefaultVariable(scope, "request", request); //$NON-NLS-1$
    // put response
    registerDefaultVariable(scope, "response", response); //$NON-NLS-1$
    // put repository
    registerDefaultVariable(scope, "repository", repository); //$NON-NLS-1$
    // put mail sender
    MailSender mailSender = new MailSender();
    registerDefaultVariable(scope, "mail", mailSender); //$NON-NLS-1$
    // put Apache Commons IOUtils
    IOUtils ioUtils = new IOUtils();
    registerDefaultVariable(scope, "io", ioUtils); //$NON-NLS-1$
    // put Apache Commons HttpClient and related classes wrapped with a
    // factory like HttpUtils
    HttpUtils httpUtils = new HttpUtils();
    registerDefaultVariable(scope, "http", httpUtils); //$NON-NLS-1$
    // put Apache Commons Codecs
    Base64 base64Codec = new Base64();
    registerDefaultVariable(scope, "base64", base64Codec); //$NON-NLS-1$
    Hex hexCodec = new Hex();
    registerDefaultVariable(scope, "hex", hexCodec); //$NON-NLS-1$
    DigestUtils digestUtils = new DigestUtils();
    registerDefaultVariable(scope, "digest", digestUtils); //$NON-NLS-1$
    // standard URLEncoder and URLDecoder functionality
    URLUtils urlUtils = new URLUtils();
    registerDefaultVariable(scope, "url", urlUtils); //$NON-NLS-1$
    // user name
    registerDefaultVariable(scope, "user", RepositoryFacade.getUser(request)); //$NON-NLS-1$
    // file upload
    ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory());
    registerDefaultVariable(scope, "upload", fileUpload); //$NON-NLS-1$
    // UUID
    UUID uuid = new UUID(0, 0);
    registerDefaultVariable(scope, "uuid", uuid); //$NON-NLS-1$
    // the input from the execution chain if any
    registerDefaultVariable(scope, "input", input); //$NON-NLS-1$
    // DbUtils
    DbUtils dbUtils = new DbUtils(dataSource);
    registerDefaultVariable(scope, "db", dbUtils); //$NON-NLS-1$
    // EscapeUtils
    StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
    registerDefaultVariable(scope, "xss", stringEscapeUtils); //$NON-NLS-1$
    // Extension Manager
    ExtensionManager extensionManager = new ExtensionManager(repository, dataSource);
    registerDefaultVariable(scope, "extensionManager", extensionManager); //$NON-NLS-1$
    // Apache Lucene Indexer
    IndexerUtils indexerUtils = new IndexerUtils();
    registerDefaultVariable(scope, "indexer", indexerUtils); //$NON-NLS-1$
    // Mylyn Confluence Format
    WikiUtils wikiUtils = new WikiUtils();
    registerDefaultVariable(scope, "wiki", wikiUtils); //$NON-NLS-1$
    // Simple binary storage
    StorageUtils storageUtils = new StorageUtils(dataSource);
    registerDefaultVariable(scope, "storage", storageUtils); //$NON-NLS-1$
    // Simple file storage
    FileStorageUtils fileStorageUtils = new FileStorageUtils(dataSource);
    registerDefaultVariable(scope, "fileStorage", fileStorageUtils); //$NON-NLS-1$
    // Simple binary storage
    ConfigStorageUtils configStorageUtils = new ConfigStorageUtils(dataSource);
    registerDefaultVariable(scope, "config", configStorageUtils); //$NON-NLS-1$
    // XML to JSON and vice-versa
    XMLUtils xmlUtils = new XMLUtils();
    registerDefaultVariable(scope, "xml", xmlUtils); //$NON-NLS-1$

}

From source file:com.tc.websocket.scripts.Script.java

/**
 * Gets the common vars.//from  w  w  w.ja va 2 s  . c om
 *
 * @param session the session
 * @return the common vars
 */
public Map<String, Object> getCommonVars(Session session) {
    Map<String, Object> vars = new HashMap<String, Object>();
    vars.put(Const.FUNCTION, this.getFunction());
    vars.put(Const.VAR_SESSION, session);
    vars.put(Const.VAR_BUNDLE_UTILS, new BundleUtils());

    vars.put(Const.VAR_TERM_SIGNAL, TermSignal.insta());
    vars.put(Const.VAR_CACHE, ScriptCache.insta());
    vars.put(Const.VAR_SCRIPT, new ScriptWrapper(this));
    vars.put(Const.VAR_B64, Base64.insta());
    vars.put(Const.VAR_STRUTILS, StrUtils.insta());
    vars.put(Const.VAR_COLUTILS, ColUtils.insta());
    vars.put(Const.VAR_STOPWATCH, new StopWatch());
    vars.put(Const.VAR_FILEUTILS, new FileUtils());
    vars.put(Const.VAR_IOUTILS, new IOUtils());
    vars.put(Const.VAR_ATTACHUTILS, AttachUtils.insta());

    SimpleClient client = guicer.inject(new SimpleClient(this));
    vars.put(Const.VAR_WEBSOCKET_CLIENT, client);

    String from = this.getFrom();

    //add application scoped objects
    String key = "/" + dbPath();
    this.applyVars("/" + dbPath(), vars);

    //now add user scoped objects
    if (!StrUtils.isEmpty(from)) {
        IUser user = client.getUser(from);
        if (user != null) {
            key = "/" + dbPath() + "/" + user.getSessionId();
            this.applyVars(key, vars);
        }
    }

    //last bit, make sure db is available.
    try {
        vars.put(Const.VAR_DB, session.getDatabase("", this.dbPath()));
    } catch (NotesException n) {
        LOG.log(Level.SEVERE, null, n);
    }

    return vars;
}

From source file:org.eclipse.dirigible.runtime.scripting.AbstractScriptExecutor.java

@Override
public void registerDefaultVariables(HttpServletRequest request, HttpServletResponse response, Object input,
        Map<Object, Object> executionContext, IRepository repository, Object scope) {

    InjectedAPIBuilder apiBuilder = new InjectedAPIBuilder();

    if (executionContext == null) {
        // in case executionContext is not provided from outside
        executionContext = new HashMap<Object, Object>();
    }//  w  ww.  j  av  a  2s . c om

    // Objects

    // put the execution context
    registerDefaultVariable(scope, IInjectedAPIAliases.EXECUTION_CONTEXT, executionContext);
    apiBuilder.setExecutionContext(executionContext);

    // put the console
    Console console = new Console();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.CONSOLE, console);
    apiBuilder.setConsole(console);

    // put the system out
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.SYSTEM_OUTPUT,
            System.out);
    apiBuilder.setSystemOutput(System.out);

    // put the default data source
    DataSource dataSource = null;
    dataSource = registerDefaultDatasource(request, executionContext, scope, apiBuilder);

    // put request
    registerRequest(request, executionContext, scope, apiBuilder);

    // put response
    registerResponse(response, executionContext, scope, apiBuilder);

    // put repository
    registerRepository(executionContext, repository, scope, apiBuilder);

    // user name
    registerUserName(request, executionContext, scope, apiBuilder);

    // the input from the execution chain if any
    registerRequestInput(input, executionContext, scope, apiBuilder);

    // put JNDI
    registerInitialContext(request, executionContext, scope, apiBuilder);

    // Simple binary storage
    registerBinaryStorage(executionContext, scope, apiBuilder, dataSource);

    // Simple file storage
    registerFileStorage(executionContext, scope, apiBuilder, dataSource);

    // Simple configuration storage
    registerConfigurationStorage(executionContext, scope, apiBuilder, dataSource);

    // Services

    // put mail sender
    registerMailService(request, executionContext, scope, apiBuilder);

    // Extension Manager
    registerExtensionManager(request, executionContext, repository, scope, apiBuilder, dataSource);

    // Apache Lucene Indexer
    registerIndexingService(executionContext, scope, apiBuilder);

    // Connectivity Configuration service
    registerConnectivityService(executionContext, scope, apiBuilder);

    // Document service
    registerDocumentService(executionContext, scope, apiBuilder);

    // Messaging Service
    registerMessagingService(request, executionContext, scope, apiBuilder, dataSource);

    // Templating Service
    registerTemplatingService(executionContext, scope, apiBuilder);

    // Executing Service
    registerExecutingService(executionContext, scope, apiBuilder);

    // Generation Service
    registerGenerationService(executionContext, scope, apiBuilder);

    // Lifecycle Service
    registerLifecycleService(executionContext, scope, apiBuilder);

    // Workspaces Service
    registerWorkspacesService(executionContext, scope, apiBuilder);

    // Utils

    // put Apache Commons IOUtils
    IOUtils ioUtils = new IOUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.IO_UTILS, ioUtils);
    apiBuilder.setIOUtils(ioUtils);

    // put Apache Commons HttpClient and related classes wrapped with a factory like HttpUtils
    HttpUtils httpUtils = new HttpUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.HTTP_UTILS,
            httpUtils);
    apiBuilder.setHttpUtils(httpUtils);

    // put Apache Commons Codecs
    Base64 base64Codec = new Base64();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.BASE64_UTILS,
            base64Codec);
    apiBuilder.setBase64Utils(base64Codec);

    Hex hexCodec = new Hex();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.HEX_UTILS, hexCodec);
    apiBuilder.setHexUtils(hexCodec);

    DigestUtils digestUtils = new DigestUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DIGEST_UTILS,
            digestUtils);
    apiBuilder.setDigestUtils(digestUtils);

    // standard URLEncoder and URLDecoder functionality
    URLUtils urlUtils = new URLUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.URL_UTILS, urlUtils);
    apiBuilder.setUrlUtils(urlUtils);

    // file upload
    ServletFileUpload fileUpload = new ServletFileUpload(new DiskFileItemFactory());
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.UPLOAD_UTILS,
            fileUpload);
    apiBuilder.setUploadUtils(fileUpload);

    // UUID
    UUID uuid = new UUID(0, 0);
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.UUID_UTILS, uuid);
    apiBuilder.setUuidUtils(uuid);

    // DbUtils
    DbUtils dbUtils = new DbUtils(dataSource);
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DB_UTILS, dbUtils);
    apiBuilder.setDatabaseUtils(dbUtils);

    // EscapeUtils
    StringEscapeUtils stringEscapeUtils = new StringEscapeUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.XSS_UTILS,
            stringEscapeUtils);
    apiBuilder.setXssUtils(stringEscapeUtils);

    // XML to JSON and vice-versa
    XMLUtils xmlUtils = new XMLUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.XML_UTILS, xmlUtils);
    apiBuilder.setXmlUtils(xmlUtils);

    // ExceptionUtils
    ExceptionUtils exceptionUtils = new ExceptionUtils();
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.EXCEPTION_UTILS,
            exceptionUtils);
    apiBuilder.setExceptionUtils(exceptionUtils);

    // Named DataSources Utils
    NamedDataSourcesUtils namedDataSourcesUtils = new NamedDataSourcesUtils(request);
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.DATASOURCES_UTILS,
            namedDataSourcesUtils);
    apiBuilder.setNamedDataSourcesUtils(namedDataSourcesUtils);

    // register objects via extension
    try {
        BundleContext context = RuntimeActivator.getContext();
        if (context != null) {
            Collection<ServiceReference<IContextService>> serviceReferences = context
                    .getServiceReferences(IContextService.class, null);
            for (ServiceReference<IContextService> serviceReference : serviceReferences) {
                try {
                    IContextService contextService = context.getService(serviceReference);
                    registerDefaultVariableInContextAndScope(executionContext, scope, contextService.getName(),
                            contextService.getInstance());
                    apiBuilder.set(contextService.getName(), contextService.getInstance());
                } catch (Throwable t) {
                    logger.error(t.getMessage(), t);
                }
            }
        }
    } catch (InvalidSyntaxException e) {
        logger.error(e.getMessage(), e);
    }

    InjectedAPIWrapper api = new InjectedAPIWrapper(apiBuilder);
    registerDefaultVariableInContextAndScope(executionContext, scope, IInjectedAPIAliases.API, api);
}