[jboss-svn-commits] JBL Code SVN: r5941 - in labs/shotoku/trunk: . shotoku-example shotoku-example/src shotoku-example/src/java shotoku-example/src/java/org shotoku-example/src/java/org/jboss shotoku-example/src/java/org/jboss/shotoku shotoku-example/src/java/org/jboss/shotoku/example shotoku-example/src/web shotoku-example/src/web/WEB-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Aug 18 10:00:33 EDT 2006
Author: adamw
Date: 2006-08-18 10:00:29 -0400 (Fri, 18 Aug 2006)
New Revision: 5941
Added:
labs/shotoku/trunk/shotoku-example/
labs/shotoku/trunk/shotoku-example/maven.xml
labs/shotoku/trunk/shotoku-example/project.properties
labs/shotoku/trunk/shotoku-example/project.xml
labs/shotoku/trunk/shotoku-example/shotoku-example.iml
labs/shotoku/trunk/shotoku-example/src/
labs/shotoku/trunk/shotoku-example/src/java/
labs/shotoku/trunk/shotoku-example/src/java/org/
labs/shotoku/trunk/shotoku-example/src/java/org/jboss/
labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/
labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/example/
labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/example/ExampleEmbedded.java
labs/shotoku/trunk/shotoku-example/src/web/
labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/
labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/jboss-web.xml
labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/web.xml
Log:
Shotoku example
Property changes on: labs/shotoku/trunk/shotoku-example
___________________________________________________________________
Name: svn:ignore
+ target
Added: labs/shotoku/trunk/shotoku-example/maven.xml
===================================================================
--- labs/shotoku/trunk/shotoku-example/maven.xml 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/maven.xml 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,16 @@
+<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:u="jelly:util">
+ <goal name="build">
+ </goal>
+
+ <goal name="deploy">
+ </goal>
+
+ <goal name="clean">
+ </goal>
+
+ <goal name="all">
+ <attainGoal name="clean" />
+ <attainGoal name="build" />
+ <attainGoal name="deploy" />
+ </goal>
+</project>
Added: labs/shotoku/trunk/shotoku-example/project.properties
===================================================================
--- labs/shotoku/trunk/shotoku-example/project.properties 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/project.properties 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,4 @@
+maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/
+
+maven.final.name=${pom.artifactId}
+
Added: labs/shotoku/trunk/shotoku-example/project.xml
===================================================================
--- labs/shotoku/trunk/shotoku-example/project.xml 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/project.xml 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,32 @@
+<?xml version='1.0' encoding='ISO-8859-1'?>
+<project>
+ <pomVersion>3</pomVersion>
+ <extend>../project.xml</extend>
+ <id>shotoku-example</id>
+ <name>Shotoku example</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>shotoku</groupId>
+ <artifactId>shotoku-base</artifactId>
+ <jar>shotoku-base.jar</jar>
+ </dependency>
+
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>javax.servlet</artifactId>
+ <version>1.0</version>
+ <jar>javax.servlet.jar</jar>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <sourceDirectory>src/java</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>src/etc</directory>
+ <include>**/*</include>
+ </resource>
+ </resources>
+ </build>
+</project>
Added: labs/shotoku/trunk/shotoku-example/shotoku-example.iml
===================================================================
--- labs/shotoku/trunk/shotoku-example/shotoku-example.iml 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/shotoku-example.iml 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="true" type="JAVA_MODULE">
+ <component name="ModuleRootManager" />
+ <component name="NewModuleRootManager">
+ <output url="file://$MODULE_DIR$/target" />
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="module" module-name="shotoku-base" />
+ <orderEntry type="library" name="jboss" level="application" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../shotoku-base/target/shotoku-base.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntry type="module" module-name="shotoku-svn" />
+ <orderEntry type="module-library">
+ <library>
+ <CLASSES>
+ <root url="jar://$MODULE_DIR$/../shotoku-svn/target/shotoku-svn.jar!/" />
+ </CLASSES>
+ <JAVADOC />
+ <SOURCES />
+ </library>
+ </orderEntry>
+ <orderEntryProperties />
+ </component>
+</module>
+
Added: labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/example/ExampleEmbedded.java
===================================================================
--- labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/example/ExampleEmbedded.java 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/src/java/org/jboss/shotoku/example/ExampleEmbedded.java 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,288 @@
+package org.jboss.shotoku.example;
+
+import org.jboss.shotoku.*;
+import org.jboss.shotoku.exceptions.ResourceDoesNotExist;
+import org.jboss.shotoku.exceptions.ResourceAlreadyExists;
+import org.jboss.shotoku.exceptions.NameFormatException;
+import org.jboss.shotoku.exceptions.SaveException;
+
+import java.util.Set;
+import java.util.List;
+import java.util.Map;
+import java.util.HashSet;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+/**
+ * @author Adam Warski (adamw at aster.pl)
+ */
+public class ExampleEmbedded {private ContentManager cm;
+ private Set<Node> openNodes;
+ private Set<Directory> openDirectories;
+
+ public ExampleEmbedded() {
+ // Initializing with the default content manager.
+ cm = ContentManager.getContentManager();
+
+ openNodes = new HashSet<Node>();
+ openDirectories = new HashSet<Directory>();
+ }
+
+ /**
+ * Changes the content manager to a one with the given id (should be
+ * one of the specified in shotoku.properties) and prefix (a path to
+ * which all other used paths will be relative).
+ * @param id
+ * @param prefix
+ */
+ public void changeContentManager(String id, String prefix) {
+ ContentManager newCm = ContentManager.getContentManager(id, prefix);
+ if (newCm == null) {
+ System.out.println("No content manager with id: " + id + ".");
+ } else {
+ // Clearing any existing modifications.
+ openDirectories.clear();
+ openNodes.clear();
+
+ cm = newCm;
+ System.out.println("Content manager changed to (" + id +
+ ", " + prefix + ").");
+ }
+
+ System.out.println("---");
+ System.out.println();
+ }
+
+ /**
+ * Reads a list of nodes which are contained in a directory
+ * with the given path and prints their names.
+ * @param path
+ * @throws org.jboss.shotoku.exceptions.ResourceDoesNotExist If path is not a directory.
+ */
+ public void listNodes(String path)
+ throws ResourceDoesNotExist {
+ NodeList nl = cm.getDirectory(path).getNodes();
+ System.out.println("Nodes in directory: " + path);
+ for (Node n : nl) {
+ System.out.println("- " + n.getName());
+ }
+ System.out.println("---");
+ System.out.println();
+ }
+
+ /**
+ * Reads a list of directories which are contained in a directory
+ * with the given path and prints their names.
+ * @param path
+ * @throws ResourceDoesNotExist If path is not a directory.
+ */
+ public void listDirectories(String path)
+ throws ResourceDoesNotExist {
+ List<Directory> dirs = cm.getDirectory(path).getDirectories();
+ System.out.println("Directories in directory: " + path);
+ for (Directory d : dirs) {
+ System.out.println("- " + d.getName());
+ }
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void listProperties(String path) throws ResourceDoesNotExist {
+ Resource res;
+ try {
+ res = cm.getNode(path);
+ } catch (ResourceDoesNotExist resourceDoesNotExist) {
+ res = cm.getDirectory(path);
+ }
+
+ System.out.println("Properties on path: " + path);
+ Map<String, String> props = res.getProperties();
+ for (String propName : props.keySet()) {
+ System.out.println("- " + propName + " = " + props.get(propName));
+ }
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void setNodeContent(String path, String content)
+ throws ResourceAlreadyExists, NameFormatException {
+ Node n;
+ try {
+ n = cm.getNode(path);
+ } catch (ResourceDoesNotExist resourceDoesNotExist) {
+ n = cm.getRootDirectory().newNode(path);
+ }
+
+ n.setContent(content);
+ openNodes.add(n);
+
+ System.out.println("Content of node " + path + " changed.");
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void setNodeProprety(String path, String name, String value)
+ throws ResourceAlreadyExists, NameFormatException {
+ Node n;
+ try {
+ n = cm.getNode(path);
+ } catch (ResourceDoesNotExist resourceDoesNotExist) {
+ n = cm.getRootDirectory().newNode(path);
+ }
+
+ n.setProperty(name, value);
+ openNodes.add(n);
+
+ System.out.println("Property " + name + " on node " + path +
+ " changed.");
+ System.out.println("No modifications will be done on the repository" +
+ " until the modified resources are saved.");
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void newDirectory(String path)
+ throws ResourceAlreadyExists, NameFormatException {
+ openDirectories.add(cm.getRootDirectory().newDirectory(path));
+
+ System.out.println("Directory " + path + " created.");
+ System.out.println("No modifications will be done on the repository" +
+ " until the modified resources are saved.");
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void saveAll(String logMessage) throws SaveException {
+ Set<Resource> toSave = new HashSet<Resource>();
+ toSave.addAll(openDirectories);
+ toSave.addAll(openNodes);
+ cm.save(logMessage, toSave);
+
+ openDirectories.clear();
+ openNodes.clear();
+
+ System.out.println("All modified resource saved.");
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void discardAll() {
+ openDirectories.clear();
+ openNodes.clear();
+ System.out.println("All changes to resources discarded.");
+ System.out.println("---");
+ System.out.println();
+ }
+
+ public void listModifiedResources() {
+ System.out.println("Modified nodes:");
+ for (Node n : openNodes) {
+ System.out.println("- " + n.getName());
+ }
+ System.out.println();
+
+ System.out.println("Modified directories:");
+ for (Directory d : openDirectories) {
+ System.out.println("- " + d.getName());
+ }
+
+ System.out.println("---");
+ System.out.println();
+ }
+
+ /*
+ * ---
+ */
+
+ private static BufferedReader br =
+ new BufferedReader(new InputStreamReader(System.in));
+
+ private static String read(String name) throws IOException {
+ System.out.println("Please input " + name + ":");
+ return br.readLine();
+ }
+
+ public static void main(String[] argv) throws IOException {
+ System.out.println("Welcome to Shotoku example!");
+
+ ExampleEmbedded ee = new ExampleEmbedded();
+
+ while (true) {
+ System.out.println("Choose your action:");
+ System.out.println("1. Change ContentManager parameters");
+ System.out.println("2. List nodes in a directory");
+ System.out.println("3. List directories in a directory");
+ System.out.println("4. List resource properties");
+ System.out.println("5. Change node content");
+ System.out.println("6. Change node property");
+ System.out.println("7. Create new directory");
+ System.out.println("8. Save all modified resources");
+ System.out.println("9. List all modified resources");
+ System.out.println("10. Discard all modified resources");
+ System.out.println("11. Exit");
+
+ String choiceStr = br.readLine();
+ int choice;
+ try {
+ choice = Integer.parseInt(choiceStr);
+ } catch (NumberFormatException nfe) {
+ System.out.println("Invalid input.");
+ continue;
+ }
+
+ try {
+ switch (choice) {
+ case 1:
+ ee.changeContentManager(read("id"),
+ read("prefix"));
+ break;
+
+ case 2:
+ ee.listNodes(read("path"));
+ break;
+
+ case 3:
+ ee.listDirectories(read("path"));
+ break;
+
+ case 4:
+ ee.listProperties(read("path"));
+ break;
+
+ case 5:
+ ee.setNodeContent(read("path"), read("content"));
+ break;
+
+ case 6:
+ ee.setNodeProprety(read("path"), read("name"),
+ read("value"));
+ break;
+
+ case 7:
+ ee.newDirectory(read("path"));
+ break;
+
+ case 8:
+ ee.saveAll(read("log message"));
+ break;
+
+ case 9:
+ ee.listModifiedResources();
+ break;
+
+ case 10:
+ ee.discardAll();
+ break;
+
+ case 11:
+ System.out.println("Bye!");
+ System.exit(0);
+ }
+ } catch (Exception e) {
+ System.out.println("Exception " + e.getClass().getName() +
+ " caught, message: " + e.getMessage() + ".");
+ }
+ }
+ }
+}
Added: labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/jboss-web.xml
===================================================================
--- labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/jboss-web.xml 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/jboss-web.xml 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,8 @@
+<?xml version='1.0' encoding='UTF-8' ?>
+
+<!DOCTYPE jboss-web
+ PUBLIC "-//JBoss//DTD Web Application 2.3V2//EN"
+ "http://www.jboss.org/j2ee/dtd/jboss-web_3_2.dtd">
+
+<jboss-web>
+</jboss-web>
Added: labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/web.xml
===================================================================
--- labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/web.xml 2006-08-18 13:50:48 UTC (rev 5940)
+++ labs/shotoku/trunk/shotoku-example/src/web/WEB-INF/web.xml 2006-08-18 14:00:29 UTC (rev 5941)
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+ http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+</web-app>
More information about the jboss-svn-commits
mailing list