Author: cziegeler
Date: Fri Jul 17 06:16:52 2009
New Revision: 794977
URL: http://svn.apache.org/viewvc?rev=794977&view=rev
Log:
Experimental class loader writer for scripting engines.
Added:
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
(with props)
Modified:
sling/trunk/bundles/jcr/classloader/pom.xml
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderProviderImpl.java
sling/trunk/bundles/scripting/jsp/pom.xml
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties
Added:
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java?rev=794977&view=auto
==============================================================================
---
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
(added)
+++
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
Fri Jul 17 06:16:52 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.sling.commons.classloader;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * The class loader writer allows to modify the resources loaded by a
+ * {...@link DynamicClassLoaderProvider}. For example a class loader writer
+ * could write generated class files into the repository or the temporary
+ * file system.
+ */
+public interface ClassLoaderWriter {
+
+ OutputStream getOutputStream(String name);
+
+ InputStream getInputStream(String name) throws IOException;
+
+ long getLastModified(String name);
+
+ boolean delete(String name);
+
+ boolean rename(String oldName, String newName);
+}
Propchange:
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
------------------------------------------------------------------------------
svn:keywords = author date id revision rev url
Propchange:
sling/trunk/bundles/commons/classloader/src/main/java/org/apache/sling/commons/classloader/ClassLoaderWriter.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sling/trunk/bundles/jcr/classloader/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/pom.xml?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/classloader/pom.xml (original)
+++ sling/trunk/bundles/jcr/classloader/pom.xml Fri Jul 17 06:16:52 2009
@@ -99,6 +99,11 @@
<version>0.9.0-SNAPSHOT</version>
</dependency>
<dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.mime</artifactId>
+ <version>2.1.0-incubator</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-classloader</artifactId>
<version>1.4.1</version>
Modified:
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
(original)
+++
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderFacade.java
Fri Jul 17 06:16:52 2009
@@ -47,15 +47,6 @@
private String[] classPath;
private DynamicRepositoryClassLoader delegate;
- /**
- * The reference counter. If not greater than zero, there are this
- * number of (assumed) life references.
- *
- * @see #ref()
- * @see #deref()
- */
- private int refCtr = 0;
-
public RepositoryClassLoaderFacade(
RepositoryClassLoaderProviderImpl classLoaderProvider,
ClassLoader parent,
@@ -140,27 +131,6 @@
}
}
- /**
- * Increases the reference counter of this class loader.
- */
- /* package */void ref() {
- this.refCtr++;
- }
-
- /**
- * Decreases the reference counter of this class loader and calls the
- * base class <code>destroy()</code> method, if this class loader has
- * already been destroyed by calling the {...@link #destroy()} method.
- */
- /* package */void deref() {
- this.refCtr--;
-
- // destroy if the loader should be destroyed and no refs exist
-// if (refCtr <= 0 /* && destroyed */ ) {
-// destroy();
-// }
- }
-
//---------- internal -----------------------------------------------------
private Session getSession() throws RepositoryException {
@@ -197,4 +167,5 @@
return this.delegate;
}
+
}
Modified:
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderProviderImpl.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderProviderImpl.java?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderProviderImpl.java
(original)
+++
sling/trunk/bundles/jcr/classloader/src/main/java/org/apache/sling/jcr/classloader/internal/RepositoryClassLoaderProviderImpl.java
Fri Jul 17 06:16:52 2009
@@ -18,20 +18,33 @@
*/
package org.apache.sling.jcr.classloader.internal;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.util.Dictionary;
import java.util.Iterator;
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import org.apache.commons.collections.BidiMap;
import org.apache.commons.collections.bidimap.DualHashBidiMap;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.commons.classloader.DynamicClassLoaderProvider;
+import org.apache.sling.commons.mime.MimeTypeService;
import org.apache.sling.jcr.api.SlingRepository;
import org.apache.sling.jcr.classloader.RepositoryClassLoaderProvider;
import org.osgi.framework.Bundle;
import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The <code>RepositoryClassLoaderProviderImpl</code> TODO
@@ -44,7 +57,10 @@
* @scr.service servicefactory="true"
*/
public class RepositoryClassLoaderProviderImpl
- implements RepositoryClassLoaderProvider, DynamicClassLoaderProvider {
+ implements RepositoryClassLoaderProvider, DynamicClassLoaderProvider,
ClassLoaderWriter {
+
+ /** default log */
+ private static final Logger log =
LoggerFactory.getLogger(RepositoryClassLoaderFacade.class);
/**
* @scr.property values0="/var/classes"
@@ -74,6 +90,9 @@
private BundleProxyClassLoader parent;
+ /** @scr.reference policy="dynamic" */
+ private MimeTypeService mimeTypeService;
+
public ClassLoader getClassLoader(String owner) {
String classLoaderOwner = this.getClassLoaderOwner(owner);
RepositoryClassLoaderFacade loader =
@@ -84,17 +103,11 @@
this.loaders.put(classLoaderOwner, loader);
}
- // extend reference counter
- loader.ref();
-
return loader;
}
public void ungetClassLoader(ClassLoader classLoader) {
- if (classLoader instanceof RepositoryClassLoaderFacade) {
- RepositoryClassLoaderFacade cl = (RepositoryClassLoaderFacade)
classLoader;
- cl.deref();
- }
+ // nothing to do
}
//---------- Support for RepositoryClassLoaderFacade ----------------------
@@ -126,18 +139,289 @@
(RepositoryClassLoaderFacade) this.loaders.get(classLoaderOwner);
if (loader == null) {
loader = new RepositoryClassLoaderFacade(this, parent,
- OWNER_DEFAULT, this.classPath);
+ this.classLoaderOwner, this.classPath);
this.loaders.put(classLoaderOwner, loader);
}
- // extend reference counter
- loader.ref();
-
return loader;
}
//---------- SCR Integration ----------------------------------------------
+ /**
+ * @see
org.apache.sling.commons.classloader.ClassLoaderWriter#delete(java.lang.String)
+ */
+ public boolean delete(String name) {
+ name = cleanPath(name);
+ Node parentNode = null;
+ Session session = null;
+ try {
+ session = getSession(this.classLoaderOwner);
+ if (session.itemExists(name)) {
+ Item fileItem = session.getItem(name);
+ parentNode = fileItem.getParent();
+ fileItem.remove();
+ parentNode.save();
+ return true;
+ }
+ } catch (RepositoryException re) {
+ log.error("Cannot remove " + name, re);
+ } finally {
+ checkNode(parentNode, name);
+ if ( session != null ) {
+ session.logout();
+ }
+ }
+
+ // fall back to false if item does not exist or in case of error
+ return false;
+ }
+
+ /**
+ * @see
org.apache.sling.commons.classloader.ClassLoaderWriter#getOutputStream(java.lang.String)
+ */
+ public OutputStream getOutputStream(String name) {
+ final String path = cleanPath(name);
+ return new RepositoryOutputStream(this, path);
+ }
+
+ /**
+ * @see
org.apache.sling.commons.classloader.ClassLoaderWriter#rename(java.lang.String,
java.lang.String)
+ */
+ public boolean rename(String oldName, String newName) {
+ Session session = null;
+ try {
+ oldName = cleanPath(oldName);
+ newName = cleanPath(newName);
+
+ session = this.getSession(this.classLoaderOwner);
+ session.getWorkspace().move(oldName, newName);
+ return true;
+ } catch (RepositoryException re) {
+ log.error("Cannot rename " + oldName + " to " + newName, re);
+ } finally {
+ if ( session != null ) {
+ session.logout();
+ }
+ }
+
+ // fallback to false in case of error or non-existence of oldFileName
+ return false;
+ }
+
+ /**
+ * Creates a folder hierarchy in the repository.
+ */
+ private boolean mkdirs(final Session session, String path) {
+ Node parentNode = null;
+ try {
+ // quick test
+ if (session.itemExists(path) && session.getItem(path).isNode()) {
+ return true;
+ }
+
+ // check path walking it down
+ Node current = session.getRootNode();
+ String[] names = path.split("/");
+ for (int i = 0; i < names.length; i++) {
+ if (names[i] == null || names[i].length() == 0) {
+ continue;
+ } else if (current.hasNode(names[i])) {
+ current = current.getNode(names[i]);
+ } else {
+ if (parentNode == null) {
+ parentNode = current;
+ }
+ current = current.addNode(names[i], "nt:folder");
+ }
+ }
+
+ if (parentNode != null) {
+ parentNode.save();
+ return true;
+ }
+
+ } catch (RepositoryException re) {
+ log.error("Cannot create folder path " + path, re);
+ } finally {
+ checkNode(parentNode, path);
+ }
+
+ // false in case of error or no need to create
+ return false;
+ }
+
+ private static void checkNode(Node node, String path) {
+ if (node != null && node.isModified()) {
+ try {
+ node.refresh(false);
+ } catch (RepositoryException re) {
+ log.error("Cannot refresh node for " + path
+ + " after failed save", re);
+ }
+ }
+ }
+
+ private String cleanPath(String path) {
+ // replace backslash by slash
+ path = path.replace('\\', '/');
+
+ // cut off trailing slash
+ while (path.endsWith("/")) {
+ path = path.substring(0, path.length() - 1);
+ }
+
+ if ( this.classPath == null || this.classPath.length == 0 ) {
+ return path;
+ }
+ return this.classPath[0] + path;
+ }
+
+ private static class RepositoryOutputStream extends ByteArrayOutputStream {
+
+ private final RepositoryClassLoaderProviderImpl
repositoryOutputProvider;
+
+ private final String fileName;
+
+ RepositoryOutputStream(RepositoryClassLoaderProviderImpl
repositoryOutputProvider,
+ String fileName) {
+ this.repositoryOutputProvider = repositoryOutputProvider;
+ this.fileName = fileName;
+ }
+
+ public void close() throws IOException {
+ super.close();
+
+ Node parentNode = null;
+ Session session = null;
+ try {
+ session =
repositoryOutputProvider.getSession(repositoryOutputProvider.classLoaderOwner);
+ final int lastPos = fileName.lastIndexOf('/');
+ if ( lastPos != -1 ) {
+ repositoryOutputProvider.mkdirs(session,
fileName.substring(0, lastPos));
+ }
+ Node fileNode = null;
+ Node contentNode = null;
+ if (session.itemExists(fileName)) {
+ Item item = session.getItem(fileName);
+ if (item.isNode()) {
+ Node node = item.isNode()
+ ? (Node) item
+ : item.getParent();
+ if ("jcr:content".equals(node.getName())) {
+ // replace the content properties of the
jcr:content
+ // node
+ parentNode = node;
+ contentNode = node;
+ } else if (node.isNodeType("nt:file")) {
+ // try to set the content properties of jcr:content
+ // node
+ parentNode = node;
+ contentNode = node.getNode("jcr:content");
+ } else { // fileName is a node
+ // try to set the content properties of the node
+ parentNode = node;
+ contentNode = node;
+ }
+ } else {
+ // replace property with an nt:file node (if possible)
+ parentNode = item.getParent();
+ String name = item.getName();
+ fileNode = parentNode.addNode(name, "nt:file");
+ item.remove();
+ }
+ } else {
+ int lastSlash = fileName.lastIndexOf('/');
+ if (lastSlash <= 0) {
+ parentNode = session.getRootNode();
+ } else {
+ Item parent = session.getItem(fileName.substring(0,
+ lastSlash));
+ if (!parent.isNode()) {
+ // TODO: fail
+ }
+ parentNode = (Node) parent;
+ }
+ String name = fileName.substring(lastSlash + 1);
+ fileNode = parentNode.addNode(name, "nt:file");
+ }
+
+ // if we have a file node, create the contentNode
+ if (fileNode != null) {
+ contentNode = fileNode.addNode("jcr:content",
"nt:resource");
+ }
+
+ final MimeTypeService mtService =
this.repositoryOutputProvider.mimeTypeService;
+
+ String mimeType = (mtService == null ? null :
mtService.getMimeType(fileName));
+ if (mimeType == null) {
+ mimeType = "application/octet-stream";
+ }
+
+ contentNode.setProperty("jcr:lastModified",
+ System.currentTimeMillis());
+ contentNode.setProperty("jcr:data", new ByteArrayInputStream(
+ buf, 0, size()));
+ contentNode.setProperty("jcr:mimeType", mimeType);
+
+ parentNode.save();
+ } catch (RepositoryException re) {
+ log.error("Cannot write file " + fileName, re);
+ throw new IOException("Cannot write file " + fileName
+ + ", reason: " + re.toString());
+ } finally {
+ checkNode(parentNode, fileName);
+ if ( session != null ) {
+ session.logout();
+ }
+ }
+ }
+ }
+
+ /**
+ * @see
org.apache.sling.commons.classloader.ClassLoaderWriter#getInputStream(java.lang.String)
+ */
+ public InputStream getInputStream(String fileName)
+ throws IOException {
+ final String path = cleanPath(fileName) + "/jcr:content/jcr:data";
+ Session session = null;
+ try {
+ session = getSession(this.classLoaderOwner);
+ if ( session.itemExists(path) ) {
+ final Property prop = (Property)session.getItem(path);
+ return prop.getStream();
+ }
+ throw new FileNotFoundException("Unable to find " + fileName);
+ } catch (RepositoryException re) {
+ throw (IOException) new IOException(
+ "Failed to get InputStream for " +
fileName).initCause(re);
+ } finally {
+ if ( session != null ) {
+ session.logout();
+ }
+ }
+ }
+
+ /**
+ * @see
org.apache.sling.commons.classloader.ClassLoaderWriter#getLastModified(java.lang.String)
+ */
+ public long getLastModified(String fileName) {
+ final String path = cleanPath(fileName) +
"/jcr:content/jcr:lastModifed";
+ Session session = null;
+ try {
+ session = getSession(this.classLoaderOwner);
+ if ( session.itemExists(path) ) {
+ final Property prop = (Property)session.getItem(path);
+ return prop.getLong();
+ }
+ } catch (RepositoryException se) {
+ log.error("Cannot get last modification time for " + fileName, se);
+ }
+
+ // fallback to "non-existant" in case of problems
+ return -1;
+ }
+
protected void activate(ComponentContext componentContext) {
@SuppressWarnings("unchecked")
Dictionary properties = componentContext.getProperties();
Modified: sling/trunk/bundles/scripting/jsp/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/pom.xml?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/jsp/pom.xml (original)
+++ sling/trunk/bundles/scripting/jsp/pom.xml Fri Jul 17 06:16:52 2009
@@ -111,11 +111,6 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
- <artifactId>org.apache.sling.jcr.api</artifactId>
- <version>2.0.2-incubator</version>
- </dependency>
- <dependency>
- <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.commons.classloader</artifactId>
<version>0.9.0-SNAPSHOT</version>
</dependency>
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspScriptEngineFactory.java
Fri Jul 17 06:16:52 2009
@@ -34,6 +34,7 @@
import org.apache.sling.api.scripting.SlingBindings;
import org.apache.sling.api.scripting.SlingScript;
import org.apache.sling.api.scripting.SlingScriptHelper;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.commons.classloader.DynamicClassLoaderManager;
import org.apache.sling.scripting.api.AbstractScriptEngineFactory;
import org.apache.sling.scripting.api.AbstractSlingScriptEngine;
@@ -61,7 +62,6 @@
* @scr.property name="jasper.genStringAsCharArray" value="false"
type="Boolean"
* @scr.property name="jasper.keepgenerated" value="true" type="Boolean"
* @scr.property name="jasper.mappedfile" value="true" type="Boolean"
- * @scr.property name="jasper.scratchdir" value="/var/classes"
* @scr.property name="jasper.trimSpaces" value="false" type="Boolean"
* @scr.property name="jasper.checkInterval" value="300" type="Integer"
* @scr.property name="jasper.displaySourceFragments" value="true"
@@ -71,7 +71,7 @@
public class JspScriptEngineFactory extends AbstractScriptEngineFactory {
/** default log */
- private static final Logger log =
LoggerFactory.getLogger(JspScriptEngineFactory.class);
+ private final Logger log =
LoggerFactory.getLogger(JspScriptEngineFactory.class);
ComponentContext componentContext;
@@ -95,6 +95,9 @@
/** @scr.reference */
private DynamicClassLoaderManager dynamicClassLoaderManager;
+ /** @scr.reference */
+ private ClassLoaderWriter classLoaderWriter;
+
public static final String[] SCRIPT_TYPE = { "jsp", "jspf", "jspx" };
public JspScriptEngineFactory() {
@@ -181,7 +184,7 @@
// prepare some classes
prepareJasperClasses();
- ioProvider = new SlingIOProvider(slingServletContext);
+ ioProvider = new SlingIOProvider(classLoaderWriter);
tldLocationsCache = new SlingTldLocationsCache(slingServletContext,
componentContext.getBundleContext());
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/JspServletOptions.java
Fri Jul 17 06:16:52 2009
@@ -113,11 +113,6 @@
private boolean errorOnUseBeanInvalidClassAttribute = true;
/**
- * I want to see my generated servlets. Which directory are they in?
- */
- private String scratchDir;
-
- /**
* Need to have this as is for versions 4 and 5 of IE. Can be set from the
* initParams so if it changes in the future all that is needed is to have
a
* jsp initParam of type ieClassId="<value>"
@@ -127,7 +122,7 @@
/**
* What classpath should I use while compiling generated servlets?
*/
- private String classpath = null;
+ private String classpath;
/**
* Compiler target VM.
@@ -142,17 +137,17 @@
/**
* Cache for the TLD locations
*/
- private TldLocationsCache tldLocationsCache = null;
+ private TldLocationsCache tldLocationsCache;
/**
* Jsp config information
*/
- private JspConfig jspConfig = null;
+ private JspConfig jspConfig;
/**
* TagPluginManager
*/
- private TagPluginManager tagPluginManager = null;
+ private TagPluginManager tagPluginManager;
/**
* Java platform encoding to generate the JSP page servlet.
@@ -279,13 +274,6 @@
}
/**
- * What is my scratch dir?
- */
- public String getScratchDir() {
- return this.scratchDir;
- }
-
- /**
* What classpath should I use while compiling the servlets generated from
* JSP files?
*/
@@ -607,9 +595,6 @@
this.classpath = classpath;
}
- String dir = getProperty("scratchdir");
- this.scratchDir = (dir != null) ? dir : "/var/classes";
-
String compilerTargetVM = getProperty("compilerTargetVM");
if (compilerTargetVM != null) {
this.compilerTargetVM = compilerTargetVM;
@@ -662,4 +647,7 @@
this.tagPluginManager = new TagPluginManager(servletContext);
}
+ public String getScratchDir() {
+ return ":";
+ }
}
Modified:
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
Fri Jul 17 06:16:52 2009
@@ -16,8 +16,6 @@
*/
package org.apache.sling.scripting.jsp;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -28,36 +26,30 @@
import java.util.Iterator;
import java.util.Set;
-import javax.jcr.Item;
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.servlet.ServletContext;
-
import org.apache.sling.api.SlingException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceMetadata;
import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.commons.classloader.ClassLoaderWriter;
import org.apache.sling.scripting.jsp.jasper.IOProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * The <code>SlingIOProvider</code> TODO
+ * The <code>SlingIOProvider</code>
*/
class SlingIOProvider implements IOProvider {
/** default log */
- private static final Logger log =
LoggerFactory.getLogger(SlingIOProvider.class);
+ private final Logger log = LoggerFactory.getLogger(SlingIOProvider.class);
private final ThreadLocal<ResourceResolver> requestResourceResolver;
- // used to find out about the mime type for created files
- private final ServletContext servletContext;
+ private final ClassLoaderWriter classLoaderWriter;
- SlingIOProvider(ServletContext servletContext) {
+ SlingIOProvider(final ClassLoaderWriter classLoaderWriter) {
this.requestResourceResolver = new ThreadLocal<ResourceResolver>();
- this.servletContext = servletContext;
+ this.classLoaderWriter = classLoaderWriter;
}
void setRequestResourceResolver(ResourceResolver resolver) {
@@ -68,10 +60,6 @@
requestResourceResolver.remove();
}
- ServletContext getServletContext() {
- return servletContext;
- }
-
// ---------- IOProvider interface
-----------------------------------------
/**
@@ -81,7 +69,9 @@
*/
public InputStream getInputStream(String fileName)
throws FileNotFoundException, IOException {
-
+ if ( fileName.startsWith(":") ) {
+ return
this.classLoaderWriter.getInputStream(fileName.substring(1));
+ }
try {
Resource resource = getResourceInternal(fileName);
@@ -109,6 +99,9 @@
* returned.
*/
public long lastModified(String fileName) {
+ if ( fileName.startsWith(":") ) {
+ return
this.classLoaderWriter.getLastModified(fileName.substring(1));
+ }
try {
Resource resource = getResourceInternal(fileName);
if (resource != null) {
@@ -129,97 +122,29 @@
* Removes the named item from the repository.
*/
public boolean delete(String fileName) {
- Node parentNode = null;
- try {
- fileName = cleanPath(fileName);
- Session session = getPrivateSession();
- if (session.itemExists(fileName)) {
- Item fileItem = session.getItem(fileName);
- parentNode = fileItem.getParent();
- fileItem.remove();
- parentNode.save();
- return true;
- }
- } catch (RepositoryException re) {
- log.error("Cannot remove " + fileName, re);
- } finally {
- checkNode(parentNode, fileName);
- }
-
- // fall back to false if item does not exist or in case of error
- return false;
+ return this.classLoaderWriter.delete(fileName.substring(1));
}
/**
* Returns an output stream to write to the repository.
*/
public OutputStream getOutputStream(String fileName) {
- fileName = cleanPath(fileName);
- return new RepositoryOutputStream(this, fileName);
+ return this.classLoaderWriter.getOutputStream(fileName.substring(1));
}
/**
* Renames a node in the repository.
*/
public boolean rename(String oldFileName, String newFileName) {
- try {
- oldFileName = cleanPath(oldFileName);
- newFileName = cleanPath(newFileName);
-
- Session session = getPrivateSession();
- session.getWorkspace().move(oldFileName, newFileName);
- return true;
- } catch (RepositoryException re) {
- log.error("Cannot rename " + oldFileName + " to " + newFileName,
re);
- }
-
- // fallback to false in case of error or non-existence of oldFileName
- return false;
+ return this.classLoaderWriter.rename(oldFileName.substring(1),
newFileName.substring(1));
}
/**
* Creates a folder hierarchy in the repository.
*/
public boolean mkdirs(String path) {
- Node parentNode = null;
- try {
- Session session = getPrivateSession();
-
- // quick test
- path = cleanPath(path);
- if (session.itemExists(path) && session.getItem(path).isNode()) {
- return true;
- }
-
- // check path walking it down
- Node current = session.getRootNode();
- String[] names = path.split("/");
- for (int i = 0; i < names.length; i++) {
- if (names[i] == null || names[i].length() == 0) {
- continue;
- } else if (current.hasNode(names[i])) {
- current = current.getNode(names[i]);
- } else {
- if (parentNode == null) {
- parentNode = current;
- }
- current = current.addNode(names[i], "nt:folder");
- }
- }
-
- if (parentNode != null) {
- parentNode.save();
- return true;
- }
-
- } catch (RepositoryException re) {
- log.error("Cannot create folder path " + path, re);
- } finally {
- checkNode(parentNode, path);
- }
-
- // false in case of error or no need to create
- return false;
+ // we just do nothing
+ return true;
}
// ---------- Helper Methods for JspServletContext
-------------------------
@@ -267,21 +192,6 @@
// ---------- internal
-----------------------------------------------------
- private Session getPrivateSession() {
- return requestResourceResolver.get().adaptTo(Session.class);
- }
-
- private static void checkNode(Node node, String path) {
- if (node != null && node.isModified()) {
- try {
- node.refresh(false);
- } catch (RepositoryException re) {
- log.error("Cannot refresh node for " + path
- + " after failed save", re);
- }
- }
- }
-
private String cleanPath(String path) {
// replace backslash by slash
path = path.replace('\\', '/');
@@ -293,96 +203,4 @@
return path;
}
-
- private static class RepositoryOutputStream extends ByteArrayOutputStream {
-
- private final SlingIOProvider repositoryOutputProvider;
-
- private final String fileName;
-
- RepositoryOutputStream(SlingIOProvider repositoryOutputProvider,
- String fileName) {
- this.repositoryOutputProvider = repositoryOutputProvider;
- this.fileName = fileName;
- }
-
- public void close() throws IOException {
- super.close();
-
- Node parentNode = null;
- try {
- Session session = repositoryOutputProvider.getPrivateSession();
- Node fileNode = null;
- Node contentNode = null;
- if (session.itemExists(fileName)) {
- Item item = session.getItem(fileName);
- if (item.isNode()) {
- Node node = item.isNode()
- ? (Node) item
- : item.getParent();
- if ("jcr:content".equals(node.getName())) {
- // replace the content properties of the
jcr:content
- // node
- parentNode = node;
- contentNode = node;
- } else if (node.isNodeType("nt:file")) {
- // try to set the content properties of jcr:content
- // node
- parentNode = node;
- contentNode = node.getNode("jcr:content");
- } else { // fileName is a node
- // try to set the content properties of the node
- parentNode = node;
- contentNode = node;
- }
- } else {
- // replace property with an nt:file node (if possible)
- parentNode = item.getParent();
- String name = item.getName();
- fileNode = parentNode.addNode(name, "nt:file");
- item.remove();
- }
- } else {
- int lastSlash = fileName.lastIndexOf('/');
- if (lastSlash <= 0) {
- parentNode = session.getRootNode();
- } else {
- Item parent = session.getItem(fileName.substring(0,
- lastSlash));
- if (!parent.isNode()) {
- // TODO: fail
- }
- parentNode = (Node) parent;
- }
- String name = fileName.substring(lastSlash + 1);
- fileNode = parentNode.addNode(name, "nt:file");
- }
-
- // if we have a file node, create the contentNode
- if (fileNode != null) {
- contentNode = fileNode.addNode("jcr:content",
"nt:resource");
- }
-
- String mimeType =
repositoryOutputProvider.getServletContext().getMimeType(
- fileName);
- if (mimeType == null) {
- mimeType = "application/octet-stream";
- }
-
- contentNode.setProperty("jcr:lastModified",
- System.currentTimeMillis());
- contentNode.setProperty("jcr:data", new ByteArrayInputStream(
- buf, 0, size()));
- contentNode.setProperty("jcr:mimeType", mimeType);
-
- parentNode.save();
- } catch (RepositoryException re) {
- log.error("Cannot write file " + fileName, re);
- throw new IOException("Cannot write file " + fileName
- + ", reason: " + re.toString());
- } finally {
- checkNode(parentNode, fileName);
- }
- }
- }
}
Modified:
sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties?rev=794977&r1=794976&r2=794977&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties
(original)
+++
sling/trunk/bundles/scripting/jsp/src/main/resources/OSGI-INF/metatype/metatype.properties
Fri Jul 17 06:16:52 2009
@@ -75,11 +75,6 @@
on every access. Default is 4 seconds. This parameter has only an effect if \
developement mode is turned on.
-jasper.scratchdir.name = Compilation Location
-jasper.scratchdir.description = What scratch directory should we use when \
- compiling JSP pages? Default is the work directory for the current web \
- application.
-
jasper.trimSpaces.name = Trim Spaces
jasper.trimSpaces.description = Should white spaces in template text between \
actions or directives be trimmed ?, default false.