Author: abelevich
Date: 2008-11-21 12:29:09 -0500 (Fri, 21 Nov 2008)
New Revision: 11295
Added:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java
Log:
add marker interface for the seam text converter impl, add default seam text converter
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-11-21
16:46:20 UTC (rev 11294)
+++ trunk/sandbox/ui/editor/src/main/java/org/richfaces/component/UIEditor.java 2008-11-21
17:29:09 UTC (rev 11295)
@@ -30,7 +30,9 @@
import javax.faces.component.UIInput;
import javax.faces.convert.Converter;
+import org.richfaces.convert.seamtext.DefaultSeamTextConverter;
import org.richfaces.convert.seamtext.SeamTextConverter;
+import org.richfaces.convert.seamtext.SeamTextConverterFactory;
/**
* JSF component class
@@ -48,7 +50,7 @@
/** Id suffix of textarea which used as target element for tinyMCE scripts*/
public static final String EDITOR_TEXT_AREA_ID_SUFFIX = "TextArea";
- private SeamTextConverter defaultSeamTextConverter = new SeamTextConverter();
+ private SeamTextConverterFactory converterFactory = new SeamTextConverterFactory();
public abstract void setType(String type);
@@ -140,7 +142,7 @@
public Converter getConverter() {
Converter converter = super.getConverter();
if(isUseSeamText() && converter == null) {
- converter = defaultSeamTextConverter;
+ return converterFactory.getConverter();
}
return converter;
}
Added:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
(rev 0)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java 2008-11-21
17:29:09 UTC (rev 11295)
@@ -0,0 +1,99 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/*
+ * SeamTextConverter.java Date created: 26.09.2008
+ * Last modified by: $Author: alevkovsky $
+ * $Revision: 11244 $ $Date: 2008-11-19 18:45:36 +0200 (Wed, 19 Nov 2008) $
+ */
+
+package org.richfaces.convert.seamtext;
+
+import java.io.Reader;
+import java.io.StringReader;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.ConverterException;
+
+import org.jboss.seam.text.SeamTextLexer;
+import org.jboss.seam.text.SeamTextParser;
+import org.richfaces.antlr.HtmlSeamTextLexer;
+import org.richfaces.antlr.HtmlSeamTextParser;
+
+/**
+ * Seam Text Converter class. Provides converting html to seam text and vice versa.
+ *
+ * @author Alexandr Levkovsky
+ *
+ */
+public final class DefaultSeamTextConverter implements SeamTextConverter {
+
+ /** The converter id for this converter. */
+ public static final String CONVERTER_ID = DefaultSeamTextConverter.class.getName();
+
+
+ private DefaultSeamTextConverter() {
+ }
+
+ private static class DefaultConverterHolder {
+ private static final SeamTextConverter INSTANCE = new DefaultSeamTextConverter();
+ }
+
+ public static SeamTextConverter getInstance() {
+ return DefaultConverterHolder.INSTANCE;
+ }
+
+ public Object getAsObject(FacesContext context, UIComponent component,
+ String value) {
+ try {
+
+ Reader r = new StringReader(value);
+ HtmlSeamTextLexer lexer = new HtmlSeamTextLexer(r);
+ HtmlSeamTextParser parser = new HtmlSeamTextParser(lexer);
+ parser.startRule();
+ return parser.toString();
+
+ } catch (Exception e) {
+ FacesMessage message = new FacesMessage("An error occurred during conversion
html to seam text",e.getMessage());
+ throw new ConverterException(message,e);
+ }
+ }
+
+ public String getAsString(FacesContext context, UIComponent component,
+ Object value) {
+ if (value == null) {
+ return "";
+ }
+ try {
+ Reader r = new StringReader(value.toString());
+ SeamTextLexer lexer = new SeamTextLexer(r);
+ SeamTextParser parser = new SeamTextParser(lexer);
+ parser.startRule();
+ return parser.toString();
+
+ } catch (Exception e) {
+ FacesMessage message = new FacesMessage("An error occurred during conversion seam
text to html",e.getMessage());
+ throw new ConverterException(message,e);
+ }
+ }
+}
Modified:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java 2008-11-21
16:46:20 UTC (rev 11294)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java 2008-11-21
17:29:09 UTC (rev 11295)
@@ -19,105 +19,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*
- * SeamTextConverter.java Date created: 26.09.2008
- * Last modified by: $Author: alevkovsky $
- * $Revision: 11244 $ $Date: 2008-11-19 18:45:36 +0200 (Wed, 19 Nov 2008) $
- */
-
package org.richfaces.convert.seamtext;
-import java.io.Reader;
-import java.io.StringReader;
-import java.lang.reflect.Constructor;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.seam.text.SeamTextLexer;
-import org.jboss.seam.text.SeamTextParser;
-import org.richfaces.antlr.HtmlSeamTextLexer;
-import org.richfaces.antlr.HtmlSeamTextParser;
-
-import antlr.ANTLRException;
-import antlr.RecognitionException;
-import antlr.TokenStream;
-
/**
- * Seam Text Converter class. Provides converting html to seam text and vice versa.
- *
- * @author Alexandr Levkovsky
- *
+ * @author Anton Belevich
+ * Marker interface for the Seam Text Converter
+ *
*/
-public class SeamTextConverter implements Converter {
-
- /** log4j instance for converter class */
- private static final Log _log = LogFactory.getLog(SeamTextConverter.class);
-
- /** The converter id for this converter. */
- public static final String CONVERTER_ID = SeamTextConverter.class.getName();
-
- /* (non-Javadoc)
- * @see javax.faces.convert.Converter#getAsObject(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.String)
- */
- @SuppressWarnings("unchecked")
- public Object getAsObject(FacesContext context, UIComponent component,
- String value) {
- try {
- Reader r = new StringReader(value);
- HtmlSeamTextLexer lexer = new HtmlSeamTextLexer(r);
- HtmlSeamTextParser parser = new HtmlSeamTextParser(lexer);
- parser.startRule();
- return parser.toString();
- } catch (RecognitionException rex) {
- // Log a nice message for any lexer/parser errors, users can disable
- // this if they want to
- _log.warn("Seam Text parse error: " + rex.getMessage());
- } catch (ANTLRException ex) {
- // All other errors are fatal;
- throw new RuntimeException(ex);
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext,
javax.faces.component.UIComponent, java.lang.Object)
- */
- @SuppressWarnings("unchecked")
- public String getAsString(FacesContext context, UIComponent component,
- Object value) {
- if (value == null) {
- return "";
- }
-
- SeamTextParser parser = null;
-
- try {
-
- Reader r = new StringReader(value.toString());
- Class seamTextLexerClass =
Class.forName("org.jboss.seam.text.SeamTextLexer");
- Class seamTextParserClass =
Class.forName("org.jboss.seam.text.SeamTextParser");
- Constructor seamTextLexerConstructor =
seamTextLexerClass.getConstructor(Reader.class);
- SeamTextLexer lexer = (SeamTextLexer) seamTextLexerConstructor.newInstance(new
Object[] { r });
- Constructor seamTextParserConstructor =
seamTextParserClass.getConstructor(TokenStream.class);
- parser = (SeamTextParser) seamTextParserConstructor.newInstance(new Object[] { lexer
});
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- try {
- parser.startRule();
- } catch (RecognitionException rex) {
- // Log a nice message for any lexer/parser errors, users can disable
- // this if they want to
- _log.warn("Seam Text parse error: " + rex.getMessage());
- } catch (ANTLRException ex) {
- // All other errors are fatal;
- throw new RuntimeException(ex);
- }
- return parser.toString();
- }
-
+public interface SeamTextConverter extends Converter {
}
Added:
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java
===================================================================
---
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java
(rev 0)
+++
trunk/sandbox/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java 2008-11-21
17:29:09 UTC (rev 11295)
@@ -0,0 +1,56 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.convert.seamtext;
+
+import java.lang.reflect.Method;
+
+import javax.faces.FacesException;
+
+/**
+ * Default seam text converter implementation factory
+ * @author Anton Belevich
+ *
+ */
+public class SeamTextConverterFactory {
+
+ private SeamTextConverter converter;
+
+
+ public SeamTextConverter getConverter() {
+ if(converter == null) {
+ converter = createSeamTextConverter();
+ }
+ return converter;
+ }
+
+ public SeamTextConverter createSeamTextConverter() {
+ try {
+
+ Class clazz =
Class.forName("org.richfaces.convert.seamtext.DefaultSeamTextConverter");
+ Method method = clazz.getMethod("getInstance");
+ return (SeamTextConverter) method.invoke(clazz);
+
+ } catch(Exception e) {
+ throw new FacesException(e);
+ }
+ }
+}