[richfaces-svn-commits] JBoss Rich Faces SVN: r2261 - trunk/ui/insert/src/main/java/org/richfaces/ui/component.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Tue Aug 14 18:32:02 EDT 2007


Author: alexsmirnov
Date: 2007-08-14 18:32:01 -0400 (Tue, 14 Aug 2007)
New Revision: 2261

Added:
   trunk/ui/insert/src/main/java/org/richfaces/ui/component/Highlight.java
Modified:
   trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java
Log:
Remove mandatory dependency from jhighlight library. ( it's optional )

Added: trunk/ui/insert/src/main/java/org/richfaces/ui/component/Highlight.java
===================================================================
--- trunk/ui/insert/src/main/java/org/richfaces/ui/component/Highlight.java	                        (rev 0)
+++ trunk/ui/insert/src/main/java/org/richfaces/ui/component/Highlight.java	2007-08-14 22:32:01 UTC (rev 2261)
@@ -0,0 +1,62 @@
+/**
+ * 
+ */
+package org.richfaces.ui.component;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.faces.FacesException;
+
+import com.uwyn.jhighlight.renderer.Renderer;
+import com.uwyn.jhighlight.renderer.XhtmlRendererFactory;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class Highlight {
+	
+	
+	
+	private Renderer _renderer;
+
+	public Highlight(String type) {
+		_renderer = XhtmlRendererFactory.getRenderer(type);
+		if(null == _renderer){
+			throw new FacesException("Unknown type ["+type+"] to highlight source");
+		}
+	}
+
+	/**
+	 * @param name
+	 * @param in
+	 * @param out
+	 * @param encoding
+	 * @param fragment
+	 * @throws IOException
+	 * @see com.uwyn.jhighlight.renderer.Renderer#highlight(java.lang.String, java.io.InputStream, java.io.OutputStream, java.lang.String, boolean)
+	 */
+	public void highlight(String name, InputStream in, OutputStream out,
+			String encoding, boolean fragment) throws IOException {
+		_renderer.highlight(name, in, out, encoding, fragment);
+	}
+
+	/**
+	 * @param name
+	 * @param in
+	 * @param encoding
+	 * @param fragment
+	 * @return
+	 * @throws IOException
+	 * @see com.uwyn.jhighlight.renderer.Renderer#highlight(java.lang.String, java.lang.String, java.lang.String, boolean)
+	 */
+	public String highlight(String name, String in, String encoding,
+			boolean fragment) throws IOException {
+		return _renderer.highlight(name, in, encoding, fragment);
+	}
+	
+	
+
+}


Property changes on: trunk/ui/insert/src/main/java/org/richfaces/ui/component/Highlight.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Date Revision Author

Modified: trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java
===================================================================
--- trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java	2007-08-14 22:17:21 UTC (rev 2260)
+++ trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java	2007-08-14 22:32:01 UTC (rev 2261)
@@ -12,9 +12,6 @@
 import javax.faces.FacesException;
 import javax.faces.component.UIComponentBase;
 
-import com.uwyn.jhighlight.renderer.Renderer;
-import com.uwyn.jhighlight.renderer.XhtmlRendererFactory;
-
 /**
  * JSF component class
  * 
@@ -28,17 +25,19 @@
 	public String getContent() {
 		String content = null;
 		if (null != getSrc()) {
-			InputStream inputStream = getFacesContext().getExternalContext().getResourceAsStream(getSrc());
-			if(null != inputStream){
-				if(null == getHighlight()){
+			InputStream inputStream = getFacesContext().getExternalContext()
+					.getResourceAsStream(getSrc());
+			if (null != inputStream) {
+				if (null == getHighlight()) {
 					StringBuffer buff = new StringBuffer(1024);
 					InputStreamReader in = new InputStreamReader(inputStream);
 					char[] temp = new char[1024];
 					try {
 						int bytes;
-						while((bytes = in.read(temp))>0){
-							buff.append(temp,0,bytes);
-						};
+						while ((bytes = in.read(temp)) > 0) {
+							buff.append(temp, 0, bytes);
+						}
+						;
 					} catch (IOException e) {
 						throw new FacesException(e);
 					} finally {
@@ -50,28 +49,31 @@
 					}
 					content = buff.toString();
 				} else {
-					Renderer renderer = XhtmlRendererFactory.getRenderer(getHighlight());
-					if(null != renderer){
-						ByteArrayOutputStream out = new ByteArrayOutputStream();
+					ByteArrayOutputStream out = new ByteArrayOutputStream();
+					try {
+						Highlight highlighter = new Highlight(getHighlight());
+						highlighter.highlight(getSrc(), inputStream, out, null,
+								true);
+					} catch (IOException e) {
+						throw new FacesException(e);
+					} finally {
 						try {
-							renderer.highlight(getSrc(), inputStream, out, null, true);
+							inputStream.close();
 						} catch (IOException e) {
 							throw new FacesException(e);
-						} finally {
-							try {
-								inputStream.close();
-							} catch (IOException e) {
-								throw new FacesException(e);
-							}
 						}
-						content = out.toString();
 					}
+					content = out.toString();
 				}
 			} else {
-				throw new FacesException("Resource '"+getSrc()+"' for a component <rich:insert > "+getClientId(getFacesContext())+" not found");				
+				throw new FacesException("Resource '" + getSrc()
+						+ "' for a component <rich:insert > "
+						+ getClientId(getFacesContext()) + " not found");
 			}
 		} else {
-			throw new FacesException("Attribute 'scr' for a component <rich:insert > "+getClientId(getFacesContext())+" must be set");
+			throw new FacesException(
+					"Attribute 'scr' for a component <rich:insert > "
+							+ getClientId(getFacesContext()) + " must be set");
 		}
 
 		return content;




More information about the richfaces-svn-commits mailing list