Author: alevkovsky
Date: 2008-09-22 12:32:22 -0400 (Mon, 22 Sep 2008)
New Revision: 10535
Added:
trunk/sandbox/ui/editor/src/main/resources/org/richfaces/renderkit/html/scripts/editor.js
Modified:
trunk/sandbox/ui/editor/src/main/config/component/editor.xml
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/TinyMceLoaderServlet.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java
trunk/sandbox/ui/editor/src/main/templates/editor.jspx
Log:
Adding basic attributes for Editor
Modified: trunk/sandbox/ui/editor/src/main/config/component/editor.xml
===================================================================
--- trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-09-22 16:26:48 UTC
(rev 10534)
+++ trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-09-22 16:32:22 UTC
(rev 10535)
@@ -34,5 +34,21 @@
</description>
<defaultvalue>"TinyMCE"</defaultvalue>
</property>
+ <property>
+ <name>width</name>
+ <classname>int</classname>
+ <description>
+ Attribute defines width of component. Default value is "300".
+ </description>
+ <defaultvalue>300</defaultvalue>
+ </property>
+ <property>
+ <name>height</name>
+ <classname>int</classname>
+ <description>
+ Attribute defines height of component. Default value is "200".
+ </description>
+ <defaultvalue>200</defaultvalue>
+ </property>
</component>
</components>
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/TinyMceLoaderServlet.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/TinyMceLoaderServlet.java 2008-09-22
16:26:48 UTC (rev 10534)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/TinyMceLoaderServlet.java 2008-09-22
16:32:22 UTC (rev 10535)
@@ -12,76 +12,87 @@
import org.apache.commons.logging.LogFactory;
/**
- * Servlet for loading TinyMCE resources
+ * Servlet for loading TinyMCE resources
*
- * @web.servlet name="TinyMCELoaderServlet" display-name="TinyMCE Loader
Servlet"
+ * @web.servlet name="TinyMCELoaderServlet" display-name="TinyMCE Loader
+ * Servlet"
*
* @web.servlet-mapping
url-pattern="/a4j/g/3_3_0-SNAPSHOTorg/richfaces/renderkit/html/scripts/tiny_mce/*"
*
* @author Alexandr Levkovsky
- *
+ *
*/
public class TinyMceLoaderServlet extends javax.servlet.http.HttpServlet {
- private static final long serialVersionUID = 1L;
- protected final Log logger = LogFactory.getLog(getClass());
-
- private static final String TINYMCE_RESOURCES_LOCATION =
"org/richfaces/renderkit/html/scripts/tiny_mce";
+ private static final long serialVersionUID = 1L;
+ protected final Log logger = LogFactory.getLog(getClass());
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException {
- String path = TINYMCE_RESOURCES_LOCATION + request.getPathInfo();
- try {
+ private static final String TINYMCE_RESOURCES_LOCATION =
"org/richfaces/renderkit/html/scripts/tiny_mce";
- copyFileToOutput(path, response.getOutputStream());
+ protected void doGet(HttpServletRequest request,
+ HttpServletResponse response) throws ServletException {
+ String requestedResource = request.getPathInfo();
+ if (requestedResource.indexOf(".jsf") > 0) {
+ requestedResource = requestedResource.split(".jsf")[0];
+ }
+ String path = TINYMCE_RESOURCES_LOCATION + requestedResource;
+ try {
- } catch (Exception e) {
- e.printStackTrace();
- }
+ if(requestedResource.indexOf(".js") > 0){
+ response.setContentType("text/javascript");
+ }
+ copyFileToOutput(path, response.getOutputStream());
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- /**
- * Open input stream using path to file
- * @param path
- * @return
- */
- private InputStream getFileStream(String path) {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- InputStream is = cl.getResourceAsStream(path);
+ }
- return is;
- }
+ /**
+ * Open input stream using path to file
+ *
+ * @param path
+ * @return
+ */
+ private InputStream getFileStream(String path) {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ InputStream is = cl.getResourceAsStream(path);
- /**
- * Copies file to output stream
- * @param path
- * @param os
- */
- private void copyFileToOutput(String path, OutputStream os) {
- InputStream is = getFileStream(path);
+ return is;
+ }
- try {
- if (is != null) {
+ /**
+ * Copies file to output stream
+ *
+ * @param path
+ * @param os
+ */
+ private void copyFileToOutput(String path, OutputStream os) {
+ InputStream is = getFileStream(path);
- int size = is.available();
- byte[] buf = new byte[size];
- int i = 0;
- while ((i = is.read(buf)) != -1) {
- os.write(buf, 0, i);
- }
- } else {
- logger.warn("Cannot load TinyMCE resource: " + path);
- }
- } catch (IOException ioex) {
- logger.warn("Cannot load TinyMCE resource: " + path);
- } finally {
- if (is != null) {
try {
- is.close();
+ if (is != null) {
+
+ int size = is.available();
+ byte[] buf = new byte[size];
+ int i = 0;
+ while ((i = is.read(buf)) != -1) {
+ os.write(buf, 0, i);
+ }
+ } else {
+ logger.warn("Cannot load TinyMCE resource: " + path);
+ }
} catch (IOException ioex) {
- //just ignore it here
+ logger.warn("Cannot load TinyMCE resource: " + path);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException ioex) {
+ // just ignore it here
+ }
+ }
}
- }
}
- }
}
Modified: trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java
===================================================================
--- trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java 2008-09-22
16:26:48 UTC (rev 10534)
+++ trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java 2008-09-22
16:32:22 UTC (rev 10535)
@@ -6,24 +6,32 @@
package org.richfaces.component;
-import javax.faces.component.UIComponentBase;
+import javax.faces.component.UIInput;
/**
* JSF component class
* @author Alexandr Levkovsky
*
*/
-public abstract class UIEditor extends UIComponentBase {
+public abstract class UIEditor extends UIInput {
- public static final String COMPONENT_TYPE = "org.richfaces.Editor";
+ public static final String COMPONENT_TYPE = "org.richfaces.Editor";
- public static final String COMPONENT_FAMILY = "org.richfaces.Editor";
-
- public abstract void setType(String type);
+ public static final String COMPONENT_FAMILY = "org.richfaces.Editor";
- public abstract String getType();
+ public abstract void setType(String type);
- public boolean getRendersChildren() {
- return true;
- }
+ public abstract String getType();
+
+ public abstract int getWidth();
+
+ public abstract void setWidth(int width);
+
+ public abstract int getHeight();
+
+ public abstract void setHeight(int height);
+
+ public boolean getRendersChildren() {
+ return true;
+ }
}
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java 2008-09-22
16:26:48 UTC (rev 10534)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java 2008-09-22
16:32:22 UTC (rev 10535)
@@ -29,38 +29,57 @@
import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.convert.ConverterException;
import org.ajax4jsf.javascript.ScriptUtils;
-import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.util.InputUtils;
import org.richfaces.component.UIEditor;
+
/**
* @author Pavel Yaschenko - mailto:pyaschenko@exadel.com created 09.17.2008
*
*/
-public class EditorRendererBase extends HeaderResourcesRendererBase {
+public class EditorRendererBase extends InputRendererBase {
- @Override
- protected Class<? extends UIComponent> getComponentClass() {
- return UIEditor.class;
- }
+ @Override
+ protected Class<? extends UIComponent> getComponentClass() {
+ return UIEditor.class;
+ }
- public void writeEditorScript(FacesContext context, UIEditor component) throws
IOException {
+ public void writeEditorScriptParameters(FacesContext context,
+ UIEditor component) throws IOException {
- ResponseWriter writer = context.getResponseWriter();
- List<UIComponent> children = component.getChildren();
- Map<String, Object> params = new HashMap<String, Object>();
- for (UIComponent child : children) {
- UIParameter c = (UIParameter) child;
- if (c instanceof UIParameter) {
- params.put(c.getName(), c.getValue());
- }
+ ResponseWriter writer = context.getResponseWriter();
+ List<UIComponent> children = component.getChildren();
+ Map<String, Object> params = new HashMap<String, Object>();
+ for (UIComponent child : children) {
+ UIParameter c = (UIParameter) child;
+ if (c instanceof UIParameter) {
+ params.put(c.getName(), c.getValue());
+ }
+ }
+ if (component.getType() != null
+ && component.getType().equalsIgnoreCase("TinyMCE")) {
+ writer.writeText("//<![CDATA[ \n", null);
+ writer.writeText("tinyMCE.init(", null);
+ writer.writeText(ScriptUtils.toScript(params), null);
+ writer.writeText(");", null);
+ writer.writeText("\n //]]>", null);
+ } else {
+ // TODO add supporting for other types
+ }
}
- if (component.getType() != null &&
component.getType().equalsIgnoreCase("TinyMCE")) {
- writer.writeText("tinyMCE.init(", null);
- writer.writeText(ScriptUtils.toScript(params), null);
- writer.writeText(");", null);
- } else {
- // TODO add supporting for other types
+
+ @Override
+ public Object getConvertedValue(FacesContext context,
+ UIComponent component, Object submittedValue)
+ throws ConverterException {
+ return InputUtils.getConvertedValue(context, component, submittedValue);
}
- }
+
+ protected String getConvertedStringValue(FacesContext context,
+ UIEditor component, Object value) {
+ return InputUtils.getConvertedStringValue(context, component, value);
+ }
+
}
Added:
trunk/sandbox/ui/editor/src/main/resources/org/richfaces/renderkit/html/scripts/editor.js
===================================================================
Property changes on:
trunk/sandbox/ui/editor/src/main/resources/org/richfaces/renderkit/html/scripts/editor.js
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/sandbox/ui/editor/src/main/templates/editor.jspx
===================================================================
--- trunk/sandbox/ui/editor/src/main/templates/editor.jspx 2008-09-22 16:26:48 UTC (rev
10534)
+++ trunk/sandbox/ui/editor/src/main/templates/editor.jspx 2008-09-22 16:32:22 UTC (rev
10535)
@@ -1,31 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<f:root
-
xmlns:f="http://jsf.exadel.com/template"
- xmlns:vcp="
http://jsf.exadel.com/vcp"
- xmlns:ui="
http://jsf.exadel.com/ui"
- xmlns:x="
http://jsf.exadel.com/vcp"
-
xmlns:u="http://jsf.exadel.com/util"
-
xmlns:h="http://jsf.exadel.com/header"
+
xmlns:f="http://ajax4jsf.org/cdk/template"
+ xmlns:c="
http://java.sun.com/jsf/core"
+ xmlns:ui="
http://ajax4jsf.org/cdk/ui"
+ xmlns:u="
http://ajax4jsf.org/cdk/u"
+ xmlns:jsp="
http://ajax4jsf.org/cdk/jsp"
+ xmlns:x="
http://ajax4jsf.org/cdk/x"
baseclass="org.richfaces.renderkit.EditorRendererBase"
class="org.richfaces.renderkit.html.EditorRenderer"
component="org.richfaces.component.UIEditor">
<f:clientid var="clientId"/>
<h:styles>css/editor.xcss</h:styles>
-
<h:scripts>/org/richfaces/renderkit/html/scripts/tiny_mce/tiny_mce_src.js</h:scripts>
- <div id="#{clientId}"
x:passThruWithExclusions="id,value,styleClass,class" class="rich-editor
#{component.attributes['styleClass']}">
-
- <script type="text/javascript">
- <f:call name="writeEditorScript"></f:call>
- </script>
-
-
- <textarea id="elm1" name="elm1" rows="15"
cols="80" style="width: 100%">
- <p>Some paragraph</p>
- <p>Some other paragraph</p>
- <p>Some <b>element</b>, this is to be editor
1. <br /> This editor instance has a 100% width to it.
- <p>Some paragraph. <a
href="http://www.sourceforge.net">Some
link</a></p>
+ <h:scripts>scripts/tiny_mce/tiny_mce_src.js,
scripts/editor.js</h:scripts>
+ <div id="#{clientId}"
x:passThruWithExclusions="id,value,styleClass,class"
+ class="rich-editor #{component.attributes['styleClass']}">
+
+ <textarea id="#{clientId}TextArea" name='#{clientId}'
+ style="width: #{component.attributes['width']}px; height:
#{component.attributes['height']}px;">
+ <jsp:scriptlet>
+ <![CDATA[
+ String fieldValue = (String)component.getSubmittedValue();
+ if (fieldValue == null) {
+ fieldValue = getConvertedStringValue(context, component, component.getValue());
+ }
+ variables.setVariable("fieldValue", fieldValue);
+ writer.write(fieldValue);
+ ]]>
+ </jsp:scriptlet>
</textarea>
-
+
+ <script type="text/javascript">
+ <f:call name="writeEditorScriptParameters" />
+ </script>
</div>
</f:root>