use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.
the class WebAppFile method readAll.
@Override
public String readAll() throws ScriptException {
if (!opened) {
log.warn("You need to open the file for reading");
return null;
}
if (!readable) {
log.warn("File has not opened in a readable mode.");
return null;
}
try {
long pointer = file.getFilePointer();
file.seek(0);
String data = read(file.length());
file.seek(pointer);
return data;
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
}
use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.
the class WebAppFile method read.
@Override
public String read(long count) throws ScriptException {
if (!opened) {
log.warn("You need to open the file for reading");
return null;
}
if (!readable) {
log.warn("File has not opened in a readable mode.");
return null;
}
try {
byte[] arr = new byte[(int) min(count, file.length())];
file.readFully(arr);
return new String(arr, "UTF-8");
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new ScriptException(e);
}
}
use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.
the class ResponseHostObject method jsFunction_sendRedirect.
@SuppressFBWarnings("UNVALIDATED_REDIRECT")
public static void jsFunction_sendRedirect(Context cx, Scriptable thisObj, Object[] args, Function funObj) throws ScriptException {
String functionName = "sendRedirect";
int argsCount = args.length;
if (argsCount != 1) {
HostObjectUtil.invalidNumberOfArgs(hostObjectName, functionName, argsCount, false);
}
if (!(args[0] instanceof String)) {
HostObjectUtil.invalidArgsError(hostObjectName, functionName, "1", "string", args[0], false);
}
ResponseHostObject rho = (ResponseHostObject) thisObj;
try {
rho.response.sendRedirect((String) args[0]);
} catch (IOException e) {
String msg = "Error sending redirect : " + args[0];
log.warn(msg, e);
throw new ScriptException(msg, e);
}
}
use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.
the class ResponseHostObject method jsSet_content.
public void jsSet_content(Object object) throws ScriptException {
try {
String content = HostObjectUtil.serializeObject(object);
response.getOutputStream().write(content.getBytes("UTF-8"));
} catch (IOException e) {
String msg = "Error occurred while reading Servlet OutputStream";
log.error(msg, e);
throw new ScriptException(msg, e);
}
}
use of org.jaggeryjs.scriptengine.exceptions.ScriptException in project jaggery by wso2.
the class RegistryHostObject method jsFunction_newResource.
public static Scriptable jsFunction_newResource(Context cx, Scriptable thisObj, Object[] arguments, Function funObj) throws ScriptException {
RegistryHostObject registryHostObject = (RegistryHostObject) thisObj;
if (arguments.length == 0) {
if (registryHostObject.registry != null) {
try {
Resource resource = registryHostObject.registry.newResource();
ResourceHostObject rho = (ResourceHostObject) cx.newObject(registryHostObject, "Resource", new Object[] { resource });
return rho;
} catch (RegistryException e) {
throw new ScriptException("Error occurred while creating a new Resource", e);
}
} else {
throw new ScriptException("Registry has not initialized");
}
} else {
throw new ScriptException("newResource() Method doesn't accept arguments");
}
}
Aggregations