Author: vbaranov
Date: 2008-04-07 10:46:55 -0400 (Mon, 07 Apr 2008)
New Revision: 7630
Added:
trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/
trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/InsertTagBase.java
Modified:
trunk/ui/insert/src/main/config/component/insert.xml
trunk/ui/insert/src/main/java/org/ajax4jsf/renderkit/AbstractInsertRenderer.java
trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java
Log:
http://jira.jboss.com/jira/browse/RF-2932
Modified: trunk/ui/insert/src/main/config/component/insert.xml
===================================================================
--- trunk/ui/insert/src/main/config/component/insert.xml 2008-04-07 14:01:00 UTC (rev
7629)
+++ trunk/ui/insert/src/main/config/component/insert.xml 2008-04-07 14:46:55 UTC (rev
7630)
@@ -20,10 +20,8 @@
<tag>
<name>insert</name>
<classname>org.richfaces.ui.taglib.InsertTag</classname>
- <superclass>
- org.ajax4jsf.webapp.taglib.HtmlComponentTagBase
- </superclass>
- <test/>
+ <superclass>org.richfaces.ui.taglib.InsertTagBase</superclass>
+ <test />
</tag>
<!--
<taghandler>
@@ -46,6 +44,13 @@
<description>Defines the path to the file with source code</description>
</property>
<property>
+ <name>content</name>
+ <classname>java.lang.String</classname>
+ <description><![CDATA[
+ Defines the String, inserted with this component. This attribute is alternative to
"src" attribute.
+ ]]></description>
+ </property>
+ <property>
<name>highlight</name>
<classname>java.lang.String</classname>
<description>Defines a type of code</description>
Modified:
trunk/ui/insert/src/main/java/org/ajax4jsf/renderkit/AbstractInsertRenderer.java
===================================================================
---
trunk/ui/insert/src/main/java/org/ajax4jsf/renderkit/AbstractInsertRenderer.java 2008-04-07
14:01:00 UTC (rev 7629)
+++
trunk/ui/insert/src/main/java/org/ajax4jsf/renderkit/AbstractInsertRenderer.java 2008-04-07
14:46:55 UTC (rev 7630)
@@ -3,11 +3,15 @@
*/
package org.ajax4jsf.renderkit;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.io.StringBufferInputStream;
+import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import javax.faces.FacesException;
@@ -30,39 +34,51 @@
HeaderResourcesRendererBase {
private static final Object ERROR_MESSAGE_CLASS = "dr-insert-error";
+
+
public void renderContent(FacesContext context, UIInsert component)
throws IOException {
- if (null != component.getSrc()) {
- ExternalContext externalContext = context.getExternalContext();
- InputStream inputStream = externalContext
- .getResourceAsStream(component.getSrc());
- if (null != inputStream) {
- renderStream(context, component, inputStream);
- } else {
- String errorContent = component.getErrorContent();
- if (null != errorContent
- && null != (inputStream = externalContext
- .getResourceAsStream(errorContent))) {
- // Render default content, if src not found.
- renderStream(context, component, inputStream);
- } else {
- // Render error message for a not found resource.
- renderErrorMessage(context, component, "UI_INSERT_RESOURCE_NOT_FOUND");
- }
- }
+ boolean isSrcAvailable = (component.getSrc() != null);
+ boolean isContentAvailable = (component.getContent() != null);
+ if (isSrcAvailable && isContentAvailable) {
+ throw new FacesException(UIInsert.ILLEGAL_ATTRIBUTE_VALUE_MESSAGE);
+ }
+
+ if (isSrcAvailable || isContentAvailable) {
+ ExternalContext externalContext = context.getExternalContext();
+ InputStream inputStream = null;
+
+ if (isSrcAvailable) {
+ inputStream = externalContext.getResourceAsStream(component.getSrc());
+ } else if (isContentAvailable) {
+ inputStream = new ByteArrayInputStream(component.getContent().getBytes());
+ }
+ if (null != inputStream) {
+ renderStream(context, component, inputStream);
} else {
- throw new FacesException(
- "Attribute 'scr' for a component <rich:insert > "
- + component.getClientId(context) + " must be set");
+ String errorContent = component.getErrorContent();
+ if ((null != errorContent)
+ && (null != (inputStream =
externalContext.getResourceAsStream(errorContent)))) {
+ // Render default content, if src not found.
+ renderStream(context, component, inputStream);
+ } else {
+ // Render error message for a not found resource.
+ renderErrorMessage(context, component, "UI_INSERT_RESOURCE_NOT_FOUND");
}
+ }
+ } else {
+ throw new FacesException("Attribute 'scr' for a component
<rich:insert> " + component.getClientId(context)
+ + " must be set");
+ }
}
/**
* @param context
* @param component
- * @param message TODO
+ * @param message
+ * TODO
* @throws IOException
*/
private void renderErrorMessage(FacesContext context, UIInsert component, String
message)
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 2008-04-07
14:01:00 UTC (rev 7629)
+++ trunk/ui/insert/src/main/java/org/richfaces/ui/component/UIInsert.java 2008-04-07
14:46:55 UTC (rev 7630)
@@ -4,12 +4,6 @@
package org.richfaces.ui.component;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-import javax.faces.FacesException;
import javax.faces.component.UIComponentBase;
/**
@@ -18,6 +12,13 @@
*/
public abstract class UIInsert extends UIComponentBase {
+ /**
+ * Message of the Exception thrown in case both "content" and
"src"
+ * attributes are set on the page
+ */
+ public static final String ILLEGAL_ATTRIBUTE_VALUE_MESSAGE = "Only one
attribute "
+ + "should be set for the <rich:insert> component: either
\"content\" or \"src\".";
+
private static final String COMPONENT_TYPE = "org.richfaces.ui.Insert";
private static final String COMPONENT_FAMILY = "org.richfaces.ui.Insert";
@@ -26,7 +27,11 @@
public abstract String getSrc();
public abstract void setSrc(String src);
+
+ public abstract String getContent();
+ public abstract void setContent(String content);
+
public abstract String getHighlight();
public abstract void setHighlight(String highlight);
Added: trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/InsertTagBase.java
===================================================================
--- trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/InsertTagBase.java
(rev 0)
+++ trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/InsertTagBase.java 2008-04-07
14:46:55 UTC (rev 7630)
@@ -0,0 +1,124 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * 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.ui.taglib;
+
+import javax.el.ELException;
+import javax.el.ValueExpression;
+import javax.faces.FacesException;
+import javax.faces.component.UIComponent;
+
+import org.ajax4jsf.webapp.taglib.HtmlComponentTagBase;
+import org.richfaces.ui.component.UIInsert;
+
+/**
+ * Abstract base tag class for the <rich:insert> tag.
+ *
+ * @author Vladislav Baranov
+ */
+public abstract class InsertTagBase extends HtmlComponentTagBase {
+
+ /**
+ * Defines the String, inserted with this component.
+ * This attribute is alternative to "src" attribute.
+ */
+ private ValueExpression _content;
+
+ /**
+ * Defines the path to the file with source code
+ */
+ private ValueExpression _src;
+
+ /**
+ * Setter for content
+ *
+ * @param content - new value
+ */
+ public void setContent(ValueExpression __content) {
+ if (this._src == null) {
+ this._content = __content;
+ } else {
+ throw new FacesException(UIInsert.ILLEGAL_ATTRIBUTE_VALUE_MESSAGE);
+ }
+ }
+
+ /**
+ * Defines the path to the file with source code.
+ * Setter for src.
+ *
+ * @param src - new value
+ */
+ public void setSrc(ValueExpression __src) {
+ if (this._content == null) {
+ this._src = __src;
+ } else {
+ throw new FacesException(UIInsert.ILLEGAL_ATTRIBUTE_VALUE_MESSAGE);
+ }
+ }
+
+ public void release() {
+ super.release();
+
+ this._content = null;
+ this._src = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.components.taglib.html.HtmlCommandButtonTagBase#setProperties(javax.faces.component.UIComponent)
+ */
+ protected void setProperties(UIComponent component) {
+ super.setProperties(component);
+ UIInsert insertComponent = (UIInsert) component;
+
+ if (this._content != null) {
+ if (this._content.isLiteralText()) {
+ try {
+ String __content = (String)
getFacesContext().getApplication().getExpressionFactory().coerceToType(
+ this._content.getExpressionString(), String.class);
+
+ insertComponent.setContent(__content);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ } else {
+ component.setValueExpression("content", this._content);
+ }
+ }
+
+ if (this._src != null) {
+ if (this._src.isLiteralText()) {
+ try {
+ String __src = (String)
getFacesContext().getApplication().getExpressionFactory().coerceToType(
+ this._src.getExpressionString(), String.class);
+
+ insertComponent.setSrc(__src);
+ } catch (ELException e) {
+ throw new FacesException(e);
+ }
+ } else {
+ component.setValueExpression("src", this._src);
+ }
+ }
+ }
+
+}
Property changes on:
trunk/ui/insert/src/main/java/org/richfaces/ui/taglib/InsertTagBase.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native