You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by ch...@apache.org on 2006/09/21 19:16:13 UTC

svn commit: r448608 - in /lenya/trunk/src/modules: fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java xhtml/config/cocoon-xconf/resource-type-xhtml.xconf

Author: chestnut
Date: Thu Sep 21 10:16:12 2006
New Revision: 448608

URL: http://svn.apache.org/viewvc?view=rev&rev=448608
Log:
use resource types clean xslt format to clean xml from fckeditor before validation/save
*if this is a valid use of a format, webDAV needs to use the format: input module to access the clean-xhtml.xsl stylesheet as well
WebDAV module currently incorrectly assumes that the resource type and the module which contain it have the same name

Modified:
    lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java
    lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf

Modified: lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java?view=diff&rev=448608&r1=448607&r2=448608
==============================================================================
--- lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java (original)
+++ lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java Thu Sep 21 10:16:12 2006
@@ -24,7 +24,9 @@
 import java.io.StringWriter;
 import java.io.UnsupportedEncodingException;
 import java.io.Writer;
+import java.util.Arrays;
 import java.util.Properties;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
@@ -56,6 +58,7 @@
 public class Fckeditor extends DocumentUsecase {
     
     public static final String TIDY_CONFIG="tidyConfig";
+    public static final String XSLT_CLEAN_FORMAT="xslt-clean";
     
     
     /**
@@ -131,6 +134,7 @@
         SourceResolver resolver = null;
         Source indexSource = null;
         Source tidySource = null;
+        ModifiableSource xsltSource = null;
         Properties properties = null;
         try {
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
@@ -199,6 +203,31 @@
                 }
             }
             
+            //Try to clean the xml using xslt
+            ResourceType resType = getSourceDocument().getResourceType();
+            String[] formats = resType.getFormats();
+            if (Arrays.asList(formats).contains(XSLT_CLEAN_FORMAT)) {
+                StringWriter output = new StringWriter();
+                StreamResult strResult = new StreamResult(output);
+                TransformerFactory tfac = TransformerFactory.newInstance();
+                try {
+                    xsltSource = (ModifiableSource) resolver.resolveURI(resType.getFormatURI(XSLT_CLEAN_FORMAT));
+                    Transformer t = tfac.newTransformer(new StreamSource(xsltSource.getInputStream()));
+                    t.setOutputProperty(OutputKeys.ENCODING, encoding);
+                    t.setOutputProperty(OutputKeys.INDENT, "yes");
+                    t.setOutputProperty(OutputKeys.METHOD, "xml");
+                    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+                    xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
+                    t.transform(new DOMSource(xmlDoc.getDocumentElement()), strResult);
+                
+                    content = strResult.getWriter().toString();
+                } catch (Exception e) {
+                    addErrorMessage(e.getMessage());
+                }
+                
+                saveXMLFile(encoding, content, xmlSource);
+            }
+            
             if (xmlDoc != null) {
                 ResourceType resourceType = getSourceDocument().getResourceType();
                 Schema schema = resourceType.getSchema();
@@ -224,6 +253,9 @@
                 }
                 if (tidySource != null) {
                     resolver.release(tidySource);
+                }
+                if (xsltSource != null) {
+                    resolver.release(xsltSource);
                 }
                 this.manager.release(resolver);
             }

Modified: lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf?view=diff&rev=448608&r1=448607&r2=448608
==============================================================================
--- lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf (original)
+++ lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf Thu Sep 21 10:16:12 2006
@@ -35,6 +35,8 @@
     <format name="xhtml" uri="cocoon://modules/xhtml/xhtml.xml"/>
     <format name="webdavGET" uri="cocoon://modules/xhtml/davget.xml"/>
     <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index"/>
+    <!-- "xslt-clean" format is used by webDAV (and other editors?) to "clean" xml content before it is validated/saved --> 
+    <format name="xslt-clean" uri="fallback://lenya/modules/xhtml/xslt/clean-xhtml.xsl"/>
     <format name="icon" uri="cocoon://modules/xhtml/icon"/>
   </component-instance>
   



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org


Re: svn commit: r448608 - in /lenya/trunk/src/modules: fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java xhtml/config/cocoon-xconf/resource-type-xhtml.xconf

Posted by Andreas Hartmann <an...@apache.org>.
Doug Chestnut wrote:
> WDOT?  Is this a valid use of a format?

Hmmm, maybe that's a little beyond the borderline :)

BTW, I used the format "icon" for sitetree icons, this is
certainly a borderline case as well.

> I think not: " A resource type provides a set of formats to provide
> different ways of presenting content documents."
> 
> Should we add "resources" or "tools" to resource types?
> ({resource-type:tool-xsltClean}, {resource-type:resource-xsltClean})

Sounds good, but maybe a resource base URL would be sufficient?
This would be programming by convention rather than configuration,
but IMO we can accept this in this case, given that there is
sufficient documentation.

  {resource-type:{type}:resources:xslt/clean.xsl}
  {resource-type:{type}:resources:icon/{pub}/{area}/{uuid}/{language}}


-- Andreas


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org


Re: svn commit: r448608 - in /lenya/trunk/src/modules: fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java xhtml/config/cocoon-xconf/resource-type-xhtml.xconf

Posted by Doug Chestnut <dh...@virginia.edu>.
WDOT?  Is this a valid use of a format?

I think not: " A resource type provides a set of formats to provide 
different ways of presenting content documents."

Should we add "resources" or "tools" to resource types? 
({resource-type:tool-xsltClean}, {resource-type:resource-xsltClean})

--Doug

chestnut@apache.org wrote:
> Author: chestnut
> Date: Thu Sep 21 10:16:12 2006
> New Revision: 448608
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=448608
> Log:
> use resource types clean xslt format to clean xml from fckeditor before validation/save
> *if this is a valid use of a format, webDAV needs to use the format: input module to access the clean-xhtml.xsl stylesheet as well
> WebDAV module currently incorrectly assumes that the resource type and the module which contain it have the same name
> 
> Modified:
>     lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java
>     lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
> 
> Modified: lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java
> URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java?view=diff&rev=448608&r1=448607&r2=448608
> ==============================================================================
> --- lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java (original)
> +++ lenya/trunk/src/modules/fckeditor/java/src/org/apache/lenya/cms/editors/fckeditor/Fckeditor.java Thu Sep 21 10:16:12 2006
> @@ -24,7 +24,9 @@
>  import java.io.StringWriter;
>  import java.io.UnsupportedEncodingException;
>  import java.io.Writer;
> +import java.util.Arrays;
>  import java.util.Properties;
> +import javax.xml.transform.stream.StreamSource;
>  import javax.xml.transform.stream.StreamResult;
>  import javax.xml.transform.TransformerFactory;
>  import javax.xml.transform.dom.DOMSource;
> @@ -56,6 +58,7 @@
>  public class Fckeditor extends DocumentUsecase {
>      
>      public static final String TIDY_CONFIG="tidyConfig";
> +    public static final String XSLT_CLEAN_FORMAT="xslt-clean";
>      
>      
>      /**
> @@ -131,6 +134,7 @@
>          SourceResolver resolver = null;
>          Source indexSource = null;
>          Source tidySource = null;
> +        ModifiableSource xsltSource = null;
>          Properties properties = null;
>          try {
>              resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
> @@ -199,6 +203,31 @@
>                  }
>              }
>              
> +            //Try to clean the xml using xslt
> +            ResourceType resType = getSourceDocument().getResourceType();
> +            String[] formats = resType.getFormats();
> +            if (Arrays.asList(formats).contains(XSLT_CLEAN_FORMAT)) {
> +                StringWriter output = new StringWriter();
> +                StreamResult strResult = new StreamResult(output);
> +                TransformerFactory tfac = TransformerFactory.newInstance();
> +                try {
> +                    xsltSource = (ModifiableSource) resolver.resolveURI(resType.getFormatURI(XSLT_CLEAN_FORMAT));
> +                    Transformer t = tfac.newTransformer(new StreamSource(xsltSource.getInputStream()));
> +                    t.setOutputProperty(OutputKeys.ENCODING, encoding);
> +                    t.setOutputProperty(OutputKeys.INDENT, "yes");
> +                    t.setOutputProperty(OutputKeys.METHOD, "xml");
> +                    t.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
> +                    xmlDoc = DocumentHelper.readDocument(xmlSource.getInputStream());
> +                    t.transform(new DOMSource(xmlDoc.getDocumentElement()), strResult);
> +                
> +                    content = strResult.getWriter().toString();
> +                } catch (Exception e) {
> +                    addErrorMessage(e.getMessage());
> +                }
> +                
> +                saveXMLFile(encoding, content, xmlSource);
> +            }
> +            
>              if (xmlDoc != null) {
>                  ResourceType resourceType = getSourceDocument().getResourceType();
>                  Schema schema = resourceType.getSchema();
> @@ -224,6 +253,9 @@
>                  }
>                  if (tidySource != null) {
>                      resolver.release(tidySource);
> +                }
> +                if (xsltSource != null) {
> +                    resolver.release(xsltSource);
>                  }
>                  this.manager.release(resolver);
>              }
> 
> Modified: lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf
> URL: http://svn.apache.org/viewvc/lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf?view=diff&rev=448608&r1=448607&r2=448608
> ==============================================================================
> --- lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf (original)
> +++ lenya/trunk/src/modules/xhtml/config/cocoon-xconf/resource-type-xhtml.xconf Thu Sep 21 10:16:12 2006
> @@ -35,6 +35,8 @@
>      <format name="xhtml" uri="cocoon://modules/xhtml/xhtml.xml"/>
>      <format name="webdavGET" uri="cocoon://modules/xhtml/davget.xml"/>
>      <format name="luceneIndex" uri="cocoon://modules/xhtml/lucene-index"/>
> +    <!-- "xslt-clean" format is used by webDAV (and other editors?) to "clean" xml content before it is validated/saved --> 
> +    <format name="xslt-clean" uri="fallback://lenya/modules/xhtml/xslt/clean-xhtml.xsl"/>
>      <format name="icon" uri="cocoon://modules/xhtml/icon"/>
>    </component-instance>
>    
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
> For additional commands, e-mail: commits-help@lenya.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lenya.apache.org
For additional commands, e-mail: dev-help@lenya.apache.org