[ 
https://issues.apache.org/jira/browse/COCOON3-77?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13144970#comment-13144970
 ] 

Andre Juffer commented on COCOON3-77:
-------------------------------------

# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Locally New
+++ Locally New
@@ -0,0 +1,150 @@
+/*
+ * 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.cocoon.optional.servlet.components.sax.serializers;
+
+import org.apache.cocoon.components.serializers.util.JsonSerializer;
+
+import 
org.apache.cocoon.optional.servlet.components.sax.serializers.util.ConfigurationUtils;
+import org.apache.cocoon.sax.SAXPipelineComponent;
+import org.apache.cocoon.pipeline.component.Finisher;
+import org.apache.cocoon.sax.SAXConsumer;
+import org.apache.cocoon.pipeline.component.CachingPipelineComponent;
+import org.apache.cocoon.pipeline.caching.CacheKey;
+import org.apache.cocoon.pipeline.caching.ParameterCacheKey;
+import org.apache.cocoon.pipeline.SetupException;
+import org.apache.cocoon.servlet.util.HttpContextHelper;
+
+import java.util.Map;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+/**
+ * <p>Usage in sitemap:
+ * <pre>
+ * &lt;map:serialize type='json' /&gt;
+ * </pre>
+ *
+
+ * @author Andr&#233; Juffer, Triacle Biocomputing
+ */
+public class EncodingJsonSerializer extends JsonSerializer 
+                                    implements SAXPipelineComponent, Finisher, 
SAXConsumer, CachingPipelineComponent {
+    
+    private String encoding;
+    private int indent = 0;
+    private String omitXmlDeclaration;
+    private String docType;
+    
+    public EncodingJsonSerializer()
+        throws Exception
+    {
+        super();
+    }
+    
+    @Override
+    public void setup(java.util.Map<java.lang.String, java.lang.Object> 
parameters)
+    {
+        this.setup(HttpContextHelper.getRequest(parameters));
+    }
+    
+    @Override
+    public void setConfiguration(Map<String,? extends Object> configuration)
+    {
+        try {
+            this.encoding = ConfigurationUtils.getEncoding(configuration);
+            this.setEncoding(this.encoding);
+        }
+        catch (UnsupportedEncodingException exception)
+        {
+              throw new SetupException(exception);
+       }
+
+        try {
+            this.indent = ConfigurationUtils.getIndent(configuration);
+            this.setIndentPerLevel(this.indent);
+        } 
+        catch (NumberFormatException exception)
+        {
+            throw new SetupException(exception);
+        }
+
+        this.omitXmlDeclaration = (String) 
configuration.get("omit-xml-declaration");
+        this.docType = (String) configuration.get("doctype-default");
+    }
+    
+    @Override
+    public void finish()
+    {
+        // Do nothing.
+    }
+    
+    @Override
+    public String getContentType()
+    {
+        return this.getMimeType();
+    }
+    
+    public CacheKey constructCacheKey()
+    {
+        ParameterCacheKey parameterCacheKey = new ParameterCacheKey();
+        parameterCacheKey.addParameter("encoding", this.encoding);
+        parameterCacheKey.addParameter("indent", this.indent);
+        parameterCacheKey.addParameter("docType", this.docType);
+        parameterCacheKey.addParameter("omitXmlDeclaration", 
this.omitXmlDeclaration);
+        return parameterCacheKey;
+    }
+    
+    @Override
+    public void setOutputStream(OutputStream outputStream)
+    {
+        try
+        {
+            super.setOutputStream(outputStream);
+       } 
+        catch (IOException exception)
+        {
+            throw new SetupException(exception);
+       }               
+    }
+    
+    @Override
+    public String toString()
+    {
+        String newline = System.getProperty("line.separator");
+        
+        StringBuilder s = new StringBuilder(this.getClass().getName() + 
newline);
+        s.append("charset - ").append(this.charset).append(newline);
+        s.append("docType - ").append(this.docType).append(newline);
+        if ( this.doctype != null )
+            s.append("doctype - 
").append(this.doctype.toString()).append(newline);
+        s.append("encoding - ").append(this.encoding).append(newline);
+        s.append("indent - ").append(this.indent).append(newline);
+        s.append("indentPerLevel - 
").append(this.indentPerLevel).append(newline);
+        if ( this.namespaces != null )
+            s.append("namespaces - 
").append(this.namespaces.toString()).append(newline);
+        s.append("omitXmlDeclaration - 
").append(this.omitXmlDeclaration).append(newline);
+        if ( this.request != null )
+            s.append("request - 
").append(this.request.toString()).append(newline);
+        s.append("mime-type - ").append(this.getMimeType()).append(newline);
+        s.append("]").append(newline);
+        
+        return s.toString();
+    }
+}

                
> Text and JSON serializers
> -------------------------
>
>                 Key: COCOON3-77
>                 URL: https://issues.apache.org/jira/browse/COCOON3-77
>             Project: Cocoon 3
>          Issue Type: Improvement
>          Components: cocoon-optional
>    Affects Versions: 3.0.0-alpha-3
>            Reporter: Andre Juffer
>            Priority: Minor
>         Attachments: EncodingJsonSerializer.java, 
> EncodingTextSerializer.java, JsonSerializer.java, TextEncoder.java, 
> TextSerializer.java, pom.xml, tribc-cocoon-3.xml
>
>
> Serveral classes have been created for serializing text and JSON in the 
> sitemap. The JsonSerializer also checks whether the JSON text actually is 
> valid. The organization of the classes follows the encoding serializers (such 
> as the EncodingHTMLSerializer).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to