Permalink
Browse files

JCRSITE-30: First Hops Update

Patch by Alex Parvulescu

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/trunk@1079373 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 3f336df commit 3da8ebf213de923793214da1e8f2d0adbdf5250c @jukka jukka committed Mar 8, 2011
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-firsthops</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <name>First Hops</name>
+ <description>First Hops Example Page</description>
+ <url>http://jackrabbit.apache.org/first-hops.html</url>
+
+ <dependencies>
+
+ <!-- The JCR API -->
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <!-- Jackrabbit content repository -->
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ <version>2.2.4</version>
+ </dependency>
+
+ <!-- Use Log4J for logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.5.11</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <compilerVersion>1.5</compilerVersion>
+ <source>1.5</source>
+ <target>1.5</target>
+ <debug>true</debug>
+ <showDeprecation>false</showDeprecation>
+ <showWarnings>true</showWarnings>
+ <optimize>false</optimize>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
+
+
+
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.firsthops;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.core.TransientRepository;
+
+/**
+ * First hop example. Logs in to a content repository and prints a status
+ * message.
+ */
+public class FirstHop {
+
+ /**
+ * The main entry point of the example application.
+ *
+ * @param args
+ * command line arguments (ignored)
+ * @throws Exception
+ * if an error occurs
+ */
+ public static void main(String[] args) throws Exception {
+ Repository repository = new TransientRepository();
+ Session session = repository.login();
+ try {
+ String user = session.getUserID();
+ String name = repository.getDescriptor(Repository.REP_NAME_DESC);
+ System.out.println("Logged in as " + user + " to a " + name
+ + " repository.");
+ } finally {
+ session.logout();
+ }
+ }
+}
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.firsthops;
+
+import javax.jcr.Repository;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Node;
+import org.apache.jackrabbit.core.TransientRepository;
+
+/**
+ * Second hop example. Stores, retrieves, and removes example content.
+ */
+public class SecondHop {
+
+ /**
+ * The main entry point of the example application.
+ *
+ * @param args
+ * command line arguments (ignored)
+ * @throws Exception
+ * if an error occurs
+ */
+ public static void main(String[] args) throws Exception {
+ Repository repository = new TransientRepository();
+ Session session = repository.login(new SimpleCredentials("username",
+ "password".toCharArray()));
+ try {
+ Node root = session.getRootNode();
+
+ // Store content
+ Node hello = root.addNode("hello");
+ Node world = hello.addNode("world");
+ world.setProperty("message", "Hello, World!");
+ session.save();
+
+ // Retrieve content
+ Node node = root.getNode("hello/world");
+ System.out.println(node.getPath());
+ System.out.println(node.getProperty("message").getString());
+
+ // Remove content
+ root.getNode("hello").remove();
+ session.save();
+ } finally {
+ session.logout();
+ }
+ }
+
+}
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.firsthops;
+
+import javax.jcr.*;
+import org.apache.jackrabbit.core.TransientRepository;
+import java.io.FileInputStream;
+
+/**
+ * Third Jackrabbit example application. Imports an example XML file and outputs
+ * the contents of the entire workspace.
+ */
+public class ThirdHop {
+
+ /**
+ * The main entry point of the example application.
+ *
+ * @param args
+ * command line arguments (ignored)
+ * @throws Exception
+ * if an error occurs
+ */
+ public static void main(String[] args) throws Exception {
+ Repository repository = new TransientRepository();
+ Session session = repository.login(new SimpleCredentials("username",
+ "password".toCharArray()));
+
+ FileInputStream xml = new FileInputStream("src/main/resources/test.xml");
+ try {
+ Node root = session.getRootNode();
+
+ // Import the XML file unless already imported
+ if (!root.hasNode("importxml")) {
+ System.out.print("Importing xml... ");
+ // Create an unstructured node under which to import the XML
+ Node node = root.addNode("importxml", "nt:unstructured");
+ // Import the file "test.xml" under the created node
+ session.importXML(node.getPath(), xml,
+ ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
+
+ session.save();
+ System.out.println("done.");
+ }
+
+ dump(root);
+ } finally {
+ session.logout();
+ }
+ }
+
+ /** Recursively outputs the contents of the given node. */
+ private static void dump(Node node) throws RepositoryException {
+ // First output the node path
+ System.out.println(node.getPath());
+ // Skip the virtual (and large!) jcr:system subtree
+ if (node.getName().equals("jcr:system")) {
+ return;
+ }
+
+ // Then output the properties
+ PropertyIterator properties = node.getProperties();
+ while (properties.hasNext()) {
+ Property property = properties.nextProperty();
+ if (property.getDefinition().isMultiple()) {
+ // A multi-valued property, print all values
+ Value[] values = property.getValues();
+ for (int i = 0; i < values.length; i++) {
+ System.out.println(property.getPath() + " = "
+ + values[i].getString());
+ }
+ } else {
+ // A single-valued property
+ System.out.println(property.getPath() + " = "
+ + property.getString());
+ }
+ }
+
+ // Finally output all the child nodes recursively
+ NodeIterator nodes = node.getNodes();
+ while (nodes.hasNext()) {
+ dump(nodes.nextNode());
+ }
+ }
+
+}
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+log4j.rootLogger=ERROR, Console
+
+log4j.appender.Console=org.apache.log4j.ConsoleAppender
+log4j.appender.Console.layout=org.apache.log4j.PatternLayout
+log4j.appender.Console.layout.ConversionPattern=%d %p %c - %m%n
@@ -0,0 +1,68 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
+ xmlns:mathml="http://www.w3.org/1998/Math/MathML">
+ <xhtml:head>
+ <xhtml:title>Three Namespaces</xhtml:title>
+ </xhtml:head>
+ <xhtml:body>
+ <xhtml:h1 align="center">An Ellipse and a Rectangle</xhtml:h1>
+ <svg:svg xmlns:svg="http://www.w3.org/2000/svg" width="12cm"
+ height="10cm">
+ <svg:ellipse rx="110" ry="130" />
+ <svg:rect x="4cm" y="1cm" width="3cm" height="6cm" />
+ </svg:svg>
+ <xhtml:p>The equation for ellipses</xhtml:p>
+ <mathml:math>
+ <mathml:apply>
+ <mathml:eq />
+ <mathml:cn> 1 </mathml:cn>
+ <mathml:apply>
+ <mathml:plus />
+ <mathml:apply>
+ <mathml:divide />
+ <mathml:apply>
+ <mathml:power />
+ <mathml:ci> x </mathml:ci>
+ <mathml:cn> 2 </mathml:cn>
+ </mathml:apply>
+ <mathml:apply>
+ <mathml:power />
+ <mathml:ci> a </mathml:ci>
+ <mathml:cn> 2 </mathml:cn>
+ </mathml:apply>
+ </mathml:apply>
+ <mathml:apply>
+ <mathml:divide />
+ <mathml:apply>
+ <mathml:power />
+ <mathml:ci> y </mathml:ci>
+ <mathml:cn> 2 </mathml:cn>
+ </mathml:apply>
+ <mathml:apply>
+ <mathml:power />
+ <mathml:ci> b </mathml:ci>
+ <mathml:cn> 2 </mathml:cn>
+ </mathml:apply>
+ </mathml:apply>
+ </mathml:apply>
+ </mathml:apply>
+ </mathml:math>
+ <xhtml:hr />
+ <xhtml:p>Last Modified January 10, 2002</xhtml:p>
+ </xhtml:body>
+</xhtml:html>

0 comments on commit 3da8ebf

Please sign in to comment.