You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2006/01/25 08:23:01 UTC
svn commit: r372156 - in /myfaces/tomahawk/trunk/sandbox/core/src/main:
java/org/apache/myfaces/custom/script/ resources-facesconfig/META-INF/ tld/
tld/entities/
Author: matzew
Date: Tue Jan 24 23:22:51 2006
New Revision: 372156
URL: http://svn.apache.org/viewcvs?rev=372156&view=rev
Log:
added a script component
Added:
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/Script.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptRenderer.java
myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptTag.java
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/html_script_attributes.xml
Modified:
myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/Script.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/Script.java?rev=372156&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/Script.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/Script.java Tue Jan 24 23:22:51 2006
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.script;
+
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.util._ComponentUtils;
+
+/**
+ * @author Matthias Wessendorf (changed by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class Script extends UIOutput {
+
+ public static final String COMPONENT_TYPE = "org.apache.myfaces.Script";
+ public static final String COMPONENT_FAMILY = "javax.faces.Output";
+ private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.Script";
+
+ private String src = null;
+ private String type = HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT;
+
+ // ------------------------------------------------------------ Constructor
+ public Script() {
+ setRendererType(DEFAULT_RENDERER_TYPE);
+ }
+
+ /**
+ * @see <code>UIComponentBase</code>
+ */
+ public String getFamily() {
+
+ return COMPONENT_FAMILY;
+
+ }
+
+ // ------------------------------------------------------------ getter/setter
+ public String getSrc() {
+ if (src != null) return src;
+ ValueBinding vb = getValueBinding("src");
+ return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
+ }
+
+
+ public void setSrc(String src) {
+ this.src = src;
+ }
+
+
+ public String getType() {
+ if (type != null) return type;
+ ValueBinding vb = getValueBinding("type");
+ return vb != null ? _ComponentUtils.getStringValue(getFacesContext(), vb) : null;
+ }
+
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ // ------------------------------------------------------------ StateHolder
+ public void restoreState(FacesContext context, Object state) {
+
+ Object values[] = (Object[]) state;
+ super.restoreState(context, values[0]);
+ src = (String) values[1];
+ type = (String) values[2];
+
+ }
+
+ public Object saveState(FacesContext context) {
+
+ Object values[] = new Object[6];
+ values[0] = super.saveState(context);
+ values[1] = src;
+ values[2] = type;
+ return values;
+
+ }
+
+
+}
\ No newline at end of file
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptRenderer.java?rev=372156&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptRenderer.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptRenderer.java Tue Jan 24 23:22:51 2006
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.script;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.renderkit.html.HtmlRenderer;
+
+/**
+ * @author Matthias Wessendorf (changed by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ScriptRenderer extends HtmlRenderer {
+
+ public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
+ if ((context == null) || (component == null)) {
+ throw new NullPointerException();
+ }
+ Script script = (Script) component;
+ ResponseWriter writer = context.getResponseWriter();
+
+ writer.startElement(HTML.SCRIPT_ELEM, component);
+ writer.writeAttribute(HTML.SRC_ATTR, context.getExternalContext().getRequestContextPath()+script.getSrc(), null);
+ writer.writeAttribute(HTML.TYPE_ATTR, script.getType(), null);
+ writer.writeText("",null);
+ writer.endElement(HTML.SCRIPT_ELEM);
+ }
+}
\ No newline at end of file
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptTag.java?rev=372156&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptTag.java (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/java/org/apache/myfaces/custom/script/ScriptTag.java Tue Jan 24 23:22:51 2006
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.myfaces.custom.script;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.renderkit.html.HTML;
+import org.apache.myfaces.taglib.html.HtmlOutputTextTagBase;
+
+/**
+ * @author Matthias Wessendorf (changed by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class ScriptTag extends HtmlOutputTextTagBase {
+
+ private String src = null;
+ private String type = null;
+
+
+ // ------------------------------------------------------------ UIComponentTags
+ public String getComponentType() {
+ return Script.COMPONENT_TYPE;
+
+ }
+
+ public String getRendererType() {
+ return "org.apache.myfaces.Script";
+ }
+
+ public void release() {
+
+ super.release();
+ src = null;
+ type = null;
+
+ }
+
+ protected void setProperties(UIComponent component) {
+
+ super.setProperties(component);
+ setStringProperty(component, HTML.SRC_ATTR, src);
+ setStringProperty(component, HTML.TYPE_ATTR, type);
+ }
+
+
+ // ------------------------------------------------------------ setter
+ public void setSrc(String src) {
+ this.src = src;
+ }
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+}
\ No newline at end of file
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml?rev=372156&r1=372155&r2=372156&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/resources-facesconfig/META-INF/faces-config.xml Tue Jan 24 23:22:51 2006
@@ -57,7 +57,13 @@
<component>
<component-type>org.apache.myfaces.Schedule</component-type>
<component-class>org.apache.myfaces.custom.schedule.HtmlSchedule</component-class>
- </component>
+ </component>
+
+ <component>
+ <component-type>org.apache.myfaces.Script</component-type>
+ <component-class>org.apache.myfaces.custom.script.Script</component-class>
+ </component>
+
<component>
<component-type>org.apache.myfaces.AutoUpdateDataTable</component-type>
@@ -144,6 +150,12 @@
<renderer-type>org.apache.myfaces.InputSuggestAjax</renderer-type>
<renderer-class>org.apache.myfaces.custom.inputsuggestajax.InputSuggestAjaxRenderer</renderer-class>
</renderer>
+
+ <renderer>
+ <component-family>javax.faces.Output</component-family>
+ <renderer-type>org.apache.myfaces.Script</renderer-type>
+ <renderer-class>org.apache.myfaces.custom.script.ScriptRenderer</renderer-class>
+ </renderer>
<renderer>
<component-family>javax.faces.SelectMany</component-family>
Added: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/html_script_attributes.xml
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/html_script_attributes.xml?rev=372156&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/html_script_attributes.xml (added)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/entities/html_script_attributes.xml Tue Jan 24 23:22:51 2006
@@ -0,0 +1,17 @@
+ <attribute>
+ <name>src</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ URL for script file.
+ </description>
+ </attribute>
+ <attribute>
+ <name>type</name>
+ <required>false</required>
+ <rtexprvalue>false</rtexprvalue>
+ <description>
+ type of script source
+ </description>
+ </attribute>
+
\ No newline at end of file
Modified: myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld?rev=372156&r1=372155&r2=372156&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld (original)
+++ myfaces/tomahawk/trunk/sandbox/core/src/main/tld/myfaces_sandbox.tld Tue Jan 24 23:22:51 2006
@@ -117,6 +117,7 @@
<!ENTITY html_planner_attributes SYSTEM "entities/html_planner_attributes.xml">
<!ENTITY html_focus_attributes SYSTEM "entities/html_focus_attributes.xml">
<!ENTITY validator_compare_to_attributes SYSTEM "entities/validator_compare_to_attributes.xml">
+<!ENTITY html_script_attributes SYSTEM "entities/html_script_attributes.xml">
]>
<taglib>
@@ -171,6 +172,19 @@
&ui_command_attributes;
&ui_schedule_attributes;
&html_schedule_attributes;
+ </tag>
+
+ <!-- script -->
+ <tag>
+ <name>script</name>
+ <tag-class>org.apache.myfaces.custom.script.ScriptTag</tag-class>
+ <body-content>empty</body-content>
+ <display-name>Script component</display-name>
+ <description>
+ Adds (java)script to the browser
+ </description>
+ &ui_component_attributes;
+ &html_script_attributes;
</tag>
<!-- inputsuggestajax -->