You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sv...@apache.org on 2005/01/02 21:39:16 UTC
cvs commit: incubator-myfaces/tlds myfaces_ext.tld
svieujot 2005/01/02 12:39:16
Modified: src/components/org/apache/myfaces/custom/htmlEditor
HtmlEditorRenderer.java HtmlEditor.java
HtmlEditorTag.java
tlds myfaces_ext.tld
Log:
HtmlEditor can now process HTML documents and HTML fragments.
Revision Changes Path
1.17 +12 -10 incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditorRenderer.java
Index: HtmlEditorRenderer.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditorRenderer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- HtmlEditorRenderer.java 27 Dec 2004 04:11:11 -0000 1.16
+++ HtmlEditorRenderer.java 2 Jan 2005 20:39:16 -0000 1.17
@@ -36,6 +36,9 @@
* @author Sylvain Vieujot (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.17 2005/01/02 20:39:16 svieujot
+ * HtmlEditor can now process HTML documents and HTML fragments.
+ *
* Revision 1.16 2004/12/27 04:11:11 mmarinschek
* Data Table stores the state of facets of children; script tag is rendered with type attribute instead of language attribute, popup works better as a column in a data table
*
@@ -95,9 +98,9 @@
return ((HtmlEditor)uiComponent).isDisabled();
}
- public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
- RendererUtils.checkParamValidity(context, component, HtmlEditor.class);
- HtmlEditor editor = (HtmlEditor) component;
+ public void encodeEnd(FacesContext context, UIComponent uiComponent) throws IOException {
+ RendererUtils.checkParamValidity(context, uiComponent, HtmlEditor.class);
+ HtmlEditor editor = (HtmlEditor) uiComponent;
String clientId = editor.getClientId(context);
String formId;
{
@@ -899,8 +902,7 @@
writer.endElement(HTML.DIV_ELEM); // kupu-fulleditor
- String value = RendererUtils.getStringValue(context, editor);
- String text = "<html><body>"+(value==null ? "" : value)+"</body></html>";
+ String text = editor.getValueAsHtmlDocument( context );
String encodedText = text == null ? "" : JavascriptUtils.encodeString( text );
boolean formularMode = editor.isEnableFlexiTools();
@@ -980,8 +982,8 @@
public Object getConvertedValue(FacesContext facesContext, UIComponent uiComponent, Object submittedValue) throws ConverterException {
RendererUtils.checkParamValidity(facesContext, uiComponent, HtmlEditor.class);
- return RendererUtils.getConvertedUIOutputValue(facesContext,
- (UIOutput)uiComponent,
- submittedValue);
+ HtmlEditor editor = (HtmlEditor) uiComponent;
+ String submittedDocument = (String) RendererUtils.getConvertedUIOutputValue(facesContext, editor, submittedValue);
+ return editor.getValueFromDocument( submittedDocument );
}
}
1.14 +96 -9 incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditor.java
Index: HtmlEditor.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditor.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- HtmlEditor.java 24 Dec 2004 13:21:50 -0000 1.13
+++ HtmlEditor.java 2 Jan 2005 20:39:16 -0000 1.14
@@ -18,7 +18,10 @@
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.component.html.ext.HtmlInputText;
+import org.apache.myfaces.renderkit.RendererUtils;
/**
* HTML Editor using the kupu library.
@@ -27,6 +30,9 @@
* @author Sylvain Vieujot (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.14 2005/01/02 20:39:16 svieujot
+ * HtmlEditor can now process HTML documents and HTML fragments.
+ *
* Revision 1.13 2004/12/24 13:21:50 matzew
* organized imports
*
@@ -71,9 +77,13 @@
private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.HtmlEditor";
+ private static final Log log = LogFactory.getLog(HtmlInputText.class);
+
private String _style;
private String _styleClass;
+ private String _type;
+
private Boolean _allowEditSource;
private Boolean _addKupuLogo;
@@ -94,7 +104,7 @@
}
public Object saveState(FacesContext context) {
- Object values[] = new Object[5];
+ Object values[] = new Object[6];
values[0] = super.saveState(context);
String[] display = new String[2];
@@ -103,11 +113,13 @@
values[1] = display;
+ values[2] = _type;
+
Boolean toolBarButtons[] = new Boolean[2];
toolBarButtons[0] = _allowEditSource;
toolBarButtons[1] = _addKupuLogo;
- values[2] = toolBarButtons;
+ values[3] = toolBarButtons;
Boolean toolBoxes[] = new Boolean[5];
toolBoxes[0] = _showPropertiesToolBox;
@@ -116,12 +128,12 @@
toolBoxes[3] = _showTablesToolBox;
toolBoxes[4] = _showDebugToolBox;
- values[3] = toolBoxes;
+ values[4] = toolBoxes;
Boolean tools[] = new Boolean[1];
tools[0] = _enableFlexiTools;
- values[4] = tools;
+ values[5] = tools;
return values;
}
@@ -134,18 +146,20 @@
_style = display[0];
_styleClass = display[1];
- Boolean[] toolBarButtons = (Boolean[]) values[2];
+ _type = (String) values[2];
+
+ Boolean[] toolBarButtons = (Boolean[]) values[3];
_allowEditSource = toolBarButtons[0];
_addKupuLogo = toolBarButtons[1];
- Boolean[] toolBoxes = (Boolean[]) values[3];
+ Boolean[] toolBoxes = (Boolean[]) values[4];
_showPropertiesToolBox = toolBoxes[0];
_showLinksToolBox = toolBoxes[1];
_showImagesToolBox = toolBoxes[2];
_showTablesToolBox = toolBoxes[3];
_showDebugToolBox = toolBoxes[4];
- Boolean[] tools = (Boolean[]) values[4];
+ Boolean[] tools = (Boolean[]) values[5];
_enableFlexiTools = tools[0];
}
@@ -169,6 +183,19 @@
this._styleClass = styleClass;
}
+ public String getType(){
+ if (_type != null)
+ return _type;
+ ValueBinding vb = getValueBinding("type");
+ return vb != null ? (String)vb.getValue(getFacesContext()) : "fragment";
+ }
+ public void setType(String _type){
+ this._type = _type;
+ }
+ public boolean isTypeDocument(){
+ return getType().equals("document");
+ }
+
public Boolean isAllowEditSource(){
if (_allowEditSource != null)
return _allowEditSource;
@@ -252,5 +279,65 @@
}
public void setEnableFlexiTools(boolean formularMode){
this._enableFlexiTools = Boolean.valueOf(formularMode);
+ }
+
+ public String getValueAsHtmlDocument(FacesContext context){
+ String val = RendererUtils.getStringValue(context, this);
+ if( isHtmlDocument( val ) )
+ return val;
+
+ return "<html><body>"+(val==null ? "" : val)+"</body></html>";
+ }
+
+ private static boolean isHtmlDocument(String text){
+ if( text == null )
+ return false;
+
+ if( text.indexOf("<body>")!=-1 || text.indexOf("<body ")!=-1
+ || text.indexOf("<BODY>")!=-1 || text.indexOf("<BODY ")!=-1 )
+ return true;
+
+ return false;
+ }
+
+ public String getValueFromDocument(String text){
+ if( isTypeDocument() )
+ return text;
+
+ if( !isHtmlDocument(text) )
+ return text;
+
+ // Extract the fragment from the document.
+ String lcText = text.toLowerCase();
+ int textLength = lcText.length();
+ int bodyStartIndex = 0;
+ while(bodyStartIndex < textLength){
+ bodyStartIndex = lcText.indexOf("<body");
+ if( bodyStartIndex == -1 )
+ break; // not found.
+
+ bodyStartIndex += 5;
+ char c = lcText.charAt(bodyStartIndex);
+ if( c=='>' ){
+ break;
+ }
+
+ if( c!=' ' && c!='\t' )
+ continue;
+
+ bodyStartIndex = lcText.indexOf('>', bodyStartIndex);
+ }
+ bodyStartIndex++;
+
+ int bodyEndIndex = lcText.lastIndexOf("</body>")-1;
+
+ if( bodyStartIndex<0 || bodyEndIndex<0
+ || bodyStartIndex > bodyEndIndex
+ || bodyStartIndex>=textLength || bodyEndIndex>=textLength ){
+ log.warn("Couldn't extract HTML body from :\n"+text);
+ return text;
+ }
+
+ return text.substring(bodyStartIndex, bodyEndIndex+1);
}
}
1.9 +10 -1 incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditorTag.java
Index: HtmlEditorTag.java
===================================================================
RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/htmlEditor/HtmlEditorTag.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- HtmlEditorTag.java 10 Dec 2004 02:16:26 -0000 1.8
+++ HtmlEditorTag.java 2 Jan 2005 20:39:16 -0000 1.9
@@ -24,6 +24,9 @@
* @author Sylvain Vieujot (latest modification by $Author$)
* @version $Revision$ $Date$
* $Log$
+ * Revision 1.9 2005/01/02 20:39:16 svieujot
+ * HtmlEditor can now process HTML documents and HTML fragments.
+ *
* Revision 1.8 2004/12/10 02:16:26 svieujot
* Start implementing UserRoleAware.
*
@@ -53,6 +56,7 @@
private String style;
private String styleClass;
+ private String type;
private String formularMode;
private String allowEditSource;
@@ -73,6 +77,7 @@
setStringProperty(component, "style", style);
setStringProperty(component, "styleClass", styleClass);
+ setBooleanProperty(component, "type", type);
setBooleanProperty(component, "formularMode", formularMode);
setBooleanProperty(component, "allowEditSource", allowEditSource);
@@ -102,6 +107,10 @@
public void setStyleClass(String styleClass){
this.styleClass = styleClass;
+ }
+
+ public void setType(String type){
+ this.type = type;
}
public void setFormularMode(String formularMode){
1.146 +9 -0 incubator-myfaces/tlds/myfaces_ext.tld
Index: myfaces_ext.tld
===================================================================
RCS file: /home/cvs/incubator-myfaces/tlds/myfaces_ext.tld,v
retrieving revision 1.145
retrieving revision 1.146
diff -u -r1.145 -r1.146
--- myfaces_ext.tld 22 Dec 2004 17:52:54 -0000 1.145
+++ myfaces_ext.tld 2 Jan 2005 20:39:16 -0000 1.146
@@ -855,6 +855,15 @@
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
+ <name>type</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ The type of the value. It can be either fragment for an HTML fragment (default)
+ or document for a full HTML document, with head, title, body, ... tags.
+ </description>
+ </attribute>
+ <attribute>
<name>formularMode</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>