use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.
the class DebuggerClient method getDebugger.
/**
* Connects to the FreeMarker debugger service running on a specific host
* and port. The Java VM to which the connection is made must have defined
* the system property <tt>freemarker.debug.password</tt> in order to enable
* the debugger service. Additionally, the <tt>freemarker.debug.port</tt>
* system property can be set to specify the port where the debugger service
* is listening. When not specified, it defaults to
* {@link Debugger#DEFAULT_PORT}.
* @param host the host address of the machine where the debugger service is
* running.
* @param port the port of the debugger service
* @param password the password required to connect to the debugger service
* @return Debugger a debugger object. null is returned in case incorrect
* password was supplied.
* @throws IOException if an exception occurs.
*/
public static Debugger getDebugger(InetAddress host, int port, String password) throws IOException {
try {
Socket s = new Socket(host, port);
try {
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
int protocolVersion = in.readInt();
if (protocolVersion > 220) {
throw new IOException("Incompatible protocol version " + protocolVersion + ". At most 220 was expected.");
}
byte[] challenge = (byte[]) in.readObject();
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(password.getBytes("UTF-8"));
md.update(challenge);
out.writeObject(md.digest());
return new LocalDebuggerProxy((Debugger) in.readObject());
// return (Debugger)in.readObject();
} finally {
s.close();
}
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new UndeclaredThrowableException(e);
}
}
use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.
the class Environment method visit.
void visit(final TemplateElement[] childBuffer, TemplateDirectiveModel directiveModel, Map args, final List bodyParameterNames) throws TemplateException, IOException {
TemplateDirectiveBody nested;
if (childBuffer == null) {
nested = null;
} else {
nested = new NestedElementTemplateDirectiveBody(childBuffer);
}
final TemplateModel[] outArgs;
if (bodyParameterNames == null || bodyParameterNames.isEmpty()) {
outArgs = NO_OUT_ARGS;
} else {
outArgs = new TemplateModel[bodyParameterNames.size()];
}
if (outArgs.length > 0) {
pushLocalContext(new LocalContext() {
public TemplateModel getLocalVariable(String name) {
int index = bodyParameterNames.indexOf(name);
return index != -1 ? outArgs[index] : null;
}
public Collection getLocalVariableNames() {
return bodyParameterNames;
}
});
}
try {
directiveModel.execute(this, args, outArgs, nested);
} catch (FlowControlException e) {
throw e;
} catch (TemplateException e) {
throw e;
} catch (IOException e) {
// For backward compatibility, we assume that this is because the output Writer has thrown it.
throw e;
} catch (Exception e) {
if (EvalUtil.shouldWrapUncheckedException(e, this)) {
throw new _MiscTemplateException(e, this, "Directive has thrown an unchecked exception; see the cause exception.");
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new UndeclaredThrowableException(e);
}
} finally {
if (outArgs.length > 0) {
localContextStack.pop();
}
}
}
use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.
the class Environment method visitAndTransform.
/**
* "Visit" the template element, passing the output through a TemplateTransformModel
*
* @param elementBuffer
* the element to visit through a transform; might contains trailing {@code null}-s
* @param transform
* the transform to pass the element output through
* @param args
* optional arguments fed to the transform
*/
void visitAndTransform(TemplateElement[] elementBuffer, TemplateTransformModel transform, Map args) throws TemplateException, IOException {
try {
Writer tw = transform.getWriter(out, args);
if (tw == null)
tw = EMPTY_BODY_WRITER;
TransformControl tc = tw instanceof TransformControl ? (TransformControl) tw : null;
Writer prevOut = out;
out = tw;
try {
if (tc == null || tc.onStart() != TransformControl.SKIP_BODY) {
do {
visit(elementBuffer);
} while (tc != null && tc.afterBody() == TransformControl.REPEAT_EVALUATION);
}
} catch (Throwable t) {
try {
if (tc != null && !(t instanceof FlowControlException && getConfiguration().getIncompatibleImprovements().intValue() >= _TemplateAPI.VERSION_INT_2_3_27)) {
tc.onError(t);
} else {
throw t;
}
} catch (TemplateException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Error e) {
throw e;
} catch (Throwable e) {
if (EvalUtil.shouldWrapUncheckedException(e, this)) {
throw new _MiscTemplateException(e, this, "Transform has thrown an unchecked exception; see the cause exception.");
} else if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new UndeclaredThrowableException(e);
}
}
} finally {
out = prevOut;
if (prevOut != tw) {
tw.close();
}
}
} catch (TemplateException te) {
handleTemplateException(te);
}
}
use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.
the class SoftCacheStorage method processQueue.
private void processQueue() {
for (; ; ) {
SoftValueReference ref = (SoftValueReference) queue.poll();
if (ref == null) {
return;
}
Object key = ref.getKey();
if (concurrent) {
try {
atomicRemove.invoke(map, new Object[] { key, ref });
} catch (IllegalAccessException e) {
throw new UndeclaredThrowableException(e);
} catch (InvocationTargetException e) {
throw new UndeclaredThrowableException(e);
}
} else if (map.get(key) == ref) {
map.remove(key);
}
}
}
use of freemarker.template.utility.UndeclaredThrowableException in project freemarker by apache.
the class JaxenXPathSupport method executeQuery.
public TemplateModel executeQuery(Object context, String xpathQuery) throws TemplateModelException {
try {
BaseXPath xpath;
Map<String, BaseXPath> xpathCache = (Map<String, BaseXPath>) XPATH_CACHE_ATTR.get();
synchronized (xpathCache) {
xpath = xpathCache.get(xpathQuery);
if (xpath == null) {
xpath = new BaseXPath(xpathQuery, FM_DOM_NAVIGATOR);
xpath.setNamespaceContext(customNamespaceContext);
xpath.setFunctionContext(FM_FUNCTION_CONTEXT);
xpath.setVariableContext(FM_VARIABLE_CONTEXT);
xpathCache.put(xpathQuery, xpath);
}
}
List result = xpath.selectNodes(context != null ? context : EMPTY_ARRAYLIST);
if (result.size() == 1) {
// [2.4] Use the proper object wrapper (argument in 2.4)
return ObjectWrapper.DEFAULT_WRAPPER.wrap(result.get(0));
}
NodeListModel nlm = new NodeListModel(result, null);
nlm.xpathSupport = this;
return nlm;
} catch (UndeclaredThrowableException e) {
Throwable t = e.getUndeclaredThrowable();
if (t instanceof TemplateModelException) {
throw (TemplateModelException) t;
}
throw e;
} catch (JaxenException je) {
throw new TemplateModelException(je);
}
}
Aggregations