Author: alevkovsky
Date: 2008-11-05 10:54:28 -0500 (Wed, 05 Nov 2008)
New Revision: 11031
Modified:
trunk/sandbox/ui/editor/src/main/config/component/editor.xml
trunk/sandbox/ui/editor/src/main/config/resources/resources-config.xml
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java
Log:
Editor: basic attributes
getting mapping suffix in EditorHTMLRenderer
Modified: trunk/sandbox/ui/editor/src/main/config/component/editor.xml
===================================================================
--- trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-11-05 15:25:10 UTC
(rev 11030)
+++ trunk/sandbox/ui/editor/src/main/config/component/editor.xml 2008-11-05 15:54:28 UTC
(rev 11031)
@@ -26,6 +26,8 @@
</test>
</tag>
&ui_component_attributes;
+ &ui_input_attributes;
+ &ui_output_attributes;
<property>
<name>style</name>
<classname>java.lang.String</classname>
@@ -128,7 +130,7 @@
<name>onchange</name>
<classname>java.lang.String</classname>
<description>
- Attribute enables to specify a function name to be executed when all editor instances
have finished their initialization.
+ Attribute enables to specify a function name to be executed each time content is
modified by TinyMCE.
</description>
</property>
<property>
@@ -152,5 +154,15 @@
Attribute defines configuration properties file name
</description>
</property>
+ <property hidden="true">
+ <name>localValueSet</name>
+ <classname>boolean</classname>
+ <description>localValueSet</description>
+ </property>
+ <property hidden="true">
+ <name>valid</name>
+ <classname>boolean</classname>
+ <description>valid</description>
+ </property>
</component>
</components>
Modified: trunk/sandbox/ui/editor/src/main/config/resources/resources-config.xml
===================================================================
--- trunk/sandbox/ui/editor/src/main/config/resources/resources-config.xml 2008-11-05
15:25:10 UTC (rev 11030)
+++ trunk/sandbox/ui/editor/src/main/config/resources/resources-config.xml 2008-11-05
15:54:28 UTC (rev 11031)
@@ -5056,11 +5056,11 @@
<renderer class="org.ajax4jsf.resource.ScriptRenderer"/>
</resource>
<resource>
- <name>1$1.js</name>
+ <name>org/richfaces/renderkit/html/1$1.js</name>
<path>org/richfaces/renderkit/html/1$1.js</path>
</resource>
<resource>
- <name>1$1.xcss</name>
+ <name>org/richfaces/renderkit/html/1$1.xcss</name>
<path>org/richfaces/renderkit/html/1$1.xcss</path>
</resource>
</resource-config>
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-11-05
15:25:10 UTC (rev 11030)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/EditorRendererBase.java 2008-11-05
15:54:28 UTC (rev 11031)
@@ -22,21 +22,17 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
-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.resource.InternetResource;
import org.ajax4jsf.util.InputUtils;
import org.richfaces.component.UIEditor;
@@ -47,36 +43,14 @@
*/
public class EditorRendererBase extends InputRendererBase {
- private final static String SPECIFIC_SCRIPT_RESOURCE_NAME = "1$1.js";
- private final static String SPECIFIC_XCSS_RESOURCE_NAME = "1$1.xcss";
+ private final static String SPECIFIC_SCRIPT_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.js";
+ private final static String SPECIFIC_XCSS_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.xcss";
@Override
protected Class<? extends UIComponent> getComponentClass() {
return UIEditor.class;
}
- 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());
- }
- }
- 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)
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java 2008-11-05
15:25:10 UTC (rev 11030)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/renderkit/resources/EditorHTMLRenderer.java 2008-11-05
15:54:28 UTC (rev 11031)
@@ -28,11 +28,13 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import javax.faces.context.FacesContext;
+
import org.ajax4jsf.Messages;
import org.ajax4jsf.resource.BaseResourceRenderer;
import org.ajax4jsf.resource.InternetResource;
+import org.ajax4jsf.resource.InternetResourceBuilder;
import org.ajax4jsf.resource.ResourceContext;
-import org.ajax4jsf.webapp.WebXml;
/**
* Editor html pages renderer - used for correcting scripts src
@@ -41,6 +43,9 @@
*/
public class EditorHTMLRenderer extends BaseResourceRenderer {
+ private final static String SPECIFIC_SCRIPT_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.js";
+ private final static String SPECIFIC_XCSS_RESOURCE_NAME =
"org/richfaces/renderkit/html/1$1.xcss";
+
/**
* @see org.ajax4jsf.resource.BaseResourceRenderer#getCommonAttrs()
*/
@@ -87,14 +92,9 @@
throw new IOException(message);
}
int total;
-
+
// update scripts src
- String mappingSuffix = getFacesMappingSuffix(base);
- if (mappingSuffix != null) {
- total = updateAndSendResource(in, out, mappingSuffix);
- } else {
- total = sendStream(in, out);
- }
+ total = updateAndSendResource(in, out);
return total;
}
@@ -103,36 +103,37 @@
* Method to correct scripts src
* @param resource
*/
- private int updateAndSendResource(InputStream in, OutputStream out,
- String mappingSuffix) throws IOException {
+ private int updateAndSendResource(InputStream in, OutputStream out) throws IOException
{
//TODO Pasha, replace with regular expression if needed?
int total = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
+ String scriptSuffix = getSriptMappingSuffix();
+ String cssSuffix = getCssMappingSuffix();
try {
while (br.ready()) {
String line = br.readLine();
- if(line.indexOf("script") != -1 && line.indexOf("src=")
!= -1){
+ if(scriptSuffix != null && line.indexOf("script") != -1 &&
line.indexOf("src=") != -1){
if (line.indexOf(".js") != -1) {
- line = line.replace(".js", ".js" + mappingSuffix);
+ line = line.replace(".js", ".js" + scriptSuffix);
}
}
- if(line.indexOf("img") != -1 && line.indexOf("src=") !=
-1 && line.indexOf("src=\"http:") == -1){
+ if(scriptSuffix != null && line.indexOf("img") != -1 &&
line.indexOf("src=") != -1 && line.indexOf("src=\"http:")
== -1){
if (line.indexOf(".gif") != -1) {
- line = line.replace(".gif", ".gif" + mappingSuffix);
+ line = line.replace(".gif", ".gif" + scriptSuffix);
}
if (line.indexOf(".png") != -1) {
- line = line.replace(".png", ".png" + mappingSuffix);
+ line = line.replace(".png", ".png" + scriptSuffix);
}
if (line.indexOf(".jpg") != -1) {
- line = line.replace(".jpg", ".jpg" + mappingSuffix);
+ line = line.replace(".jpg", ".jpg" + scriptSuffix);
}
}
- if(line.indexOf("link") != -1 && line.indexOf("href=") !=
-1){
+ if(cssSuffix != null && line.indexOf("link") != -1 &&
line.indexOf("href=") != -1){
if (line.indexOf(".css") != -1) {
- line = line.replace(".css", ".xcss" + mappingSuffix);
+ line = line.replace(".css", ".xcss" + cssSuffix);
}
}
bw.write(line);
@@ -149,31 +150,24 @@
return total;
}
- /**
- * Method to get servlet mapping suffix
- *
- * @param context
- * @return
- */
- private String getFacesMappingSuffix(InternetResource resource) {
- WebXml webXml = WebXml.getInstance();
- String suffix = webXml.getFacesServletSuffix();
- String prefix = webXml.getFacesServletPrefix();
- String filterPrefix = webXml.getFacesFilterPrefix();
- String filterSuffix = webXml.getFacesFilterSuffix();
- if (filterPrefix != null) {
- return null;
+ private String getSriptMappingSuffix() {
+ return getResourceSuffix(SPECIFIC_SCRIPT_RESOURCE_NAME);
+ }
+
+ private String getCssMappingSuffix() {
+ return getResourceSuffix(SPECIFIC_XCSS_RESOURCE_NAME);
+ }
+
+ private String getResourceSuffix(String resourceName) {
+ InternetResourceBuilder builder = InternetResourceBuilder.getInstance();
+ InternetResource resource = builder.getResource(resourceName);
+ String resourceUri = resource.getUri(FacesContext.getCurrentInstance(), null);
+ String suffix = resourceUri.substring(resourceUri.indexOf(resourceName)
+ + resourceName.length());
+ if (suffix != null && suffix.length() == 0) {
+ suffix = null;
}
- if (filterSuffix != null) {
- return filterSuffix;
- }
- if (prefix != null) {
- return null;
- }
- if (suffix != null) {
- return suffix;
- }
- return null;
+ return suffix;
}
/**