diff --git a/.gitignore b/.gitignore index 4fdf425..2bc5865 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ Session.vim build/ dist/ +out/ +target/ diff --git a/lib/log4j-1.2.15.jar b/lib/log4j-1.2.15.jar new file mode 100644 index 0000000..c930a6a Binary files /dev/null and b/lib/log4j-1.2.15.jar differ diff --git a/pom.xml b/pom.xml index d76a86e..66d558a 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,36 @@ bcprov-jdk16 1.44 + + + log4j + log4j + 1.2.15 + compile + + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + javax.jms + jms + + + javax.mail + mail + + + + diff --git a/run.sh b/run.sh index 8651848..6cd60d9 100755 --- a/run.sh +++ b/run.sh @@ -1,7 +1,7 @@ #!/bin/sh java \ - -cp ./lib/bcprov-jdk16-1.46.jar:$(ls -rt ./target/*jar | tail -1) \ + -cp $(find lib/ -type f -printf "./%h/%f:")$(ls -rt ./target/*jar | tail -1) \ com.hashbangbash.trie.App \ ./src/test/resources/test-certv3.pem diff --git a/src/main/java/com/redhat/trie/PathNode.java b/src/main/java/com/redhat/trie/PathNode.java index 124f52f..6836adc 100644 --- a/src/main/java/com/redhat/trie/PathNode.java +++ b/src/main/java/com/redhat/trie/PathNode.java @@ -42,11 +42,11 @@ public class PathNode { return this.ctx; } - void addChild(NodePair cp) { + public void addChild(NodePair cp) { this.children.add(cp); } - void addParent(PathNode cp) { + public void addParent(PathNode cp) { if (!parents.contains(cp)) { this.parents.add(cp); } @@ -57,15 +57,15 @@ public class PathNode { return this.children; } - List getParents() { + public List getParents() { return this.parents; } - void setParents(List parents) { + public void setParents(List parents) { this.parents = parents; } - void addParents(List parents) { + public void addParents(List parents) { for (PathNode pn : parents) { addParent(pn); } diff --git a/src/main/java/com/redhat/trie/PathTree.java b/src/main/java/com/redhat/trie/PathTree.java index ab0e301..5812ba7 100644 --- a/src/main/java/com/redhat/trie/PathTree.java +++ b/src/main/java/com/redhat/trie/PathTree.java @@ -34,6 +34,8 @@ import java.util.zip.Deflater; import java.util.zip.DeflaterOutputStream; import java.util.zip.DataFormatException; +import org.apache.log4j.Logger; + /** * PathTree * @@ -42,6 +44,7 @@ import java.util.zip.DataFormatException; * TODO - this is a prototype stub */ public class PathTree { + private static org.apache.log4j.Logger log = Logger.getLogger(PathTree.class); private List nodeDictionary; private List pathDictionary; private StringBuffer nodeBits; // TODO make a smart getter for this @@ -303,6 +306,40 @@ public class PathTree { * TODO - this is a stub */ public boolean validate(String contentPath) { + StringTokenizer st = new StringTokenizer(contentPath, "/"); + PathNode root; + PathNode pn; + String curTok; + + try { + root = this.getRootPathNode(); + } catch (PayloadException ex) { + log.error(ex); + return false; + } + + pn = root; + while (st.hasMoreTokens()) { + curTok = st.nextToken(); + + for (NodePair np : pn.getChildren()) { + if (curTok.equals(np.getName()) || np.getName().startsWith("$")) { + //System.out.println("[" + curTok + "] == [" + np.getName() + "]"); + if (np.getConnection().getChildren().size() == 0) { + return true; + } + + pn = np.getConnection(); + break; + } + } + // XXX do hot stuff + } + + return false; + } + + private boolean matches(PathNode pn, StringTokenizer st) { return false; } @@ -321,7 +358,7 @@ public class PathTree { this.pathNodeContext = new NodeContext(); this.huffNodeContext = new NodeContext(); - PathNode treeRoot = makePathTree(contentSets, new PathNode()); + PathNode treeRoot = PathTree.makePathTree(contentSets, new PathNode()); List nodeStrings = orderStrings(treeRoot); if (nodeStrings.size() == 0) { this.payload = new byte[0]; @@ -358,13 +395,14 @@ public class PathTree { * @param parent a PathNode, will be the root node, to be populated * @return is the same object as the parent param */ - public PathNode makePathTree(List contents, PathNode parent) { + public static PathNode makePathTree(List contents, PathNode parent) { PathNode endMarker = new PathNode(new NodeContext()); for (String path : contents) { StringTokenizer st = new StringTokenizer(path, "/"); - this.makePathForURL(st, parent, endMarker); + PathTree.makePathForURL(st, parent, endMarker); } - this.condenseSubTreeNodes(endMarker); + //log.debug("would run condenseSubTreeNodes()"); + //this.condenseSubTreeNodes(endMarker); return parent; } @@ -754,7 +792,7 @@ public class PathTree { * given a tokenized URL path, build out the PathNode parent, * and append endMarker to terminal nodes. */ - private void makePathForURL(StringTokenizer st, PathNode parent, PathNode endMarker) { + private static void makePathForURL(StringTokenizer st, PathNode parent, PathNode endMarker) { if (st.hasMoreTokens()) { String childVal = st.nextToken(); if (childVal.equals("")) { @@ -765,7 +803,7 @@ public class PathTree { for (NodePair child : parent.getChildren()) { if (child.getName().equals(childVal) && !child.getConnection().equals(endMarker)) { - this.makePathForURL(st, child.getConnection(), endMarker); + PathTree.makePathForURL(st, child.getConnection(), endMarker); isNew = false; } } @@ -775,7 +813,7 @@ public class PathTree { next = new PathNode(parent.getContext()); parent.addChild(new NodePair(childVal, next)); next.addParent(parent); - this.makePathForURL(st, next, endMarker); + PathTree.makePathForURL(st, next, endMarker); } else { parent.addChild(new NodePair(childVal, endMarker)); if (!endMarker.getParents().contains(parent)) { diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 0000000..8967405 --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,17 @@ +# Define the root logger with appender file +#log = /usr/home/log4j +log4j.rootLogger = DEBUG, stderr + +log4j.appender.stderr= org.apache.log4j.ConsoleAppender +#log4j.appender.stderr.Threshold=DEBUG +log4j.appender.stderr.target=System.err +log4j.appender.stderr.layout=org.apache.log4j.PatternLayout +log4j.appender.stderr.layout.ConversionPattern=%d{ISO8601} %5p [%t] %c -- %m%n + +# Define the file appender +#log4j.appender.FILE=org.apache.log4j.FileAppender +#log4j.appender.FILE.File=${log}/log.out + +# Define the layout for file appender +#log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +#log4j.appender.FILE.layout.conversionPattern=%m%n diff --git a/src/test/java/com/redhat/trie/TestPathNode.java b/src/test/java/com/redhat/trie/TestPathNode.java index d8bcda0..443c440 100644 --- a/src/test/java/com/redhat/trie/TestPathNode.java +++ b/src/test/java/com/redhat/trie/TestPathNode.java @@ -1,6 +1,7 @@ package com.redhat.trie; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertNotNull; import org.junit.Test; @@ -19,5 +20,34 @@ public class TestPathNode { assertNotNull(pn); } + @Test + public void testEquivalent() { + NodeContext ctx0 = new NodeContext(); + NodeContext ctx1 = new NodeContext(); + PathNode endMarker = new PathNode(); + PathNode pn0 = new PathNode(ctx0); + PathNode pn1 = new PathNode(ctx1); + + assertTrue(pn0.isEquivalentTo(pn1)); + + + NodePair np0a = new NodePair("foo",endMarker); + pn0.addChild(np0a); + NodePair np1a = new NodePair("foo",endMarker); + pn1.addChild(np1a); + + assertTrue(pn0.isEquivalentTo(pn1)); + + + PathNode pn2 = new PathNode(pn0.getContext()); + PathNode pn3 = new PathNode(pn1.getContext()); + NodePair np0b = new NodePair("bar",endMarker); + pn0.addChild(np0b); + NodePair np1b = new NodePair("baz",endMarker); + pn1.addChild(np1b); + + // XXX finish this test !! + //assertTrue(pn0.isEquivalentTo(pn1)); + } } diff --git a/src/test/java/com/redhat/trie/TestPathTree.java b/src/test/java/com/redhat/trie/TestPathTree.java index acf21cc..a0af0bf 100644 --- a/src/test/java/com/redhat/trie/TestPathTree.java +++ b/src/test/java/com/redhat/trie/TestPathTree.java @@ -51,6 +51,31 @@ public class TestPathTree { assertNotNull(pt); } + @Test + public void testRootNode() { + PathTree pt = new PathTree(); + List contents = loadContents("contents.list"); + try { + pt.setContentSets(contents); + } catch (PayloadException ex) { + fail(ex.toString()); + } + + // generate the root PathNode + try { + assertNotNull(pt.getRootPathNode()); + } catch (PayloadException ex) { + fail(ex.toString()); + } + + // do it again, to make sure it was not a mistake + try { + assertNotNull(pt.getRootPathNode()); + } catch (PayloadException ex) { + fail(ex.toString()); + } + } + @Test public void testThereAndBackAgainPayload() { byte[] bytes;