[richfaces-svn-commits] JBoss Rich Faces SVN: r12089 - in trunk/ui/editor/src/main/java/org/richfaces: convert/seamtext and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Mon Jan 5 05:01:40 EST 2009


Author: abelevich
Date: 2009-01-05 05:01:39 -0500 (Mon, 05 Jan 2009)
New Revision: 12089

Removed:
   trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java
   trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java
Modified:
   trunk/ui/editor/src/main/java/org/richfaces/component/UIEditor.java
   trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
Log:
code refactoring

Modified: trunk/ui/editor/src/main/java/org/richfaces/component/UIEditor.java
===================================================================
--- trunk/ui/editor/src/main/java/org/richfaces/component/UIEditor.java	2009-01-05 09:25:14 UTC (rev 12088)
+++ trunk/ui/editor/src/main/java/org/richfaces/component/UIEditor.java	2009-01-05 10:01:39 UTC (rev 12089)
@@ -27,11 +27,10 @@
 
 package org.richfaces.component;
 
+import javax.faces.FacesException;
 import javax.faces.component.UIInput;
 import javax.faces.convert.Converter;
 
-import org.richfaces.convert.seamtext.SeamTextConverterFactory;
-
 /**
  * JSF component class
  * @author Alexandr Levkovsky
@@ -48,8 +47,7 @@
 	/** Id suffix of textarea which used as target element for tinyMCE  scripts*/
 	public static final String EDITOR_TEXT_AREA_ID_SUFFIX = "TextArea";
 	
-	//TODO nick - it's a bad idea to create converterFactory instance for each component
-	private SeamTextConverterFactory converterFactory = new SeamTextConverterFactory();
+	private Converter defaultSeamTextConverter = null;
 	
 	public abstract void setType(String type);
 
@@ -141,10 +139,17 @@
 	public Converter getConverter() {
 		Converter converter = super.getConverter();
 		if(isUseSeamText() && converter == null) {
-			return converterFactory.getConverter();
+			if(defaultSeamTextConverter == null) {
+				try {
+	//				create default seam text converter
+					Class clazz = Thread.currentThread().getContextClassLoader().loadClass("org.richfaces.convert.seamtext.DefaultSeamTextConverter");
+					defaultSeamTextConverter = (Converter) clazz.newInstance();
+				} catch (Exception e) {
+					throw new FacesException(e);
+				}
+			} 
+			converter = defaultSeamTextConverter;
 		}
-		
-		//TODO nick - check that converter is instance of SeamTextConverter if we use SeamText
 		return converter;
 	}
 	

Modified: trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java
===================================================================
--- trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java	2009-01-05 09:25:14 UTC (rev 12088)
+++ trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/DefaultSeamTextConverter.java	2009-01-05 10:01:39 UTC (rev 12089)
@@ -33,6 +33,7 @@
 import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
 import javax.faces.convert.ConverterException;
 
 import org.jboss.seam.text.SeamTextLexer;
@@ -46,38 +47,31 @@
  * @author Alexandr Levkovsky
  * 
  */
-public final class DefaultSeamTextConverter implements SeamTextConverter {
+public final class DefaultSeamTextConverter implements Converter {
 
 	/** The converter id for this converter. */
 	public static final String CONVERTER_ID = DefaultSeamTextConverter.class.getName();
 
-	//TODO nick - let everybody create instance of this class
-	private  DefaultSeamTextConverter() {
-	}
-	
-	//TODO nick - this class is not necessary
-	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) {
+
+		if (value == null) {
+			return null;
+		}
+		
 		try {
-			//TODO nick - value can be null here - see JavaDoc
 			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);
-		}
+			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,

Deleted: trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java
===================================================================
--- trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java	2009-01-05 09:25:14 UTC (rev 12088)
+++ trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverter.java	2009-01-05 10:01:39 UTC (rev 12089)
@@ -1,32 +0,0 @@
-/**
- * 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 javax.faces.convert.Converter;
-
-/**
- * @author Anton Belevich
- * Marker interface for the Seam Text Converter
- *  
- */
-public interface SeamTextConverter extends Converter {
-}

Deleted: trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java
===================================================================
--- trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java	2009-01-05 09:25:14 UTC (rev 12088)
+++ trunk/ui/editor/src/main/java/org/richfaces/convert/seamtext/SeamTextConverterFactory.java	2009-01-05 10:01:39 UTC (rev 12089)
@@ -1,58 +0,0 @@
-/**
- * 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 {
-			//TODO nick - use ThreadCCL
-			Class clazz = Class.forName("org.richfaces.convert.seamtext.DefaultSeamTextConverter");
-			Method method = clazz.getMethod("getInstance"); 
-			
-			//TODO nick - static method doesn't need any argument, better pass null
-			return (SeamTextConverter) method.invoke(clazz);
-		
-		} catch(Exception e) {
-			throw new FacesException(e);
-		}
-	}
-}




More information about the richfaces-svn-commits mailing list