Search in sources :

Example 81 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class WebAppFile method getFilePath.

private String getFilePath(String fileURL) throws ScriptException {
    JaggeryContext jaggeryContext = CommonManager.getJaggeryContext();
    Stack<String> includesCallstack = CommonManager.getCallstack(jaggeryContext);
    ServletContext context = (ServletContext) jaggeryContext.getProperty(Constants.SERVLET_CONTEXT);
    String parent = includesCallstack.lastElement();
    try {
        String[] keys = WebAppManager.getKeys(context.getContextPath(), parent, fileURL);
        fileURL = "/".equals(keys[1]) ? keys[2] : keys[1] + keys[2];
    } catch (NullPointerException ne) {
        throw new ScriptException("Invalid file path : " + fileURL, ne);
    }
    return fileURL;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) ServletContext(javax.servlet.ServletContext) JaggeryContext(org.jaggeryjs.scriptengine.engine.JaggeryContext)

Example 82 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class HostObjectUtil method readerToString.

public static String readerToString(Reader reader) throws ScriptException {
    StringBuilder sb = new StringBuilder();
    try {
        int data = reader.read();
        while (data != -1) {
            sb.append((char) data);
            data = reader.read();
        }
        return sb.toString();
    } catch (IOException e) {
        String msg = "Error while reading the content from the Reader";
        log.error(msg, e);
        throw new ScriptException(msg, e);
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            log.warn(e);
        }
    }
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Example 83 with ScriptException

use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.

the class RegistryHostObject method getRegistry.

private static UserRegistry getRegistry(String username, String password) throws ScriptException {
    UserRegistry registry;
    RegistryService registryService = RegistryHostObjectContext.getRegistryService();
    String tDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(false);
    try {
        int tId = RegistryHostObjectContext.getRealmService().getTenantManager().getTenantId(tDomain);
        registry = registryService.getGovernanceUserRegistry(username, password, tId);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ScriptException(e);
    }
    if (registry == null) {
        String msg = "User governance registry cannot be retrieved";
        throw new ScriptException(msg);
    }
    return registry;
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) RegistryException(org.wso2.carbon.registry.api.RegistryException) IndexerException(org.wso2.carbon.registry.indexing.indexer.IndexerException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) CarbonException(org.wso2.carbon.CarbonException) ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException)

Aggregations

ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)83 IOException (java.io.IOException)15 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)13 ScriptableObject (org.mozilla.javascript.ScriptableObject)12 RegistryException (org.wso2.carbon.registry.api.RegistryException)11 ScriptReader (org.jaggeryjs.jaggery.core.ScriptReader)9 URL (java.net.URL)8 JaggeryContext (org.jaggeryjs.scriptengine.engine.JaggeryContext)8 MalformedURLException (java.net.MalformedURLException)7 ServletContext (javax.servlet.ServletContext)6 ScriptCachingContext (org.jaggeryjs.scriptengine.cache.ScriptCachingContext)6 RhinoEngine (org.jaggeryjs.scriptengine.engine.RhinoEngine)5 Context (org.mozilla.javascript.Context)5 File (java.io.File)4 StringReader (java.io.StringReader)4 Callable (java.util.concurrent.Callable)4 ExecutorService (java.util.concurrent.ExecutorService)4 FileItem (org.apache.commons.fileupload.FileItem)4 FileHostObject (org.jaggeryjs.hostobjects.file.FileHostObject)4 StreamHostObject (org.jaggeryjs.hostobjects.stream.StreamHostObject)4