Author: jvazquez
Date: Fri Feb 20 19:54:41 2009
New Revision: 746348

URL: http://svn.apache.org/viewvc?rev=746348&view=rev
Log:
not needed sling:generator 

Added:
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/data.esp
      - copied, changed from r745630, 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/xml.esp
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/sample.xpl
Removed:
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/xml.esp
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/html.xpl
Modified:
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/cocoon/SlingGenerator.java
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/xproc/impl/PipelineImpl.java
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/pipelines.json
    
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/xsl/test-content.xslt

Modified: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/cocoon/SlingGenerator.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/cocoon/SlingGenerator.java?rev=746348&r1=746347&r2=746348&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/cocoon/SlingGenerator.java
 (original)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/cocoon/SlingGenerator.java
 Fri Feb 20 19:54:41 2009
@@ -18,14 +18,31 @@
  */
 package org.apache.sling.cocoon;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.util.Map;
 
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+
 import org.apache.cocoon.pipeline.component.sax.AbstractGenerator;
 import org.apache.cocoon.pipeline.util.XMLUtils;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.request.RequestDispatcherOptions;
 import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.SyntheticResource;
+import org.apache.sling.api.wrappers.SlingHttpServletResponseWrapper;
 
 public class SlingGenerator extends AbstractGenerator {
        
@@ -47,11 +64,80 @@
        
        @SuppressWarnings("unchecked")
        private InputStream genXml() throws Exception {
-               Resource resource = request.getResource();
-               Map props = resource.adaptTo(Map.class);
-               String absPathGen = props.get("sling:datasource").toString();
-               Resource genResource = 
request.getResourceResolver().resolve(absPathGen);
-               return genResource.adaptTo(InputStream.class);
+               RequestDispatcherOptions options = new 
RequestDispatcherOptions();
+               options.setForceResourceType("sling/xpl/sample/data");
+               RequestDispatcher dispatcher = 
request.getRequestDispatcher(request.getResource(), options);
+               SlingGeneratorServletOutputStream output = new 
SlingGeneratorServletOutputStream();
+               ServletResponse newResponse = new 
SlingGeneratorServletResponse(response, output);
+               dispatcher.include(request, newResponse);
+               byte[] bytes = output.toByteArray();
+               return new ByteArrayInputStream(bytes);
+       }
+       
+       protected class SlingGeneratorServletResponse 
+                                                               extends 
SlingHttpServletResponseWrapper implements SlingHttpServletResponse {
+               
+               private SlingGeneratorServletOutputStream output;
+               
+               private boolean hasWriter = false;
+               private boolean hasOutputStream  = false;
+               
+               public SlingGeneratorServletResponse(SlingHttpServletResponse 
wrappedResponse,
+                                                                               
                                SlingGeneratorServletOutputStream output) {
+                       super(wrappedResponse);
+                       this.output = output;
+               }
+               
+               @Override
+               public PrintWriter getWriter() throws IOException {
+                       if (this.hasOutputStream) {
+                               throw new 
IllegalStateException("getOutputStream was already called.");
+                       }
+                       this.hasWriter = true;
+                       return this.output.getWriter();
+               }
+               
+               @Override
+               public ServletOutputStream getOutputStream() throws IOException 
{
+                       if (this.hasWriter) {
+                               throw new IllegalStateException("getWriter was 
already called.");
+                       }
+                       this.hasOutputStream = true;
+                       return this.output;
+               }
+               
+               @Override
+               public int getBufferSize() {
+                       return 1024;
+               }
+               
+       }
+       
+       protected class SlingGeneratorServletOutputStream extends 
ServletOutputStream {
+               
+               private final ByteArrayOutputStream output;
+               private final PrintWriter writer;
+               
+               public SlingGeneratorServletOutputStream() throws 
UnsupportedEncodingException {
+                       this.output = new ByteArrayOutputStream();
+                       this.writer = new PrintWriter(new 
OutputStreamWriter(output, "UTF-8"));
+               }
+               
+               final PrintWriter getWriter() {
+                       return this.writer;
+               }
+               
+               @Override
+               public void write(int b) throws IOException {
+                       this.output.write(b);
+               }
+               
+               final byte[] toByteArray() {
+                       this.writer.flush();
+                       byte[] bytes = output.toByteArray();
+                       return bytes;
+               }
+               
        }
 
 }

Modified: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/xproc/impl/PipelineImpl.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/xproc/impl/PipelineImpl.java?rev=746348&r1=746347&r2=746348&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/xproc/impl/PipelineImpl.java
 (original)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/java/org/apache/sling/xproc/impl/PipelineImpl.java
 Fri Feb 20 19:54:41 2009
@@ -38,7 +38,6 @@
                org.apache.cocoon.pipeline.Pipeline cocoonPipeline = new 
NonCachingPipeline();
                
                cocoonPipeline.addComponent(generator);
-               
                Invocation invocation = new InvocationImpl();
                invocation.setCocoonPipeline(cocoonPipeline);
                this.invoke(invocation);

Copied: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/data.esp
 (from r745630, 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/xml.esp)
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/data.esp?p2=incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/data.esp&p1=incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/xml.esp&r1=745630&r2=746348&rev=746348&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/xml.esp
 (original)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/data/data.esp
 Fri Feb 20 19:54:41 2009
@@ -1,2 +1,23 @@
-<test/>
+<?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.
+-->
+<test>
+       <content>
+               xpl-sample: content
+       </content>
+</test>
 

Added: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/sample.xpl
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/sample.xpl?rev=746348&view=auto
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/sample.xpl
 (added)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/apps/sling/xpl/sample/sample.xpl
 Fri Feb 20 19:54:41 2009
@@ -0,0 +1,26 @@
+<?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.
+-->
+<p:pipeline xmlns:p="http://www.w3.org/ns/xproc";>
+
+  <p:xslt>
+    <p:input port="stylesheet">
+      <p:document 
href="http://localhost:8888/xpl-sample/xsl/test-content.xslt"/>
+    </p:input>
+  </p:xslt>
+  
+</p:pipeline>

Modified: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/pipelines.json
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/pipelines.json?rev=746348&r1=746347&r2=746348&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/pipelines.json
 (original)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/pipelines.json
 Fri Feb 20 19:54:41 2009
@@ -4,6 +4,5 @@
        "test_pipeline": {
                "title": "test_pipeline",
                "sling:resourceType": "sling/xpl/sample",
-               "sling:datasource": "/xpl-sample/test.xml"
        }
 }
\ No newline at end of file

Modified: 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/xsl/test-content.xslt
URL: 
http://svn.apache.org/viewvc/incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/xsl/test-content.xslt?rev=746348&r1=746347&r2=746348&view=diff
==============================================================================
--- 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/xsl/test-content.xslt
 (original)
+++ 
incubator/sling/whiteboard/jvazquez/org.apache.sling.scripting.xproc/src/main/resources/SLING-INF/content/xpl-sample/xsl/test-content.xslt
 Fri Feb 20 19:54:41 2009
@@ -17,6 +17,8 @@
 -->
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
   <xsl:template match="/test">
-    <content>A little bit of content.</content>
+       <result>
+       <xsl:value-of select="content"/>
+    </result>
   </xsl:template>
 </xsl:stylesheet>


Reply via email to