Author: bdelacretaz
Date: Thu Nov 20 06:05:03 2008
New Revision: 719230
URL: http://svn.apache.org/viewvc?rev=719230&view=rev
Log:
SLING-740 - javashell sample
Added:
incubator/sling/trunk/samples/javashell/ (with props)
incubator/sling/trunk/samples/javashell/README.txt (with props)
incubator/sling/trunk/samples/javashell/pom.xml (with props)
incubator/sling/trunk/samples/javashell/src/
incubator/sling/trunk/samples/javashell/src/main/
incubator/sling/trunk/samples/javashell/src/main/resources/
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/code-templates.jcr.xml
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp
(with props)
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
(with props)
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp
(with props)
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp
(with props)
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/sling-logo.png
(with props)
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml
(with props)
Propchange: incubator/sling/trunk/samples/javashell/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Nov 20 06:05:03 2008
@@ -0,0 +1,10 @@
+target
+bin
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
Added: incubator/sling/trunk/samples/javashell/README.txt
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/README.txt?rev=719230&view=auto
==============================================================================
--- incubator/sling/trunk/samples/javashell/README.txt (added)
+++ incubator/sling/trunk/samples/javashell/README.txt Thu Nov 20 06:05:03 2008
@@ -0,0 +1,37 @@
+----------------------
+Sling javashell sample
+----------------------
+
+This sample application executes java code entered in an HTML form,
+by generating and compiling java servlets on the fly.
+
+In its first version (2008/11/20), javashell contains a number of
+JCR code snippets, under /content/javashell/scripts. We might want
+to extend this to more Sling-specific samples, but for now I just
+needed that for an interactive JCR presentation.
+
+To test this bundle:
+
+1. Install the org.apache.sling.scripting.java bundle, found under
+ sling/scripting/java.
+
+2. Install this bundle and navigate to
+
+ http://localhost:8888/content/javashell/scripts/first_example.html
+
+ That page should include a "Result of execution" section which lists
+ some properties and child nodes.
+
+ If you get an AccessDeniedException you need to set "allow anonymous
+ access" to false in the SlingAuthenticator config, via
+ http://localhost:8888/system/console/configMgr
+
+ If you get the default HTML rendering under the "Result of execution"
+ header, the scripting.java bundle is probably not active.
+
+3. The above page includes links to edit the java code, and create new
+ pages with more code to execute.
+
+The servlets are generated under /apps/javashell/servlets, and are *not*
+cleaned up currently, this is something that should be improved.
+
\ No newline at end of file
Propchange: incubator/sling/trunk/samples/javashell/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/sling/trunk/samples/javashell/pom.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/pom.xml?rev=719230&view=auto
==============================================================================
--- incubator/sling/trunk/samples/javashell/pom.xml (added)
+++ incubator/sling/trunk/samples/javashell/pom.xml Thu Nov 20 06:05:03 2008
@@ -0,0 +1,82 @@
+<?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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>4-incubator-SNAPSHOT</version>
+ <relativePath>../../../parent/pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.sling.samples</groupId>
+ <artifactId>org.apache.sling.samples.javashell</artifactId>
+ <packaging>bundle</packaging>
+ <version>2.0.3-incubator-SNAPSHOT</version>
+
+ <name>Sling - Javashell sample</name>
+ <description>
+ Sample applications that executes java code snippets
+ defined by content nodes, includes a simple editing form.
+ </description>
+
+ <scm>
+
<connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/samples/javashell</connection>
+
<developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/samples/javashell</developerConnection>
+
<url>http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell</url>
+ </scm>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Sling-Initial-Content>
+ initial-content
+ </Sling-Initial-Content>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <configuration>
+ <excludePackageNames>
+ org.apache.sling.samples.webloader.internal
+ </excludePackageNames>
+ </configuration>
+ </plugin>
+ </plugins>
+ </reporting>
+
+ <dependencies/>
+</project>
Propchange: incubator/sling/trunk/samples/javashell/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/code-templates.jcr.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/code-templates.jcr.xml?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/code-templates.jcr.xml
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/code-templates.jcr.xml
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,75 @@
+<?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.
+-->
+<sv:node xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
xmlns:crx="http://www.day.com/crx/1.0"
xmlns:vlt="http://www.day.com/jcr/vault/1.0"
+ xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ sv:name="code-templates">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>
+ package _SERVLET_PACKAGE_;
+ import java.io.IOException;
+ import java.io.PrintWriter;
+ import javax.servlet.ServletException;
+ import org.apache.sling.api.SlingHttpServletRequest;
+ import org.apache.sling.api.SlingHttpServletResponse;
+ import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+ import javax.jcr.*;
+ import javax.jcr.lock.*;
+ import javax.jcr.nodetype.*;
+ import javax.jcr.observation.*;
+ import javax.jcr.query.*;
+ import javax.jcr.util.*;
+ import javax.jcr.version.*;
+
+ /** Servlet template for javashell - make sure to keep the _MARKERS_
+ * (package, class name, user code location) if modifying this template.
+ */
+ public class _SERVLET_CLASS_ extends SlingSafeMethodsServlet {
+ private static int counter;
+
+ protected String getRequestParameter(SlingHttpServletRequest request,
String name, String defaultValue) {
+ String result = request.getParameter(name);
+ if(result == null || result.trim().length() == 0) {
+ result = defaultValue;
+ }
+ return result;
+ }
+
+ protected void doGet(SlingHttpServletRequest request,
SlingHttpServletResponse response)
+ throws ServletException, IOException {
+ response.setContentType("text/html");
+ final PrintWriter out = new PrintWriter(response.getWriter(), true);
+ try {
+ // Provide a session and a newly created test root node for the user
code
+ Session session =
request.getResource().adaptTo(Node.class).getSession();
+ final String testRootName = "testroot-" + System.currentTimeMillis()
+ "-" + (counter++);
+ final Node testRoot =
((Node)session.getItem("/content/javashell/testroot")).addNode(testRootName);
+ // _USER_CODE_
+ } catch(Exception e) {
+ throw new ServletException("Exception in javashell servlet:" + e,
e);
+ }
+ }
+ }
+ </sv:value>
+ </sv:property>
+</sv:node>
\ No newline at end of file
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,78 @@
+<% /*
+ 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.
+*/ %>
+
+<%
+// A resource path ending with /* indicates that
+// we are creating a new node, an not editing an
+// existing one
+var path = resource.getPath();
+var creating = path.match("/\\*" + "$") == "/*";
+
+// Get current node values for editing
+var title = currentNode.title ? currentNode.title : "";
+var code = currentNode.code ? currentNode.code : "";
+var pageTitle = creating ? "Create a new javashell script" : "Editing: " +
title;
+
+// Default values, if creating a new node
+if(creating) {
+ code = 'out.println("Hello, javashell world!");';
+}
+%>
+
+<html>
+<head>
+ <title><%= pageTitle %></title>
+ <link rel="stylesheet" type="text/css" href="/apps/javashell/javashell.css"/>
+</head>
+<body>
+
+<div class="title">
+ <div class="logo">
+ <a href="http://incubator.apache.org/sling">
+ <img border="0" src="/apps/javashell/sling-logo.png"/>
+ </a>
+ </div>
+</div>
+
+<div class="menu">
+ <ul>
+ <% if(!creating) { load("siblings.esp"); } %>
+ </ul>
+</div>
+
+<div class="main">
+<h1><%= pageTitle %></h1>
+<form method="POST">
+<input type="submit" value="Save and execute"/>
+<br/>
+Title:
+<br/>
+<input type="text" size="80" style="width:100%" name="title" value="<%= title
%>"/>
+<br/>
+Code:
+<br/>
+<textarea rows="30" cols="80" name="code" style="width:100%"><%= code
%></textarea>
+<br/>
+<input type="submit" value="Save and execute"/>
+<input type="hidden" name=":redirect" value="*.html"/>
+</form>
+
+</div>
+</body>
+</html>
\ No newline at end of file
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/edit.esp
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+/* @override http://incubator.apache.org/sling/site/media.data/site.css */
+
+body { background-color: #ffffff; color: #3b3b3b; font-family: Tahoma, Arial,
sans-serif; font-size: 10pt; line-height: 140% }
+h1, h2, h3, h4, h5, h6 { font-weight: normal; color: #000000; line-height:
100%; }
+h1 { font-size: 200% }
+h2 { font-size: 175% }
+h3 { font-size: 150% }
+h4 { font-size: 140% }
+h5 { font-size: 130% }
+h6 { font-size: 120% }
+a { color: #1980af }
+a:visited { color: #1980af }
+a:hover { color: #1faae9 }
+.title { position: absolute; left: 1px; right: 1px; top:25px; height: 81px;
background: url(http://incubator.apache.org/sling/site/media.data/gradient.png)
repeat-x; background-position: bottom; }
+.logo { position: absolute; width: 15em; height: 81px; text-align: center; }
+.header { text-align: right; margin-right: 20pt; }
+.menu { border-top: 10px solid #f9bb00; position: absolute; top: 107px; left:
1px; width: 15em; bottom: 0px; padding: 0px; background-color: #fcfcfc }
+.menu ul { background-color: #fdf5d9; list-style: none; padding-left: 4em;
margin-top: 0px; padding-top: 2em; padding-bottom: 2em; margin-left: 0px;
color: #4a4a43}
+.menu a { text-decoration: none; color: #4a4a43 }
+.main { position: absolute; border-top: 10px solid #cde0ea; top: 107px; left:
15em; right: 1px; margin-left: 2px; padding-right: 4em; padding-left: 1em;
padding-top: 1em;}
+.code { color: black; background-color: #eeeeee; border: solid 1px black;
margin-top: 0.5em; margin-bottom: 0.5em; }
+.codeHeader { text-align: center; font-family: monospace; border-bottom:1px
solid black; padding-top: 0.5em; padding-bottom: 0.5em; margin-bottom: 0.5em; }
+.codeContent { padding: 0.5em }
+.codeContent pre { margin: 0em }
+.code-keyword { color: #880000 }
+.code-quote { color: #008800 }
+.code-object { color: #0000dd }
+.code-java { margin: 0em }
+.preformatted { color: black; background-color: #eeeeee; border: solid 1px
black; padding: 0.5em }
+.preformattedContent pre { margin: 0em }
+table.confluenceTable { border-collapse:collapse; margin:5px; }
+table.confluenceTable th.confluenceTh { background-color:#FDF5D9; border:1px
solid #CCCCCC; padding:3px 4px; text-align:center; }
+table.confluenceTable td.confluenceTd { border:1px solid #CCCCCC; padding:3px
4px; }
+.infoMacro { background-color: #D8E4F1; border: 1px solid #3C78B5; }
+.noteMacro { background-color: #FFFFCE; border: 1px solid #F0C000; }
+.tipMacro { background-color: #DDFFDD; border: 1px solid #009900; }
+.warningMacro { background-color: #FFCCCC; border: 1px solid #CC0000; }
+.note { font-size: 80%; }
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.css
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,100 @@
+<% /*
+ 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.
+*/ %>
+
+<%
+// TODO - this code really belongs to a java service that
+// would generate and serve the servlet code
+var title = "javashell: " + currentNode.title;
+var servletFolderName = "servlets";
+function trim(str) {
+ return str.replace(/^\s+|\s+$/g, '') ;
+}
+
+// Unique ID for the servlet that we're creating
+var servlet = {};
+servlet.id = "servlet" + Packages.java.lang.System.currentTimeMillis() +
Math.floor(Math.random() * 999999999);
+servlet.pkg = "apps.javashell." + servletFolderName;
+
+// Get code-template node
+var nodeClass = Packages.javax.jcr.Node;
+var scriptNode = sling.getScript().getScriptResource().adaptTo(nodeClass);
+var scriptFolderNode = scriptNode.getParent();
+var codeTemplate = scriptFolderNode.getNode("code-templates");
+
+// Inject currentNode.code into code template
+servlet.info = "// code template is at " + codeTemplate.getPath() + "/code";
+servlet.code = servlet.info + codeTemplate.getProperty("code").getString();
+servlet.code = servlet.code.replace("_SERVLET_PACKAGE_", servlet.pkg);
+servlet.code = servlet.code.replace("_SERVLET_CLASS_", servlet.id);
+servlet.code = servlet.code.replace("// _USER_CODE_", currentNode.code + "");
+
+// Save servlet.java code
+var servletFolder;
+if(scriptFolderNode.hasNode(servletFolderName)) {
+ servletFolder = scriptFolderNode.getNode(servletFolderName);
+} else {
+ servletFolder = scriptFolderNode.addNode(servletFolderName,
"nt:unstructured");
+}
+var servletNodeName = servlet.id + ".java";
+var fileNode = servletFolder.addNode(servletNodeName,"nt:file");
+var contentNode = fileNode.addNode("jcr:content", "nt:unstructured");
+var codeStream = new Packages.java.io.ByteArrayInputStream(new
java.lang.String(servlet.code).getBytes());
+contentNode.setProperty("jcr:data", codeStream);
+contentNode.setProperty("jcr:mimeType", "text/plain");
+contentNode.setProperty("jcr:lastModified", java.util.Calendar.getInstance());
+scriptFolderNode.save();
+%>
+
+<html>
+<head>
+ <title><%= title %></title>
+ <link rel="stylesheet" type="text/css" href="/apps/javashell/javashell.css"/>
+</head>
+<body>
+
+<div class="title">
+ <div class="logo">
+ <a href="http://incubator.apache.org/sling">
+ <img border="0" src="/apps/javashell/sling-logo.png"/>
+ </a>
+ </div>
+</div>
+
+<div class="menu">
+ <ul>
+ <li>
+ <b><a href="<%= currentNode.getPath() %>.edit.html">Edit script</a></b>
+ </li>
+ <li>
+ <b><a href="<%= currentNode.getParent().getPath() %>/*.edit.html">Create
new script</a></b>
+ </li>
+ <% load("siblings.esp"); %>
+ </ul>
+</div>
+
+<div class="main">
+ <h1><%= title %></h1>
+ <pre><%= trim(currentNode.code) %></pre>
+ <p class="note">The <a href="<%= fileNode.getPath() %>">complete source
code</a> of the generated servlet is available.</p>
+
+ <h2>Result of execution</h2>
+ <pre><% sling.include(currentNode.getPath(), "replaceSelectors=" +
servlet.id + ", forceResourceType=javashell/" + servletFolderName); %></pre>
+</div>
+</body>
+</html>
\ No newline at end of file
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/javashell.esp
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,31 @@
+<% /*
+ 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.
+*/ %>
+
+<%
+// Generate links to siblings of current node
+var siblings = currentNode.getParent().getNodes();
+for(var i in siblings) {
+ var n = siblings[i];
+ %>
+ <li>
+ <a href="<%= n.getPath() %>.html"><%= n.getProperty("title").getString()
%></a>
+ </li>
+ <%
+}
+%>
\ No newline at end of file
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/siblings.esp
------------------------------------------------------------------------------
svn:executable = *
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/sling-logo.png
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/sling-logo.png?rev=719230&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/sling-logo.png
------------------------------------------------------------------------------
svn:executable = *
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/apps/javashell/sling-logo.png
------------------------------------------------------------------------------
svn:mime-type = image/png
Added:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml?rev=719230&view=auto
==============================================================================
---
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml
(added)
+++
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml
Thu Nov 20 06:05:03 2008
@@ -0,0 +1,251 @@
+<?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.
+-->
+<sv:node xmlns:nt="http://www.jcp.org/jcr/nt/1.0" xmlns:rep="internal"
xmlns:crx="http://www.day.com/crx/1.0"
xmlns:vlt="http://www.day.com/jcr/vault/1.0"
+ xmlns:sv="http://www.jcp.org/jcr/sv/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
+ xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ sv:name="javashell">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="jcr:mixinTypes" sv:type="Name">
+ <sv:value>mix:lockable</sv:value>
+ </sv:property>
+ <sv:node sv:name="scripts">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:node sv:name="first_example">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>
+// Our entry point into to the JCR Repository is the "session"
+// object provided by javashell, which is a JCR Session.
+String nodePath = getRequestParameter(request, "path", "/");
+Node n = (Node)session.getItem(nodePath);
+
+out.println("List of property names of the " + n.getPath() + " Node:");
+PropertyIterator pi = n.getProperties();
+while(pi.hasNext()) {
+ Property p = pi.nextProperty();
+ out.println(p.getName());
+}
+
+out.println("\nList of child nodes of the " + n.getPath() + " Node:");
+NodeIterator ni = n.getNodes();
+while(ni.hasNext()) {
+ Node kid = ni.nextNode();
+ out.println(kid.getPath()
+ + " is of type " + kid.getPrimaryNodeType().getName()
+ + " and has " + kid.getNodes().getSize() + " child nodes."
+ );
+}
+</sv:value>
+ </sv:property>
+ <sv:property sv:name="sling:resourceType" sv:type="String">
+ <sv:value>javashell</sv:value>
+ </sv:property>
+ <sv:property sv:name="title" sv:type="String">
+ <sv:value>First example</sv:value>
+ </sv:property>
+ </sv:node>
+ <sv:node sv:name="add_and_retrieve_nodes">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>
+// The testRoot node is available for our tests, unique for each request
+out.println("Test root node is at " + testRoot.getPath());
+out.println("Adding child nodes to testRoot");
+for(int i=0; i < 5; i++) {
+ Node n = testRoot.addNode("node_" + i);
+ n.setProperty("title", "title_" + i);
+}
+
+// Without this, testRoot won't be saved, but the example still works
+// as data is read from the transient space.
+session.save();
+
+out.println("Retrieving child nodes of testRoot...");
+NodeIterator it = testRoot.getNodes();
+while(it.hasNext()) {
+ Node n = it.nextNode();
+ out.println(n.getPath() + " (" + n.getProperty("title").getString() + ")");
+}
+
+out.println("testRoot node has " + testRoot.getNodes().getSize() + " child
nodes, deleting them...");
+it = testRoot.getNodes();
+while(it.hasNext()) {
+ it.nextNode().remove();
+}
+
+out.println("testRoot node now has " + testRoot.getNodes().getSize() + " child
nodes");
+</sv:value>
+</sv:property>
+<sv:property sv:name="title" sv:type="String">
+ <sv:value>Add/retrieve/delete</sv:value>
+</sv:property>
+
+</sv:node>
+ <sv:node sv:name="simple_sql_search">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>// javashell provides a JCR Session, use that to get the
QueryManager
+QueryManager qm = session.getWorkspace().getQueryManager();
+
+// SQL query
+String statement = "select * from nt:unstructured where jcr:path like
'/content/%/scripts/%'";
+String language = "sql";
+
+// Uncomment these two statements to use XPath instead
+// statement = "//content//scripts/element(*, nt:unstructured)";
+// language = "xpath";
+
+// Execute query and display results
+Query q = qm.createQuery(statement, language);
+NodeIterator it = q.execute().getNodes();
+out.println(it.getSize() + " nodes found");
+while(it.hasNext()) {
+ Node n = it.nextNode();
+ out.println(n.getPath());
+}</sv:value>
+ </sv:property>
+ <sv:property sv:name="sling:resourceType" sv:type="String">
+ <sv:value>javashell</sv:value>
+ </sv:property>
+ <sv:property sv:name="title" sv:type="String">
+ <sv:value>Simple SQL or XPath search</sv:value>
+ </sv:property>
+ </sv:node>
+
+ <sv:node sv:name="versioning">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>
+// Create versionable node, save and create version
+Node n = testRoot.addNode("childNode", "nt:unstructured");
+n.addMixin("mix:versionable");
+n.setProperty("phase", "one");
+session.save();
+Version firstVersion = n.checkin();
+
+// Add another version
+Node child = testRoot.getNode("childNode");
+child.checkout();
+child.setProperty("phase", "two");
+session.save();
+child.checkin();
+
+// Print version history
+VersionHistory history = child.getVersionHistory();
+for (VersionIterator it = history.getAllVersions(); it.hasNext();) {
+ Version version = (Version) it.next();
+ out.println("Version with timestamp " +
version.getCreated().getTime().getTime()
+ + " has " + version.getPredecessors().length + " predecessors"
+ + " and " + version.getSuccessors().length + " successors"
+ );
+}
+
+// Restore firstVersion
+child.checkout();
+out.println("before restore, child phase=" +
child.getProperty("phase").getString());
+child.restore(firstVersion, true);
+out.println("after restore, child phase=" +
child.getProperty("phase").getString());
+</sv:value>
+ </sv:property>
+ <sv:property sv:name="sling:resourceType" sv:type="String">
+ <sv:value>javashell</sv:value>
+ </sv:property>
+ <sv:property sv:name="title" sv:type="String">
+ <sv:value>Versioning</sv:value>
+ </sv:property>
+ </sv:node>
+
+ <sv:node sv:name="tagging">
+ <sv:property sv:name="jcr:primaryType" sv:type="Name">
+ <sv:value>nt:unstructured</sv:value>
+ </sv:property>
+ <sv:property sv:name="code" sv:type="String">
+ <sv:value>
+// Find nt:file nodes and add a multi-value "tag" property
+String dataPath = "/content/javashell/data";
+String [] possibleTags = { "culture", "sports", "news", "finance" };
+QueryManager qm = session.getWorkspace().getQueryManager();
+Query q = qm.createQuery("/" + dataPath + "//element(*, nt:file)", "xpath");
+NodeIterator it = q.execute().getNodes();
+if(it.getSize() == 0) {
+ out.println("Please add some files under " + dataPath + " for this example");
+} else {
+ int tagIndex = 0;
+ while(it.hasNext()) {
+ Node file = it.nextNode();
+ Node content = file.getNode("jcr:content");
+ if(content.hasProperty("tags")) {
+ out.print("File " + file.getPath() + " has tags ");
+ Value [] v = content.getProperty("tags").getValues();
+ for(int i=0; i < v.length; i++) {
+ if(i > 0) out.print(",");
+ out.print(v[i].getString());
+ }
+ out.println();
+ } else {
+ String mime = content.getProperty("jcr:mimeType").getString();
+ String mimePrefix = mime.split("/")[0];
+ String [] tags = { possibleTags[tagIndex], mimePrefix };
+ content.setProperty("tags", tags);
+ out.println("file " + file.getPath() + " tagged with " + tags[0] + "," +
tags[1]);
+ tagIndex++; if(tagIndex >= possibleTags.length) tagIndex=0;
+ }
+ }
+}
+
+// Indexing happens only on save, and asynchronously
+// So sleeping is really a hack for this test
+session.save();
+Thread.sleep(1000L);
+
+// Find tagged files
+String tag = getRequestParameter(request, "tag", possibleTags[0]);
+String statement = "/" + dataPath + "//element(*,
nt:file)[jcr:content/@tags='" + tag + "']";
+out.println("Searching for tag '" + tag + "', " + statement);
+q = qm.createQuery(statement, "xpath");
+it = q.execute().getNodes();
+while(it.hasNext()) {
+ Node file = it.nextNode();
+ out.println("Found file " + file.getPath());
+}
+</sv:value>
+ </sv:property>
+ <sv:property sv:name="sling:resourceType" sv:type="String">
+ <sv:value>javashell</sv:value>
+ </sv:property>
+ <sv:property sv:name="title" sv:type="String">
+ <sv:value>Tagging files</sv:value>
+ </sv:property>
+ </sv:node>
+
+</sv:node><sv:node sv:name="testroot"><sv:property sv:name="jcr:primaryType"
sv:type="Name"><sv:value>nt:unstructured</sv:value></sv:property><sv:property
sv:name="jcr:mixinTypes"
sv:type="Name"><sv:value>mix:lockable</sv:value></sv:property></sv:node>
+</sv:node>
\ No newline at end of file
Propchange:
incubator/sling/trunk/samples/javashell/src/main/resources/initial-content/content/javashell.jcr.xml
------------------------------------------------------------------------------
svn:eol-style = native