AMQ-3665: Moved code for creating VelocityContext into its own method createVelocityContext().

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1234781 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Torsten Mielke 2012-01-23 13:28:42 +00:00
parent 4ddd9019c8
commit 95355ae6e3
1 changed files with 27 additions and 18 deletions

View File

@ -88,6 +88,30 @@ public class AMQJournalTool {
consumerTool.execute();
}
/**
* Creates a new VelocityContext that is pre-populated with the JVMs
* system properties.
*
* @return - the VelocityContext that got created.
*/
protected VelocityContext createVelocityContext() {
VelocityContext ctx = new VelocityContext();
List keys = Arrays.asList(ctx.getKeys());
for (Iterator iterator = System.getProperties().entrySet()
.iterator(); iterator.hasNext();) {
Map.Entry kv = (Map.Entry) iterator.next();
String name = (String) kv.getKey();
String value = (String) kv.getValue();
if (!keys.contains(name)) {
ctx.put(name, value);
}
}
return ctx;
}
public void execute() throws Exception {
if( help ) {
@ -120,34 +144,20 @@ public class AMQJournalTool {
}
}
context = new VelocityContext();
List keys = Arrays.asList(context.getKeys());
for (Iterator iterator = System.getProperties().entrySet()
.iterator(); iterator.hasNext();) {
Map.Entry kv = (Map.Entry) iterator.next();
String name = (String) kv.getKey();
String value = (String) kv.getValue();
if (!keys.contains(name)) {
context.put(name, value);
}
}
context = createVelocityContext();
velocity = new VelocityEngine();
velocity.setProperty(Velocity.RESOURCE_LOADER, "all");
velocity.setProperty("all.resource.loader.class", CustomResourceLoader.class.getName());
velocity.init();
resources.put("message", messageFormat);
resources.put("topicAck", topicAckFormat);
resources.put("queueAck", queueAckFormat);
resources.put("transaction", transactionFormat);
resources.put("trace", traceFormat);
resources.put("unknown", unknownFormat);
Query query = null;
if (where != null) {
query = new Query();
@ -171,7 +181,7 @@ public class AMQJournalTool {
entry.setQuery(query);
process(entry);
curr = manager.getNextLocation(curr);
curr = manager.getNextLocation(curr);
}
} finally {
manager.close();
@ -189,7 +199,6 @@ public class AMQJournalTool {
private void process(Entry entry) throws Exception {
Location location = entry.getLocation();
DataStructure record = entry.getRecord();
switch (record.getDataStructureType()) {