Dear Wiki user, You have subscribed to a wiki page or wiki category on "Lenya Wiki" for change notification.
The following page has been changed by Kristen: http://wiki.apache.org/lenya/HowToIntegrateFCKEditor ------------------------------------------------------------------------------ = Integrating the FCKeditor with Lenya = - This is still very much a work in progress. This will get the famous FCKeditor (which we have nicknamed "Fred" to reduce snickering) to load with content, but the saving usecase has not been implemented yet (maybe next week). And we've only tried this with FCKeditor 2.1 and Lenya 2.2.1. Full credit for all this goes to K. Haenni. + This is still very much a work in progress. This will get the famous FCKeditor (which we have nicknamed "Fred" to reduce snickering) to load with content and save the content. However, validation still needs to be implemented, as well as asset insertion (maybe next week). And we've only tried this with FCKeditor 2.1 and Lenya 2.2.1. Full credit for all this goes to K. Haenni. 1. Make sure the Fred (the FCK Editor) is in the `lenya/webapp/lenya/resource/fckeditor` directory. This can be downloaded from http://www.fckeditor.net/. Remove any unnecessary folders and files in the fckeditor directory (anything that begins with an â_â). @@ -11, +11 @@ {{{ function invoke() { - var oFCKeditor = new FCKeditor( 'EditTextArea' ) ; + var oFCKeditor = new FCKeditor( 'content' ) ; oFCKeditor.ReplaceTextarea() ; } }}} @@ -55, +55 @@ <body onload="invoke();"> <form id="myform" action="/default/authoring/index.html?lenya.usecase=fckeditor&lenya.step=save" method="POST"> - <textarea id="EditTextArea" rows="40" cols="80"><xsl:copy-of select="xhtml:html/xhtml:body/node()"/></textarea> + <textarea id="content" rows="40" cols="80"><xsl:copy-of select="xhtml:html/xhtml:body/node()"/></textarea> </form> </body> @@ -96, +96 @@ a. Modify the `<!-- == Components == -->` section of the document to only contain `<map:components/>` - b. Replace `<map:match type="usecase" pattern="bxeng">` with `<map:match type="usecase" pattern="fckeditor">` + b. Modify `<map:match pattern="request2document">` to contain the following: + {{{ + <map:match pattern="request2document"> + <map:generate src="../../pubs/{page-envelope:publication-id}/work/frededitor/authoring/{page-envelope:document-id}.xml"/> + <map:transform src="../../xslt/fckeditor/savedContent.xsl"> + <map:parameter name="title" value="{dublincore:title}"/> + <map:parameter name="creator" value="{dublincore:creator}"/> + <map:parameter name="subject" value="{dublincore:subject}"/> + <map:parameter name="publisher" value="{dublincore:publisher}"/> + <map:parameter name="contributor" value="{dublincore:contributor}"/> + <map:parameter name="date" value="{dublincore:date}"/> + <map:parameter name="type" value="{dublincore:type}"/> + <map:parameter name="format" value="{dublincore:format}"/> + <map:parameter name="identifier" value="{dublincore:identifier}"/> + <map:parameter name="source" value="{dublincore:source}"/> + <map:parameter name="language" value="{dublincore:language}"/> + <map:parameter name="relation" value="{dublincore:relation}"/> + <map:parameter name="coverage" value="{dublincore:coverage}"/> + <map:parameter name="rights" value="{dublincore:rights}"/> + <map:parameter name="issued" value="{dublincore:issued}"/> + <map:parameter name="modified" value="{dublincore:modified}"/> + </map:transform> + <map:transform src="../../xslt/authoring/edit/unnumberTags.xsl"/> + <map:serialize type="xml"/> + </map:match> + }}} + + c. Replace `<map:match type="usecase" pattern="bxeng">` with `<map:match type="usecase" pattern="fckeditor">` + - c. Replace everything under `<!-- Check for BXENG -->` with the following: + d. Replace everything under `<!-- Check for BXENG -->` with the following: {{{ <!-- Check for FCK Editor --> @@ -125, +153 @@ <map:generate src="../../resources/misc/bxeng/download.xhtml"/> <map:call resource="style-cms-page"/> <map:serialize type="html"/> - </map:match> + </map:match> + + <map:match type="step" pattern="save"> + <map:act type="request-parameter-exists"> + <map:act type="frededitorsave"> + <map:parameter name="file" value="../../pubs/{page-envelope:publication-id}/work/frededitor/authoring/{page-envelope:document-id}.xml"/> + <map:parameter name="schema" value="../../pubs/{page-envelope:publication-id}/config/doctypes/schemas/{page-envelope:document-type}.rng"/> + <map:generate src="../../pubs/{page-envelope:publication-id}/content/authoring/{page-envelope:document-path}"/> + <map:call resource="style-cms-page"/> + </map:act> + <map:call function="editDocument"> + <map:parameter name="sourceUri" value="cocoon:/request2document"/> + <map:parameter name="useBuffer" value="false"/> + <map:parameter name="noStatus" value="false"/> + <map:parameter name="redirectUrl" value="{request:requestURI}"/> + </map:call> + </map:act> + </map:match> }}} - To get Fred to work with all your pubs, you will need to copy this `fckeditor-usecase.xmap` to each publication. + 7. Create a new Action in `org.apache.lenya.cms.cocoon.acting` called `FredSaveAction.java` (or whatever you'd like to call it) that saves the content to a temporary file. Mine looks like this: - This is still very much a work in progress. This will get Fred to load with content, but the saving usecase has not been implemented yet. In addition, the `fckeditor-usecase.xmap` needs to be cleaned up. Any suggestions or comments are welcome! + {{{ + package org.apache.lenya.cms.cocoon.acting; + + import java.io.File; + import java.io.FileOutputStream; + import java.io.OutputStreamWriter; + import java.io.Writer; + import java.net.URL; + import java.util.HashMap; + import java.util.Map; + + import org.apache.avalon.framework.parameters.Parameters; + import org.apache.avalon.framework.thread.ThreadSafe; + import org.apache.cocoon.acting.AbstractConfigurableAction; + import org.apache.cocoon.environment.ObjectModelHelper; + import org.apache.cocoon.environment.Redirector; + import org.apache.cocoon.environment.SourceResolver; + import org.apache.cocoon.environment.http.HttpRequest; + import org.apache.lenya.xml.DocumentHelper; + import org.apache.lenya.xml.RelaxNG; + import org.apache.log4j.Category; + import org.xml.sax.SAXException; + + + public class FredSaveAction + extends AbstractConfigurableAction + implements ThreadSafe { + Category log = Category.getInstance(FredSaveAction.class); + + /** + * Save data to temporary file + * + * @param redirector a <code>Redirector</code> value + * @param resolver a <code>SourceResolver</code> value + * @param objectModel a <code>Map</code> value + * @param source a <code>String</code> value + * @param parameters a <code>Parameters</code> value + * + * @return a <code>Map</code> value + * + * @exception Exception if an error occurs + */ + public Map act( + Redirector redirector, + SourceResolver resolver, + Map objectModel, + String source, + Parameters parameters) + throws Exception { + + HttpRequest request = (HttpRequest)ObjectModelHelper.getRequest(objectModel); + + // Aggregate content + String encoding = request.getCharacterEncoding(); + String content = "<?xml version=\"1.0\" encoding=\"" + + encoding + + "\"?>\n" + + "<head><meta content" + "<body>\n" + request.getParameter("content") +"\n" + "</body>\n"; + + // Save file temporarily + File sitemap = new File(new URL(resolver.resolveURI("").getURI()).getFile()); + File file = + new File( + sitemap.getAbsolutePath() + + File.separator + + parameters.getParameter("file")); + + File parentFile = new File(file.getParent()); + if (!parentFile.exists()) { + parentFile.mkdirs(); + } + FileOutputStream fileoutstream = new FileOutputStream(file); + Writer writer = new OutputStreamWriter(fileoutstream, encoding); + writer.write(content, 0, content.length()); + writer.close(); + + //TODO: Need to Validate content against schema. + + return null; + } + + } + + }}} + + This code is basically the same as `org.apache.lenya.cms.cocoon.acting.OneFormEditorSaveAction.java`, with a few modifications. Validation needs to be added here. + + 8. Add the following action to `lenya/sitemap.xmap`: + + {{{ + <map:action name="frededitorsave" logger="sitemap.action.frededitormsave" src="org.apache.lenya.cms.cocoon.acting.FredSaveAction" /> + }}} + + 9. Add a new xsl file to `lenya/xslt/fckeditor` called saveContent.xsl. It should look like the following: + + {{{ + <?xml version="1.0"?> + + <xsl:stylesheet version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns="http://www.w3.org/1999/xhtml" + xmlns:xhtml="http://www.w3.org/1999/xhtml" + xmlns:page="http://apache.org/cocoon/lenya/cms-page/1.0" + xmlns:lenya="http://apache.org/cocoon/lenya/page-envelope/1.0" + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:dcterms="http://purl.org/dc/terms/" + xmlns:i18n="http://apache.org/cocoon/i18n/2.1" + exclude-result-prefixes="page xhtml" + > + + <xsl:param name="title"/> + <xsl:param name="creator"/> + <xsl:param name="subject"/> + <xsl:param name="publisher"/> + <xsl:param name="contributor"/> + <xsl:param name="date"/> + <xsl:param name="type"/> + <xsl:param name="format"/> + <xsl:param name="identifier"/> + <xsl:param name="source"/> + <xsl:param name="language"/> + <xsl:param name="relation"/> + <xsl:param name="coverage"/> + <xsl:param name="rights"/> + <xsl:param name="issued"/> + <xsl:param name="modified"/> + + <xsl:template match="/"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <lenya:meta> + <dc:title><xsl:value-of select="$title"/></dc:title> + <dc:creator><xsl:value-of select="$creator"/></dc:creator> + <dc:subject><xsl:value-of select="$subject"/></dc:subject> + <dc:publisher><xsl:value-of select="$publisher"/></dc:publisher> + <dc:contributor><xsl:value-of select="$contributor"/></dc:contributor> + <dc:date><xsl:value-of select="$date"/></dc:date> + <dc:type><xsl:value-of select="$type"/></dc:type> + <dc:format><xsl:value-of select="$format"/></dc:format> + <dc:identifier><xsl:value-of select="$identifier"/></dc:identifier> + <dc:source><xsl:value-of select="$source"/></dc:source> + <dc:language><xsl:value-of select="$language"/></dc:language> + <dc:relation><xsl:value-of select="$relation"/></dc:relation> + <dc:coverage><xsl:value-of select="$coverage"/></dc:coverage> + <dc:rights><xsl:value-of select="$rights"/></dc:rights> + <dcterms:issued><xsl:value-of select="$issued"/></dcterms:issued> + <dcterms:modified><xsl:value-of select="$modified"/></dcterms:modified> + </lenya:meta> + <head> + <title><xsl:value-of select="$title"/></title> + </head> + <xsl:copy-of select="body"/> + </html> + </xsl:template> + + </xsl:stylesheet> + + }}} + + To get Fred to work with all your pubs, you will need to copy `fckeditor-usecase.xmap` to each publication. + + This is still very much a work in progress. This will get Fred to load with content and save the content, but the validation and asset insertion have not been implemented yet. In addition, I'm sure there's a better way to get the lenya tags in the document when saving rather than hard coding them in the xsl file. The `fckeditor-usecase.xmap` also needs to be cleaned up. Any suggestions or comments are welcome! Note: To change the height or width of the editor text area, go to `lenya/webapp/lenya/resources/fckeditor/fckeditor.js` and change the `width` and `height` properties. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
