incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r590999 [3/5] - in /incubator/sling/trunk/microsling: ./ microsling-core/ microsling-core/src/ microsling-core/src/main/ microsling-core/src/main/java/ microsling-core/src/main/java/org/ microsling-core/src/main/java/org/apache/ microsling-...
Date Thu, 01 Nov 2007 13:30:08 GMT
Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/FileNodeRequestAttribute.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/FileNodeRequestAttribute.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/FileNodeRequestAttribute.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/FileNodeRequestAttribute.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,71 @@
+/*
+ * 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.microsling.scripting.helpers;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.microsling.helpers.exceptions.MissingRequestAttributeException;
+
+/** Stores an nt:file Node in a request attribute,
+ *  and allows the file's inputStream or reader to
+ *  be accessed easily.
+ *  Used by scripting SlingServlets to store resolved script nodes
+ *  in between canProcess and doX method calls.
+ */ 
+public class FileNodeRequestAttribute {
+    
+    private final Node node;
+    public static final String REQ_ATTR_NAME = FileNodeRequestAttribute.class.getName();
+    
+    /** Store this as an attribute of req */
+    public FileNodeRequestAttribute(Node n,HttpServletRequest req) {
+        node = n;
+        req.setAttribute(REQ_ATTR_NAME,this);
+    }
+    
+    /** Retrieve a FileNodeRequestAttribute from given request */
+    public static FileNodeRequestAttribute getFromRequest(HttpServletRequest req) throws MissingRequestAttributeException {
+        final FileNodeRequestAttribute result = 
+            (FileNodeRequestAttribute)req.getAttribute(REQ_ATTR_NAME);
+        if(result==null) {
+            throw new MissingRequestAttributeException(REQ_ATTR_NAME);
+        }
+        return result;
+    }
+    
+    /** Return our nt:file node */
+    public Node getNode() {
+        return node;
+    }
+
+    /** Return an InputStream that provides our node's file content */
+    public InputStream getInputStream() throws RepositoryException {
+        // TODO need more robust checks
+        return node.getNode("jcr:content").getProperty("jcr:data").getStream();
+    }
+    
+    /** Return a Reader that provides our node's file content */
+    public Reader getReader() throws RepositoryException {
+        return new InputStreamReader(getInputStream());
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/FileNodeRequestAttribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,82 @@
+/*
+ * 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.microsling.scripting.helpers;
+
+import org.apache.sling.microsling.helpers.constants.HttpConstants;
+
+/** Builds the names of script files based on the current input:
+ *  <ul>
+ *    <li>HTTP request method name</li>
+ *    <li>Request selectors, if any</li>
+ *    <li>Desired response Content-Type</li>
+ *    <li>Desired script extension</li>
+ *  </ul>
+ *  
+ *  See ScriptFilenameBuilderTest for examples.
+ *  
+ *  Note that names can include partial paths, for example we return
+ *  "print/a4/html.js" for a GET request for an html document with
+ *  selectors "print.a4".
+ */
+public class ScriptFilenameBuilder {
+
+    /** @return a name like "html.js" or "print/a4/html.vlt" or "POST.js" */ 
+    public String buildScriptFilename(String methodName,String selectors,String contentType,String scriptExtension) {
+        final StringBuffer sb = new StringBuffer();
+        
+        // path before filename:
+        // add selectors in front of the filename if any, replacing dots in them by slashes
+        // so that print.a4 becomes print/a4/
+        if(selectors != null && selectors.length() > 0) {
+            sb.append(selectors.toLowerCase().replace('.','/'));
+            sb.append('/');
+        }
+        
+        // filename:
+        if(methodName==null || methodName.length() == 0) {
+            sb.append("NO_METHOD");
+            
+        } else if(HttpConstants.METHOD_GET.equalsIgnoreCase(methodName)) {
+            // for the GET method, use the simplified content-type, lowercased,
+            // as the filename.
+            // TODO: how to handle HEAD?
+            if(contentType == null || contentType.length() == 0) {
+                sb.append("NO_CONTENT_TYPE");
+            } else {
+                // keep only what follows slash in the content-type
+                final String [] splitContentType = contentType.split("/");
+                sb.append(splitContentType[splitContentType.length - 1].toLowerCase());
+            }
+            
+        } else {
+            // for other methods use the method name
+            sb.append(methodName.toUpperCase());
+        }
+        
+        // extension: use desired script extension 
+        sb.append(".");
+        if(scriptExtension == null || scriptExtension.length()==0) {
+            sb.append("NO_EXT");
+        } else {
+            sb.append(scriptExtension.toLowerCase());
+        }
+        return sb.toString();
+    }
+    
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptFilenameBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptHelper.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptHelper.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptHelper.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,160 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.microsling.scripting.helpers;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.Writer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.ServletResponse;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
+
+/** Simple script helper providing access to the (wrapped) response, the
+ * on-demand writer and a simple API for request inclusion. Instances of this
+ * class are made available to the scripts as the global <code>sling</code>
+ * variable.
+ */
+public class ScriptHelper {
+
+    private final SlingHttpServletRequest request;
+
+    private final SlingHttpServletResponse response;
+
+    public ScriptHelper(SlingHttpServletRequest request, SlingHttpServletResponse response) {
+        this.request = request;
+        this.response = new OnDemandWriterResponse(response);
+    }
+
+    public SlingHttpServletRequest getRequest() {
+        return request;
+    }
+
+    public SlingHttpServletResponse getResponse() {
+        return response;
+    }
+
+    public void include(String path) throws ServletException, IOException {
+        RequestDispatcher dispatcher = getRequest().getRequestDispatcher(path);
+        if (dispatcher != null) {
+            dispatcher.include(getRequest(), getResponse());
+        }
+    }
+
+    /** Simple Response wrapper returning an on-demand writer when asked for
+     * a writer.
+     */
+    private static class OnDemandWriterResponse extends SlingHttpServletResponseWrapper {
+
+        private PrintWriter writer;
+
+        OnDemandWriterResponse(SlingHttpServletResponse delegatee) {
+            super(delegatee);
+        }
+
+        @Override
+        public PrintWriter getWriter() {
+            if (writer == null) {
+                writer = new PrintWriter(new OnDemandWriter(getResponse()));
+            }
+
+            return writer;
+        }
+    }
+
+    /** A writer acquiring the actual writer to delegate to on demand when the
+     * first data is to be written. */
+    private static class OnDemandWriter extends Writer {
+
+        private final ServletResponse response;
+        private Writer delegatee;
+
+        OnDemandWriter(ServletResponse response) {
+            this.response = response;
+        }
+
+        private Writer getWriter() throws IOException {
+            if (delegatee == null) {
+                delegatee = response.getWriter();
+            }
+
+            return delegatee;
+        }
+
+        @Override
+        public void write(int c) throws IOException {
+            synchronized (lock) {
+                getWriter().write(c);
+            }
+        }
+
+        @Override
+        public void write(char[] cbuf) throws IOException {
+            synchronized (lock) {
+                getWriter().write(cbuf);
+            }
+        }
+
+        @Override
+        public void write(char[] cbuf, int off, int len) throws IOException {
+            synchronized (lock) {
+                getWriter().write(cbuf, off, len);
+            }
+        }
+
+        @Override
+        public void write(String str) throws IOException {
+            synchronized (lock) {
+                getWriter().write(str);
+            }
+        }
+
+        @Override
+        public void write(String str, int off, int len) throws IOException {
+            synchronized (lock) {
+                getWriter().write(str, off, len);
+            }
+        }
+
+        @Override
+        public void flush() throws IOException {
+            synchronized (lock) {
+                Writer writer = delegatee;
+                if (writer != null) {
+                    writer.flush();
+                }
+            }
+        }
+
+        @Override
+        public void close() throws IOException {
+            synchronized (lock) {
+                // flush and close the delegatee if existing, otherwise ignore
+                Writer writer = delegatee;
+                if (writer != null) {
+                    writer.flush();
+                    writer.close();
+
+                    // drop the delegatee now
+                    delegatee = null;
+                }
+            }
+        }
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/scripting/helpers/ScriptHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/services/MicroslingServiceLocator.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/services/MicroslingServiceLocator.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/services/MicroslingServiceLocator.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/services/MicroslingServiceLocator.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,73 @@
+/*
+ * 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.microsling.services;
+
+import java.lang.reflect.Array;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sling.api.services.ServiceLocator;
+import org.apache.sling.api.services.ServiceNotAvailableException;
+
+/**
+ * Poor man's ServiceLocator (no, poorer than that) which uses a static list of
+ * services. This is mostly meant to introduce the ServiceLocator interface in
+ * microsling. See Sling OSGi for the real McCoy.
+ */
+
+public class MicroslingServiceLocator implements ServiceLocator {
+
+    protected final Map<Class<?>, Object> services = new HashMap<Class<?>, Object>();
+
+    public void registerService(Class<?> serviceType, Object service) {
+        services.put(serviceType, service);
+    }
+
+    @SuppressWarnings("unchecked")
+    public <ServiceType> ServiceType getService(Class<ServiceType> type) {
+        // unchecked cast:
+        return (ServiceType) services.get(type);
+    }
+
+    public <ServiceType> ServiceType getRequiredService(Class<ServiceType> type)
+            throws ServiceNotAvailableException {
+        ServiceType service = getService(type);
+        if (service != null) {
+            return service;
+        }
+
+        throw new ServiceNotAvailableException(type.getName());
+    }
+
+    @SuppressWarnings("unchecked")
+    public <ServiceType> ServiceType[] getServices(
+            Class<ServiceType> serviceType, String filter) {
+        if (serviceType != null) {
+            ServiceType service = getService(serviceType);
+            if (service != null) {
+                // unchecked cast:
+                ServiceType[] services = (ServiceType[]) Array.newInstance(
+                    serviceType, 1);
+                services[0] = service;
+                return services;
+            }
+        }
+
+        return null;
+    }
+
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/services/MicroslingServiceLocator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,160 @@
+/*
+ * 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.microsling.servlet;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+
+/**
+ * This is helper code, not very interesting to study (but it's not in an
+ * "helpers" package as that would require too much public stuff). Manages the
+ * microsling chain of servlet Filters: stores the list, calls them when
+ * processing a request and calls microSlingServlet.doService after that.
+ */
+class MicroSlingFilterHelper {
+
+    private MicroslingMainServlet microSling;
+
+    private List<Filter> requestFilterList = new LinkedList<Filter>();
+
+    private Filter[] requestFilters;
+
+    MicroSlingFilterHelper(MicroslingMainServlet microSling) {
+        this.microSling = microSling;
+    }
+
+    void destroy() {
+        Filter[] filters = getFilters();
+
+        // clean up
+        requestFilterList.clear();
+        requestFilters = null;
+
+        // destroy the filters
+        for (int i = 0; i < filters.length; i++) {
+            try {
+                filters[i].destroy();
+            } catch (Throwable t) {
+                // TODO: some logging would probably be usefull
+            }
+        }
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see javax.servlet.FilterChain#doFilter(javax.servlet.ServletRequest,
+     *      javax.servlet.ServletResponse)
+     */
+    void service(ServletRequest request, ServletResponse response)
+            throws IOException, ServletException {
+
+        MicroSlingFilterChain filterChain = new MicroSlingFilterChain(
+            microSling, getFilters());
+        filterChain.doFilter(request, response);
+
+    }
+
+    /** return our Filters as a (lazily created) array */
+    private Filter[] getFilters() {
+        if (requestFilters == null) {
+            requestFilters = requestFilterList.toArray(new Filter[requestFilterList.size()]);
+        }
+        return requestFilters;
+    }
+
+    /** Add a Filter at the end of our current chain */
+    void addFilter(final Filter filter) throws ServletException {
+        FilterConfig config = new FilterConfig() {
+            public String getFilterName() {
+                return filter.getClass().getName();
+            }
+
+            public String getInitParameter(String arg0) {
+                // no parameters for now
+                return null;
+            }
+
+            public Enumeration<?> getInitParameterNames() {
+                // no parameters for now
+                return Collections.enumeration(Collections.emptyList());
+            }
+
+            public ServletContext getServletContext() {
+                return microSling.getServletContext();
+            }
+        };
+
+        // initialize the filter and add it to the list
+        filter.init(config);
+        requestFilterList.add(filter);
+
+        // force recreation of filter list
+        requestFilters = null;
+    }
+
+    /**
+     * A FilterChain that applies all Filters in an array and calls
+     * MicroSlingServlet.doFilter when done
+     */
+    private static class MicroSlingFilterChain implements FilterChain {
+
+        private final MicroslingMainServlet microSlingServlet;
+
+        private final Filter[] requestFilters;
+
+        private int currentFilter;
+
+        private MicroSlingFilterChain(MicroslingMainServlet microSlingServlet,
+                Filter[] requestFilters) {
+            this.microSlingServlet = microSlingServlet;
+            this.requestFilters = requestFilters;
+            this.currentFilter = -1;
+        }
+
+        public void doFilter(ServletRequest request, ServletResponse response)
+                throws IOException, ServletException {
+
+            currentFilter++;
+
+            if (currentFilter < requestFilters.length) {
+                // call the next filter
+                requestFilters[currentFilter].doFilter(request, response, this);
+
+            } else {
+                // done with filters, call microsling servlet resolution and
+                // handling
+                microSlingServlet.doService((SlingHttpServletRequest) request,
+                    (SlingHttpServletResponse) response);
+            }
+
+        }
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroSlingFilterHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,204 @@
+/*
+ * 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.microsling.servlet;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import javax.jcr.Credentials;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.servlet.Filter;
+import javax.servlet.GenericServlet;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.HttpStatusCodeException;
+import org.apache.sling.api.SlingException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.scripting.SlingScriptResolver;
+import org.apache.sling.microsling.MicroslingSlingHttpServletRequest;
+import org.apache.sling.microsling.MicroslingSlingHttpServletResponse;
+import org.apache.sling.microsling.contenttype.ResponseContentTypeResolverFilter;
+import org.apache.sling.microsling.scripting.MicroslingScriptResolver;
+import org.apache.sling.microsling.services.MicroslingServiceLocator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The main microsling servlet: apply Filters to the request using our
+ * MicroSlingFilterHelper, select and delegate to a SlingServlet to process the
+ * request.
+ */
+public class MicroslingMainServlet extends GenericServlet {
+
+    private static final long serialVersionUID = 1L;
+
+    private MicroSlingFilterHelper filterChain;
+
+    private MicroslingServiceLocator serviceLocator;
+
+    private MicroslingServletResolver servletResolver;
+
+    private MicroslingScriptResolver scriptResolver;
+
+    private static final Logger log = LoggerFactory.getLogger(MicroslingMainServlet.class);
+
+    @Override
+    public void init() throws ServletException {
+        super.init();
+
+        // this must be first as services may register later
+        initServiceLocator();
+
+        initFilterChain();
+        initServletResolver();
+        initScriptResolver();
+    }
+
+    /** init our filter chain */
+    protected void initFilterChain() throws ServletException {
+        filterChain = new MicroSlingFilterHelper(this);
+        addFilter(new ResponseContentTypeResolverFilter());
+    }
+
+    /** init our servlets */
+    protected void initServletResolver() throws ServletException {
+        servletResolver = new MicroslingServletResolver(getServletContext());
+    }
+
+    /** init our serviceLocator */
+    protected void initServiceLocator() throws ServletException {
+        serviceLocator = new MicroslingServiceLocator();
+    }
+
+    /** init our scriptResolver */
+    protected void initScriptResolver() throws ServletException {
+        scriptResolver = new MicroslingScriptResolver();
+        serviceLocator.registerService(SlingScriptResolver.class,
+            scriptResolver);
+    }
+
+    protected Repository getRepository() throws SlingException {
+        // Access our Repository
+        final String repoAttr = Repository.class.getName();
+        Repository repository = (Repository) getServletContext().getAttribute(
+            repoAttr);
+        if (repository == null) {
+            throw new SlingException(
+                "Repository not available in ServletContext attribute "
+                    + repoAttr);
+        }
+
+        return repository;
+    }
+
+    /** authenticate the request by creating a JCR Session for later use */
+    protected Session authenticate(ServletRequest request)
+            throws SlingException {
+        // We should probably extract the user name and password (Credentials)
+        // if you wish from the request. For now we just log in as an
+        // admin user
+        try {
+            Credentials credentials = new SimpleCredentials("admin",
+                "admin".toCharArray());
+            return getRepository().login(credentials);
+        } catch (RepositoryException re) {
+            throw new SlingException("Repository.login() failed: "
+                + re.getMessage(), re);
+        }
+    }
+
+    /**
+     * Execute our Filters via MicroSlingFilterHelper, which calls our doService
+     * method after executing the filters
+     */
+    public void service(ServletRequest req, ServletResponse resp)
+            throws ServletException, IOException {
+
+        Session session = authenticate(req);
+
+        MicroslingSlingHttpServletRequest request = new MicroslingSlingHttpServletRequest(
+            (HttpServletRequest) req, session, serviceLocator);
+        MicroslingSlingHttpServletResponse response = new MicroslingSlingHttpServletResponse(
+            (HttpServletResponse) resp);
+
+        // our filters might need the SlingRequestContext to store info in it
+        filterChain.service(request, response);
+    }
+
+    @Override
+    public void destroy() {
+        // just for completeness, we have to take down our filters
+        if (filterChain != null) {
+            filterChain.destroy();
+            filterChain = null;
+        }
+
+        // destroy registered servlets
+        if (servletResolver != null) {
+            servletResolver.destroy();
+            servletResolver = null;
+        }
+
+        // destroy base class at the end
+        super.destroy();
+    }
+
+    /**
+     * Called by
+     * {@link MicroSlingFilterHelper#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse)}
+     * after all filters have been processed.
+     */
+    void doService(SlingHttpServletRequest request, SlingHttpServletResponse response)
+            throws SlingException, IOException {
+
+        try {
+            Servlet requestServlet = servletResolver.resolveServlet(request);
+
+            if (requestServlet == null) {
+                // TODO: decide whether this is 500 or rather 404
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No Servlet found to handle resource " + request.getResource());
+            } else {
+                requestServlet.service(request, response);
+            }
+        } catch (HttpStatusCodeException hts) {
+            response.sendError(hts.getStatusCode(), hts.getMessage());
+        } catch (IOException ioe) {
+            throw ioe;
+        } catch (SlingException se) {
+            throw se;
+        } catch (Exception e) {
+            final StringWriter sw = new StringWriter();
+            e.printStackTrace(new PrintWriter(sw, true));
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage() + "\n" + sw.toString());
+        }
+    }
+
+    /** Add a filter to our MicroSlingFilterHelper */
+    protected void addFilter(Filter filter) throws ServletException {
+        filterChain.addFilter(filter);
+    }
+
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingMainServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,164 @@
+/*
+ * 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.microsling.servlet;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.scripting.SlingScriptResolver;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.microsling.scripting.MicroslingScriptServlet;
+import org.apache.sling.microsling.slingservlets.DefaultSlingServlet;
+import org.apache.sling.microsling.slingservlets.StreamServlet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MicroslingServletResolver implements ServletResolver {
+
+    /** default log */
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private ServletContext servletContext;
+
+    private Map<String, Servlet> servlets;
+
+    private DefaultSlingServlet defaultSlingServlet;
+
+    MicroslingServletResolver(ServletContext servletContext) {
+        this.servletContext = servletContext;
+        this.servlets = new HashMap<String, Servlet>();
+
+        // TODO use a utility class to map nt:file to the magic NODETYPES path
+        addServlet("NODETYPES/nt/file", new StreamServlet());
+        defaultSlingServlet = new DefaultSlingServlet();
+    }
+
+    protected void destroy() {
+        Servlet[] servletList = servlets.values().toArray(
+            new Servlet[servlets.size()]);
+        for (Servlet servlet : servletList) {
+            try {
+                servlet.destroy();
+            } catch (Throwable t) {
+                getServletContext().log(
+                    "Unexpected problem destroying servlet " + servlet, t);
+            }
+        }
+        servlets.clear();
+    }
+
+    public Servlet resolveServlet(SlingHttpServletRequest request)
+            throws ServletException {
+        // Select a SlingServlet and delegate the actual request processing
+        // to it
+        final Servlet selectedServlet = selectSlingServlet(request);
+        if (selectedServlet != null) {
+            return selectedServlet;
+        }
+
+        // no typed servlet, so lets try scripting
+        SlingScript script = getScriptResolver(request).resolveScript(request);
+        if (script != null) {
+            return new MicroslingScriptServlet(script);
+        }
+
+        if (log.isDebugEnabled()) {
+            final Resource r = request.getResource();
+            log.debug("No specific Servlet or script found for Resource " + r
+                + ", using default Servlet");
+        }
+
+        return defaultSlingServlet;
+    }
+
+    protected SlingScriptResolver getScriptResolver(
+            SlingHttpServletRequest request) {
+        return request.getServiceLocator().getService(SlingScriptResolver.class);
+    }
+
+    /** Select a SlingServlet to process the given request */
+    protected Servlet selectSlingServlet(SlingHttpServletRequest req)
+            throws SlingException {
+
+        // use the resource type to select a servlet
+        final Resource r = req.getResource();
+        String type = (r == null ? null : r.getResourceType());
+        final Servlet result = (type != null) ? servlets.get(type) : null;
+
+        if (log.isDebugEnabled()) {
+            if (result == null) {
+                log.debug("No Servlet found for resource type " + type);
+            } else {
+                log.debug("Using Servlet class "
+                    + result.getClass().getSimpleName() + " for resource type "
+                    + type);
+            }
+        }
+
+        return result;
+    }
+
+    /** Add servlets by resource type */
+    protected void addServlet(final String resourceType, Servlet servlet) {
+
+        try {
+            ServletConfig config = new ServletConfig() {
+                public String getInitParameter(String name) {
+                    return null;
+                }
+
+                public Enumeration<?> getInitParameterNames() {
+                    return Collections.enumeration(Collections.emptyList());
+                }
+
+                public ServletContext getServletContext() {
+                    return MicroslingServletResolver.this.getServletContext();
+                }
+
+                public String getServletName() {
+                    return resourceType;
+                }
+            };
+            servlet.init(config);
+
+            // only register if initialization succeeds
+            servlets.put(resourceType, servlet);
+        } catch (Throwable t) {
+            getServletContext().log(
+                "Failed initializing servlet " + servlet + " for type "
+                    + resourceType, t);
+        }
+
+    }
+
+    protected ServletContext getServletContext() {
+        return servletContext;
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/servlet/MicroslingServletResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,223 @@
+/*
+ * 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.microsling.slingservlets;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Enumeration;
+
+import javax.jcr.Item;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.api.HttpStatusCodeException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestPathInfo;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+
+/**
+ * The default SlingServlet, used if no other SlingServlet wants to process the
+ * current request.
+ */
+public class DefaultSlingServlet extends SlingAllMethodsServlet {
+
+    @Override
+    protected void doGet(SlingHttpServletRequest req, SlingHttpServletResponse resp)
+            throws ServletException, IOException {
+        resp.setContentType("text/plain");
+
+        final Resource  r = req.getResource();
+        if (Resource.RESOURCE_TYPE_NON_EXISTING.equals(r.getResourceType())) {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "Resource not found: " + r.getURI());
+        }
+
+        final Object data = r.getRawData();
+        if (data instanceof Item) {
+            final PrintWriter pw = resp.getWriter();
+            try {
+                if (data instanceof Node) {
+                    dump(pw, r, (Node) data);
+                } else {
+                    dump(pw, r, (Property) data);
+                }
+            } catch (RepositoryException re) {
+                throw new ServletException("Cannot dump contents of "
+                    + req.getResource().getURI(), re);
+            }
+        } else {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_IMPLEMENTED,
+                "Not implemented: resource " + req.getResource().getURI()
+                    + " cannot be dumped by " + getClass().getSimpleName());
+        }
+    }
+
+    @Override
+    protected void doPost(SlingHttpServletRequest req, SlingHttpServletResponse resp)
+            throws ServletException, IOException {
+
+        // require a node resource
+        Resource r = req.getResource();
+        if (!(req.getResource().getRawData() instanceof Node)
+            && !Resource.RESOURCE_TYPE_NON_EXISTING.equals(r.getResourceType())) {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "Resource not found: " + r.getURI() + " must be missing or a Node");
+        }
+
+        String redirectPath = req.getPathInfo();
+        Session s = null;
+        try {
+            Node current = (Node) req.getResource().getRawData();
+            if (current == null) {
+                Resource root = req.getResourceResolver().getResource("/");
+                if (root != null) {
+                    current = (Node) root.getRawData();
+                } else {
+                    throw new ServletException("Cannot get resource for root node");
+                }
+            }
+            s = current.getSession();
+
+            // Decide whether to create or update a node
+            // TODO: this is a simplistic way of deciding, for now: if we have
+            // no Resource or if the Node that it points to already has child nodes,
+            // we create a new node. Else we update the current node.
+            if(current.hasNodes()) {
+                final String parentPath = current.getPath();
+                final RequestPathInfo pathInfo = req.getRequestPathInfo();
+                final String newNodePath = (pathInfo.getSuffix() == null || pathInfo.getSuffix().length() == 0)
+                        ? String.valueOf(System.currentTimeMillis())
+                        : pathInfo.getSuffix();
+                current = deepCreateNode(s, parentPath + "/" + newNodePath);
+            }
+
+            // Copy request parameters to node properties and save
+            setPropertiesFromRequest(current, req);
+            s.save();
+            redirectPath = current.getPath();
+
+        } catch (RepositoryException re) {
+            throw new ServletException("Failed to modify content: "
+                + re.getMessage(), re);
+
+        } finally {
+            try {
+                if (s != null && s.hasPendingChanges()) {
+                    s.refresh(false);
+                }
+            } catch (RepositoryException re) {
+                // TODO: might want to log, but don't further care
+            }
+        }
+
+        // redirect to the created node, so that it is displayed using a user-supplied extension
+        String redirectExtension = req.getParameter("slingDisplayExtension");
+        final String redirectUrl =
+            req.getContextPath() + req.getServletPath() + redirectPath
+            + (redirectExtension == null ? "" : "." + redirectExtension)
+        ;
+        resp.sendRedirect(redirectUrl);
+    }
+
+    /** Set node properties from current request (only handles Strings for now) */
+    protected void setPropertiesFromRequest(Node n, HttpServletRequest req)
+            throws RepositoryException {
+        // TODO ignore sling-specific properties like slingDisplayExtension
+        for (Enumeration e = req.getParameterNames(); e.hasMoreElements();) {
+            final String name = (String) e.nextElement();
+            final String[] values = req.getParameterValues(name);
+            if (values.length==1) {
+            	n.setProperty(name, values[0]);
+            } else {
+            	n.setProperty(name, values);
+            }
+        }
+    }
+
+    /**
+     * Deep creates a node, parent-padding with nt:unstructured nodes
+     *
+     * @param path absolute path to node that needs to be deep-created
+     */
+    protected Node deepCreateNode(Session s, String path)
+            throws RepositoryException {
+        String[] pathelems = path.substring(1).split("/");
+        int i = 0;
+        String mypath = "";
+        Node parent = s.getRootNode();
+        while (i < pathelems.length) {
+            String name = pathelems[i];
+            mypath += "/" + name;
+            if (!s.itemExists(mypath)) {
+                parent.addNode(name);
+            }
+            parent = (Node) s.getItem(mypath);
+            i++;
+        }
+        return (parent);
+    }
+
+    protected void dump(PrintWriter pw, Resource r, Node n) throws RepositoryException {
+        pw.println("** Node dumped by " + getClass().getSimpleName() + "**");
+        pw.println("Node path:" + n.getPath());
+        pw.println("Resource metadata: " + r.getResourceMetadata());
+
+        pw.println("\n** Node properties **");
+        for (PropertyIterator pi = n.getProperties(); pi.hasNext();) {
+            final Property p = pi.nextProperty();
+            printPropertyValue(pw, p);
+        }
+    }
+
+    protected void dump(PrintWriter pw, Resource r, Property p) throws RepositoryException {
+        pw.println("** Property dumped by " + getClass().getSimpleName() + "**");
+        pw.println("Property path:" + p.getPath());
+        pw.println("Resource metadata: " + r.getResourceMetadata());
+
+        printPropertyValue(pw, p);
+    }
+
+    protected void printPropertyValue(PrintWriter pw, Property p)
+            throws RepositoryException {
+
+        pw.print(p.getName() + ": ");
+
+        if (p.getDefinition().isMultiple()) {
+            Value[] values = p.getValues();
+            pw.print('[');
+            for (int i = 0; i < values.length; i++) {
+                if (i > 0) {
+                    pw.print(", ");
+                }
+                pw.print(values[i].getString());
+            }
+            pw.println(']');
+        } else {
+            pw.println(p.getValue().getString());
+        }
+    }
+
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java Thu Nov  1 06:30:00 2007
@@ -0,0 +1,206 @@
+/*
+ * $Url: $
+ * $Id: $
+ *
+ * Copyright 1997-2005 Day Management AG
+ * Barfuesserplatz 6, 4001 Basel, Switzerland
+ * All Rights Reserved.
+ *
+ * This software is the confidential and proprietary information of
+ * Day Management AG, ("Confidential Information"). You shall not
+ * disclose such Confidential Information and shall use it only in
+ * accordance with the terms of the license agreement you entered into
+ * with Day.
+ */
+package org.apache.sling.microsling.slingservlets;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.jcr.Item;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.api.HttpStatusCodeException;
+import org.apache.sling.api.SlingException;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.microsling.helpers.constants.HttpConstants;
+
+/**
+ * The <code>StreamServlet</code> handles requests for nodes which may just be
+ * streamed out to the response. If the requested JCR Item is an
+ * <em>nt:file</em> whose <em>jcr:content</em> child node is of type
+ * <em>nt:resource</em>, the response content type, last modification time and
+ * charcter encoding are set according to the resource node. In addition if
+ * the <em>If-Modified-Since</em> header is set, the resource will only be
+ * spooled if the last modification time is later than the header. Otherwise
+ * a 304 (Not Modified) status code is sent.
+ * <p>
+ * If the requested item is not an <em>nt:file</em>/<em>nt:resource</em> tuple,
+ * the item is just resolved by following the primary item trail according to
+ * the algorithm
+ * <pre>
+ *     while (item.isNode) {
+ *         item = ((Node) item).getPrimaryItem();
+ *     }
+ * </pre>
+ * Until a property is found or the primary item is either not defined or not
+ * existing in which case an exception is thrown and the request fails with
+ * a 404 (Not Found) status.
+ */
+public class StreamServlet extends SlingSafeMethodsServlet {
+
+    @Override
+    protected void doGet(SlingHttpServletRequest request,
+            SlingHttpServletResponse response) throws ServletException, IOException {
+
+        if (!(request.getResource().getRawData() instanceof Node)) {
+            throw new HttpStatusCodeException(HttpServletResponse.SC_NOT_FOUND,
+                "Resource " + request.getResource().getURI()
+                    + " must be a Node");
+        }
+
+        try {
+            // otherwise handle nt:file/nt:resource specially
+            Node node = (Node) request.getResource().getRawData();
+            if (node.isNodeType("nt:file")) {
+                Node content = node.getNode("jcr:content");
+                if (content.isNodeType("nt:resource")) {
+
+                    // check for if last modified
+                    long ifModified = request.getDateHeader(HttpConstants.HEADER_IF_MODIFIED_SINCE);
+                    long lastModified = getLastModified(content);
+                    if (ifModified < 0 || lastModified > ifModified) {
+
+                        String contentType = getMimeType(content);
+                        if (contentType == null) {
+                            contentType = request.getResponseContentType();
+                        }
+
+                        spool(response,
+                            content.getProperty(JcrConstants.JCR_DATA),
+                            contentType, getEncoding(content),
+                            getLastModified(content));
+                    } else {
+                        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+                    }
+
+                    return;
+                }
+            }
+
+            // just spool, the property to which the item resolves through
+            // the primary item trail
+            // the item is a property, spool and forget
+            spool(response, findDefaultProperty(node), null, null, -1);
+
+        } catch (ItemNotFoundException infe) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+
+        } catch (RepositoryException re) {
+            throw new SlingException(re.getMessage(), re);
+        }
+    }
+
+    /**
+     * Spool the property value to the response setting the content type,
+     * character set, last modification data and content length header
+     */
+    private void spool(HttpServletResponse response, Property prop,
+            String mimeType, String encoding, long lastModified)
+            throws RepositoryException, IOException {
+
+        if (mimeType != null) {
+            response.setContentType(mimeType);
+        }
+
+        if (encoding != null) {
+            response.setCharacterEncoding(encoding);
+        }
+
+        if (lastModified > 0) {
+            response.setDateHeader(HttpConstants.HEADER_LAST_MODIFIED, lastModified);
+        }
+
+        // only set the content length if the property is a binary
+        if (prop.getType() == PropertyType.BINARY) {
+            response.setContentLength((int) prop.getLength());
+        }
+
+        InputStream ins = prop.getStream();
+        OutputStream out = null;
+        try {
+            ins = prop.getStream();
+            out = response.getOutputStream();
+
+            byte[] buf = new byte[2048];
+            int num;
+            while ((num = ins.read(buf)) >= 0) {
+                out.write(buf, 0, num);
+            }
+        } finally {
+            if (ins != null) {
+                try {
+                    ins.close();
+                } catch (IOException ignore) {
+                }
+            }
+            if (out != null) {
+                try {
+                    out.close();
+                } catch (IOException ignore) {
+                }
+            }
+        }
+    }
+
+    /** Follow the primary item trail of item until a property is found */
+    Property findDefaultProperty(Item item) throws ItemNotFoundException,
+            RepositoryException {
+        while (item.isNode()) {
+            // will throw if there is none defined or existsing
+            item = ((Node) item).getPrimaryItem();
+        }
+        return (Property) item;
+    }
+
+    /** return the jcr:lastModified property value or null if property is missing */
+    private long getLastModified(Node resourceNode) throws RepositoryException {
+        Property lastModifiedProp = getProperty(resourceNode,
+            JcrConstants.JCR_LASTMODIFIED);
+        return (lastModifiedProp != null) ? lastModifiedProp.getLong() : -1;
+    }
+
+    /** return the jcr:mimeType property value or null if property is missing */
+    private String getMimeType(Node resourceNode) throws RepositoryException {
+        Property mimeTypeProp = getProperty(resourceNode,
+            JcrConstants.JCR_MIMETYPE);
+        return (mimeTypeProp != null) ? mimeTypeProp.getString() : null;
+    }
+
+    /** return the jcr:encoding property value or null if property is missing */
+    private String getEncoding(Node resourceNode) throws RepositoryException {
+        Property encodingProp = getProperty(resourceNode,
+            JcrConstants.JCR_ENCODING);
+        return (encodingProp != null) ? encodingProp.getString() : null;
+    }
+
+    /** Return the named property or null if not existing or node is null */
+    private Property getProperty(Node node, String relPath)
+            throws RepositoryException {
+        if (node != null && node.hasProperty(relPath)) {
+            return node.getProperty(relPath);
+        }
+
+        return null;
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/slingservlets/StreamServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.dtd
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.dtd?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.dtd (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.dtd Thu Nov  1 06:30:00 2007
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<!-- Authors: Chris Taylor, Ceki Gulcu. -->
+
+<!-- Version: 1.2 -->
+
+<!-- A configuration element consists of optional renderer
+elements,appender elements, categories and an optional root
+element. -->
+
+<!ELEMENT log4j:configuration (renderer*, appender*, logger*, root?)>
+
+<!-- The "threshold" attribute takes a level value such that all -->
+<!-- logging statements with a level equal or below this value are -->
+<!-- disabled. -->
+
+<!-- Setting the "debug" enable the printing of internal log4j logging   -->
+<!-- statements.                                                         -->
+
+<!-- By default, debug attribute is "null", meaning that we not do touch -->
+<!-- internal log4j logging settings. The "null" value for the threshold -->
+<!-- attribute can be misleading. The threshold field of a repository	 -->
+<!-- cannot be set to null. The "null" value for the threshold attribute -->
+<!-- simply means don't touch the threshold field, the threshold field   --> 
+<!-- keeps its old value.                                                -->
+     
+<!ATTLIST log4j:configuration
+  xmlns:log4j              CDATA #FIXED "http://jakarta.apache.org/log4j/" 
+  threshold                (all|debug|info|warn|error|fatal|off|null) "null"
+  debug                    (true|false|null)  "null"
+>
+
+<!-- renderer elements allow the user to customize the conversion of  -->
+<!-- message objects to String.                                       -->
+
+<!ELEMENT renderer EMPTY>
+<!ATTLIST renderer
+  renderedClass  CDATA #REQUIRED
+  renderingClass CDATA #REQUIRED
+>
+
+<!-- Appenders must have a name and a class. -->
+<!-- Appenders may contain an error handler, a layout, optional parameters -->
+<!-- and filters. They may also reference (or include) other appenders. -->
+<!ELEMENT appender (errorHandler?, param*, layout?, filter*, appender-ref*)>
+<!ATTLIST appender
+  name 		ID 	#REQUIRED
+  class 	CDATA	#REQUIRED
+>
+
+<!ELEMENT layout (param*)>
+<!ATTLIST layout
+  class		CDATA	#REQUIRED
+>
+
+<!ELEMENT filter (param*)>
+<!ATTLIST filter
+  class		CDATA	#REQUIRED
+>
+
+<!-- ErrorHandlers can be of any class. They can admit any number of -->
+<!-- parameters. -->
+
+<!ELEMENT errorHandler (param*, root-ref?, logger-ref*,  appender-ref?)> 
+<!ATTLIST errorHandler
+   class        CDATA   #REQUIRED 
+>
+
+<!ELEMENT root-ref EMPTY>
+
+<!ELEMENT logger-ref EMPTY>
+<!ATTLIST logger-ref
+  ref IDREF #REQUIRED
+>
+
+<!ELEMENT param EMPTY>
+<!ATTLIST param
+  name		CDATA   #REQUIRED
+  value		CDATA	#REQUIRED
+>
+
+
+<!-- The priority class is org.apache.log4j.Level by default -->
+<!--
+    DEPRECATED
+
+<!ELEMENT priority (param*)>
+<!ATTLIST priority
+  class   CDATA	#IMPLIED
+  value	  CDATA #REQUIRED
+>
+-->
+
+<!-- The level class is org.apache.log4j.Level by default -->
+<!ELEMENT level (param*)>
+<!ATTLIST level
+  class   CDATA	#IMPLIED
+  value	  CDATA #REQUIRED
+>
+
+
+<!-- If no level element is specified, then the configurator MUST not -->
+<!-- touch the level of the named category. -->
+<!--
+    DEPRECATED
+
+<!ELEMENT category (param*,(priority|level)?,appender-ref*)>
+<!ATTLIST category
+  class         CDATA   #IMPLIED
+  name		CDATA	#REQUIRED
+  additivity	(true|false) "true"  
+>
+-->
+
+<!-- If no level element is specified, then the configurator MUST not -->
+<!-- touch the level of the named logger. -->
+<!ELEMENT logger (level?, appender-ref*)>
+<!ATTLIST logger
+  class         CDATA   #IMPLIED
+  name		ID	#REQUIRED
+  additivity	(true|false) "true"  
+>
+
+<!--
+    DEPRECATED
+
+<!ELEMENT categoryFactory (param*)>
+<!ATTLIST categoryFactory 
+   class        CDATA #REQUIRED>
+-->
+
+<!ELEMENT appender-ref EMPTY>
+<!ATTLIST appender-ref
+  ref IDREF #REQUIRED
+>
+
+<!-- If no priority element is specified, then the configurator MUST not -->
+<!-- touch the priority of root. -->
+<!-- The root category always exists and cannot be subclassed. -->
+<!ELEMENT root (param*, level?, appender-ref*)>
+
+
+<!-- ==================================================================== -->
+<!--                       A logging event                                -->
+<!-- ==================================================================== -->
+<!ELEMENT log4j:eventSet (log4j:event*)>
+<!ATTLIST log4j:eventSet
+  xmlns:log4j             CDATA #FIXED "http://jakarta.apache.org/log4j/" 
+  version                (1.1|1.2) "1.2" 
+  includesLocationInfo   (true|false) "true"
+>
+
+
+
+<!ELEMENT log4j:event (log4j:message, log4j:NDC?, log4j:throwable?, 
+                       log4j:locationInfo?) >
+
+<!-- The timestamp format is application dependent. -->
+<!ATTLIST log4j:event
+    logger     CDATA #REQUIRED
+    level      CDATA #REQUIRED
+    thread     CDATA #REQUIRED
+    timestamp  CDATA #REQUIRED
+>
+
+<!ELEMENT log4j:message (#PCDATA)>
+<!ELEMENT log4j:NDC (#PCDATA)>
+
+<!ELEMENT log4j:throwable (#PCDATA)>
+
+<!ELEMENT log4j:locationInfo EMPTY>
+<!ATTLIST log4j:locationInfo
+  class  CDATA	#REQUIRED
+  method CDATA	#REQUIRED
+  file   CDATA	#REQUIRED
+  line   CDATA	#REQUIRED
+>

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.dtd
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.xml?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.xml (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.xml Thu Nov  1 06:30:00 2007
@@ -0,0 +1,49 @@
+<?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.
+  -->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+    <!-- ====================================================================== -->
+    <!-- A P P E N D E R S                                                      -->
+    <!-- ====================================================================== -->
+
+    <!-- console -->
+    <appender name="console" class="org.apache.log4j.ConsoleAppender">
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m (%F, line %L)%n"/>
+        </layout>
+    </appender>
+
+    <!-- log file -->
+    <appender name="file" class="org.apache.log4j.FileAppender">
+        <param name="File" value="logs/microsling.log"/>
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%d{dd.MM.yyyy HH:mm:ss} *%-5p* %c{1}: %m (%F, line %L)%n"/>
+        </layout>
+    </appender>
+    
+    <!-- ====================================================================== -->
+    <!-- C A T E G O R I E S                                                    -->
+    <!-- ====================================================================== -->
+     <category name="org.apache.sling">
+      <priority value="debug"/>
+      <appender-ref ref="console"/>
+      <appender-ref ref="file"/>
+    </category>
+
+</log4j:configuration>

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/log4j.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml Thu Nov  1 06:30:00 2007
@@ -0,0 +1,267 @@
+<?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.
+  -->
+
+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+
+<web-app>
+  <display-name>Microsling Web Application</display-name>
+
+  <servlet>
+    <servlet-name>Logging</servlet-name>
+    <description>Configures the Log4J logging facility.</description>
+    <servlet-class>org.apache.jackrabbit.j2ee.LoggingServlet</servlet-class>
+
+    <init-param>
+      <param-name>log4j-config</param-name>
+      <param-value>/WEB-INF/log4j.xml</param-value>
+      <description>initial log4j configuration</description>
+    </init-param>
+
+    <load-on-startup>10</load-on-startup>
+  </servlet>
+
+  <servlet>
+    <servlet-name>JackrabbitRepository</servlet-name>
+    <description>
+      Creates a Jackrabbit repository (or opens it if already created) and makes it available as
+      a servlet context attribute.
+    </description>
+    <servlet-class>org.apache.jackrabbit.servlet.jackrabbit.JackrabbitRepositoryServlet</servlet-class>
+    <load-on-startup>20</load-on-startup>
+  </servlet>
+
+  <servlet>
+    <servlet-name>RepositoryAccess</servlet-name>
+    <description>
+      Used by the WebDAV servlet to access the repository
+    </description>
+    <servlet-class>org.apache.jackrabbit.j2ee.RepositoryAccessServlet</servlet-class>
+    
+    <init-param>
+      <param-name>repository.context.attribute.name</param-name>
+      <param-value>javax.jcr.Repository</param-value>
+    </init-param>
+    
+    <load-on-startup>40</load-on-startup>
+  </servlet>
+ 
+  <servlet>
+    <servlet-name>Webdav</servlet-name>
+    <description>Makes the repository available via WebDAV</description>
+    <servlet-class>org.apache.jackrabbit.j2ee.SimpleWebdavServlet</servlet-class>
+
+    <init-param>
+      <param-name>resource-path-prefix</param-name>
+      <param-value>/repository</param-value>
+      <description>defines the prefix for spooling resources out of the repository.</description>
+    </init-param>
+    <!--
+      <init-param>
+      <param-name>missing-auth-mapping</param-name>
+      <param-value>anonymous:anonymous</param-value>
+      <description>
+      Defines how a missing authorization header should be handled.
+      1) If this init-param is missing, a 401 response is generated.
+      This is suiteable for clients (eg. webdav clients) for which
+      sending a proper authorization header is not possible if the
+      server never sent a 401.
+      2) If this init-param is present with an empty value,
+      null-credentials are returned, thus forcing an null login
+      on the repository.
+      3) If this init-param has a 'user:password' value, the respective
+      simple credentials are generated.
+      </description>
+      </init-param>
+    -->
+    <!--
+      Optional parameter to define the value of the 'WWW-Authenticate' header
+    -->
+    <!--
+      <init-param>
+      <param-name>authenticate-header</param-name>
+      <param-value>Basic realm="Jackrabbit Webdav Server"</param-value>
+      <description>
+      Defines the value of the 'WWW-Authenticate' header.
+      </description>
+      </init-param>
+    -->
+    <!--
+      Parameter used to configure behaviour of webdav resources such as:
+      - destinction between collections and non-collections
+      - resource filtering
+    -->
+    <init-param>
+      <param-name>resource-config</param-name>
+      <param-value>/WEB-INF/webdav-resource-config.xml</param-value>
+      <description>Defines various dav-resource configuration parameters.</description>
+    </init-param>
+    <load-on-startup>50</load-on-startup>
+  </servlet>
+
+  <servlet>
+    <servlet-name>Microsling</servlet-name>
+    <description>Microsling support servlet</description>
+    <servlet-class>org.apache.sling.microsling.servlet.MicroslingMainServlet</servlet-class>
+
+    <init-param>
+      <param-name>container-encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+  
+    <init-param>
+      <param-name>form-encoding</param-name>
+      <param-value>UTF-8</param-value>
+    </init-param>
+  
+    <init-param>
+      <param-name>welcome-url</param-name>
+      <param-value>index.html</param-value>
+      <description>URL to redirect to when / is accessed</description>
+    </init-param>
+
+    <load-on-startup>999</load-on-startup>
+  </servlet>
+
+  <servlet-mapping>
+    <servlet-name>Microsling</servlet-name>
+    <url-pattern>/microsling/*</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>Webdav</servlet-name>
+    <url-pattern>/repository/*</url-pattern>
+  </servlet-mapping>
+  <servlet-mapping>
+    <servlet-name>JackrabbitRepository</servlet-name>
+    <url-pattern>/repository-info</url-pattern>
+  </servlet-mapping>
+
+  <!-- ====================================================================== -->
+  <!-- M I M E T Y P E   M A P P I N G                                          -->
+  <!-- ====================================================================== -->
+  <mime-mapping>
+    <extension>doc</extension>
+    <mime-type>application/msword</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>bin</extension>
+    <mime-type>application/octet-stream</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>pdf</extension>
+    <mime-type>application/pdf</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ai</extension>
+    <mime-type>application/postscript</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>eps</extension>
+    <mime-type>application/postscript</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ps</extension>
+    <mime-type>application/postscript</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>rtf</extension>
+    <mime-type>application/rtf</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>mif</extension>
+    <mime-type>application/vnd.mif</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ppt</extension>
+    <mime-type>application/vnd.ms-powerpoint</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>vcd</extension>
+    <mime-type>application/x-cdlink</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>js</extension>
+    <mime-type>application/x-javascript</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>mp3</extension>
+    <mime-type>audio/mpeg</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ram</extension>
+    <mime-type>audio/x-pn-realaudio</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>rm</extension>
+    <mime-type>audio/x-pn-realaudio</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>ra</extension>
+    <mime-type>audio/x-realaudio</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>gif</extension>
+    <mime-type>image/gif</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>jpeg</extension>
+    <mime-type>image/jpeg</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>jpg</extension>
+    <mime-type>image/jpeg</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>png</extension>
+    <mime-type>image/png</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>tiff</extension>
+    <mime-type>image/tiff</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>tif</extension>
+    <mime-type>image/tiff</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>css</extension>
+    <mime-type>text/css</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>asc</extension>
+    <mime-type>text/plain</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>txt</extension>
+    <mime-type>text/plain</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>xml</extension>
+    <mime-type>text/xml</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>html</extension>
+    <mime-type>text/html</mime-type>
+  </mime-mapping>
+  <mime-mapping>
+    <extension>htm</extension>
+    <mime-type>text/html</mime-type>
+  </mime-mapping>
+</web-app>

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/web.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/webdav-resource-config.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/webdav-resource-config.xml?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/webdav-resource-config.xml (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/webdav-resource-config.xml Thu Nov  1 06:30:00 2007
@@ -0,0 +1,162 @@
+<?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.
+  -->
+<!--
+<!DOCTYPE config [
+        <!ELEMENT config (iomanager , propertymanager, (collection | noncollection)? , filter?) >
+
+        <!ELEMENT iomanager (class, iohandler*) >
+        <!ELEMENT iohandler (class) >
+
+        <!ELEMENT propertymanager (class, propertyhandler*) >
+        <!ELEMENT propertyhandler (class) >
+
+        <!ELEMENT collection (nodetypes) >
+        <!ELEMENT noncollection (nodetypes) >
+
+        <!ELEMENT filter (class, namespaces?, nodetypes?) >
+
+        <!ELEMENT class >
+        <!ATTLIST class
+            name  CDATA #REQUIRED
+        >
+        <!ELEMENT namespaces (prefix | uri)* >
+        <!ELEMENT prefix (CDATA) >
+        <!ELEMENT uri (CDATA) >
+
+        <!ELEMENT nodetypes (nodetype)* >
+        <!ELEMENT nodetype (CDATA) >
+]>
+-->
+
+<config>
+    <!--
+    Defines the IOManager implementation that is responsible for passing import/export
+    request to the individual IO-handlers.
+    -->
+    <iomanager>
+        <!-- class element defines the manager to be used. The specified class
+             must implement the IOManager interface.
+             Note, that the handlers are being added and called in the order
+             they appear in the configuration.
+        -->
+        <class name="org.apache.jackrabbit.server.io.IOManagerImpl" />
+        <iohandler>
+            <class name="org.apache.jackrabbit.server.io.ZipHandler" />
+        </iohandler>
+        <iohandler>
+            <class name="org.apache.jackrabbit.server.io.XmlHandler" />
+        </iohandler>
+        <iohandler>
+            <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
+        </iohandler>
+        <iohandler>
+            <class name="org.apache.jackrabbit.server.io.DefaultHandler" />
+        </iohandler>
+    </iomanager>
+    <!--
+    Example config for iomanager that populates its list of handlers with
+    default values. Therefore the 'iohandler' elements are omited.
+    -->
+    <!--
+    <iomanager>
+        <class name="org.apache.jackrabbit.server.io.DefaultIOManager" />
+    </iomanager>
+    -->
+    <!--
+    Defines the PropertyManager implementation that is responsible for export
+    and import of resource properties.
+    -->
+    <propertymanager>
+        <!-- class element defines the manager to be used. The specified class
+             must implement the PropertyManager interface.
+             Note, that the handlers are being added and called in the order
+             they appear in the configuration.
+        -->
+        <class name="org.apache.jackrabbit.server.io.PropertyManagerImpl" />
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.ZipHandler" />
+        </propertyhandler>
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.XmlHandler" />
+        </propertyhandler>
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.DirListingExportHandler" />
+        </propertyhandler>
+        <propertyhandler>
+            <class name="org.apache.jackrabbit.server.io.DefaultHandler" />
+        </propertyhandler>
+    </propertymanager>
+    <!--
+    Define nodetypes, that should never by displayed as 'collection'
+    -->
+    <noncollection>
+        <nodetypes>
+            <nodetype>nt:file</nodetype>
+            <nodetype>nt:resource</nodetype>
+        </nodetypes>
+    </noncollection>
+    <!--
+    Example: Defines nodetypes, that should always be displayed as 'collection'.
+    -->
+    <!--
+    <collection>
+        <nodetypes>
+            <nodetype>nt:folder</nodetype>
+            <nodetype>rep:root</nodetype>
+        </nodetypes>
+    </collection>
+    -->
+    <!--
+     Filter that allows to prevent certain items from being displayed.
+     Please note, that this has an effect on PROPFIND calls only and does not
+     provide limited access to those items matching any of the filters.
+
+     However specifying a filter may cause problems with PUT or MKCOL if the
+     resource to be created is being filtered out, thus resulting in inconsistent
+     responses (e.g. PUT followed by PROPFIND on parent).
+     -->
+    <filter>
+        <!-- class element defines the resource filter to be used. The specified class
+             must implement the ItemFilter interface -->
+        <class name="org.apache.jackrabbit.webdav.simple.DefaultItemFilter" />
+        <!-- Nodetype names to be used to filter child nodes.
+             A child node can be filtered if the declaring nodetype of its definition
+             is one of the nodetype names specified in the nodetypes Element.
+             E.g. defining 'rep:root' as filtered nodetype whould result in jcr:system
+             being hidden but no other child node of the root node, since those
+             are defined by the nodetype nt:unstructered.
+        -->
+        <!--
+        <nodetypes>
+            <nodetype>rep:root</nodetype>
+        </nodetypes>
+        -->
+        <!-- Namespace prefixes or uris. Items having a name that matches any of the
+             entries will be filtered.
+        -->
+        <namespaces>
+            <prefix>rep</prefix>
+            <prefix>jcr</prefix>
+            <!--
+            <uri>internal</uri>
+            <uri>http://www.jcp.org/jcr/1.0</uri>
+            -->
+        </namespaces>
+    </filter>
+</config>
+

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/WEB-INF/webdav-resource-config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html Thu Nov  1 06:30:00 2007
@@ -0,0 +1,60 @@
+<html>
+<head>
+  <title>microsling content creation forms</title>
+  <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+  <h1>microsling content creation forms</h1>
+  
+  <div class="note">
+    <a href="../">back to homepage</a>
+  </div>
+  
+  <p>
+    Use these forms to test the microsling request processing and rendering SlingServlets. 
+  </p>
+  
+  <div>
+    <form class="testbox" action="microsling/content/testing.sling" method="POST">
+      <input type="hidden" name="slingDisplayExtension" value="html"/>
+      
+      <h1>SlingPostServlet content creation form</h1>
+      <p>
+        Submitting this form creates an <em>nt:unstructured</em> node under content/testing, 
+        and displays it using an <em>html</em> extension. 
+      </p>
+      <p>
+        See the <em>Velocity scripts</em> and <em>server-side Javascript</em> pages for how to
+        render the content using templates and scripts.
+      </p>
+      <p>
+	      Title:
+	      <br/>
+	      <input name="title" type="text" size="40" value="Default title"/>
+	      <br/> 
+	      Text:
+	      <br/>
+	      <input name="text" type="text" size="80" value="Default text of the test node"/>
+	      <br/>
+          slingResourceType:
+          <span class="note">(leave this empty to use the JCR node type for script resolution)</span>
+          <br/>
+          <input name="slingResourceType" type="text" size="80" value="microsling/example"/>
+          <br/>
+	      <input type="submit" value="Create and display node"/> 
+      </p>
+    </form>
+  </div>
+  
+  <div>
+    <form class="testbox" action="microsling/whatever" method="POST">
+      <h1>Non-Sling POST method form</h1>
+      <p>
+      	Submitting this form should cause an error 501: <em>POST method is not supported by DefaultSlingServlet</em>.
+      </p>
+      <input type="submit"/>
+    </form>
+  </div>
+  
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/content-creation-forms.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/freemarker-scripts.html
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/webapp/freemarker-scripts.html?rev=590999&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/main/webapp/freemarker-scripts.html (added)
+++ incubator/sling/trunk/microsling/microsling-core/src/main/webapp/freemarker-scripts.html Thu Nov  1 06:30:00 2007
@@ -0,0 +1,38 @@
+<html>
+<head>
+  <title>microsling FreeMarker templates</title>
+  <link rel="stylesheet" href="microsling.css"/>
+</head>
+<body>
+  <h1>microsling FreeMarker templates</h1>
+  
+  <div class="note">
+    <a href="../">back to homepage</a>
+  </div>
+  <p> 
+  	Scripts found by the <code>SlingScriptResolver</code> using the <code>.ftl</code> extension are executed by
+    the <code>FreemarkerScriptEngine</code>.
+  </p>
+  <p>
+    This works exactly like the <a href="velocity-scripts.html">Velocity templates</a>, except that
+    templates use the FreeMarker syntax.
+  </p>
+  <p>
+    Here's an example HTML template. See the <a href="http://freemarker.org">FreeMarker</a> website 
+    more info about the syntax.
+    <pre>&lt;html>
+&lt;body>
+&lt;h1>This is generated from a FreeMarker template&lt;/h1>
+&lt;p>
+  The current resource URI is &lt;b>${resource.URI}&lt;/b>
+&lt;/p>
+
+&lt;h2>${resource.getItem().getProperty("title").getString()}&lt;/h2>
+&lt;p>
+  ${resource.getItem().getProperty("text").getString()}
+&lt;/p>
+
+&lt;/body></pre>  
+  </p>
+</body>
+</html>
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/main/webapp/freemarker-scripts.html
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message