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;
}
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);
}
}
}
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;
}
Aggregations