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

[EMAIL PROTECTED] 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to