001: package com.quadcap.http.servlets.jsp;
002:
003: /* Copyright 1999 - 2003 Quadcap Software. All rights reserved.
004: *
005: * This software is distributed under the Quadcap Free Software License.
006: * This software may be used or modified for any purpose, personal or
007: * commercial. Open Source redistributions are permitted. Commercial
008: * redistribution of larger works derived from, or works which bundle
009: * this software requires a "Commercial Redistribution License"; see
010: * http://www.quadcap.com/purchase.
011: *
012: * Redistributions qualify as "Open Source" under one of the following terms:
013: *
014: * Redistributions are made at no charge beyond the reasonable cost of
015: * materials and delivery.
016: *
017: * Redistributions are accompanied by a copy of the Source Code or by an
018: * irrevocable offer to provide a copy of the Source Code for up to three
019: * years at the cost of materials and delivery. Such redistributions
020: * must allow further use, modification, and redistribution of the Source
021: * Code under substantially the same terms as this license.
022: *
023: * Redistributions of source code must retain the copyright notices as they
024: * appear in each source code file, these license terms, and the
025: * disclaimer/limitation of liability set forth as paragraph 6 below.
026: *
027: * Redistributions in binary form must reproduce this Copyright Notice,
028: * these license terms, and the disclaimer/limitation of liability set
029: * forth as paragraph 6 below, in the documentation and/or other materials
030: * provided with the distribution.
031: *
032: * The Software is provided on an "AS IS" basis. No warranty is
033: * provided that the Software is free of defects, or fit for a
034: * particular purpose.
035: *
036: * Limitation of Liability. Quadcap Software shall not be liable
037: * for any damages suffered by the Licensee or any third party resulting
038: * from use of the Software.
039: */
040:
041: import java.io.PrintWriter;
042:
043: import java.util.Hashtable;
044:
045: import org.xml.sax.AttributeList;
046:
047: import com.quadcap.util.Debug;
048:
049: /**
050: *
051: * Implementation of the <b><jsp:setProperty></b> tag.
052: *
053: * @author Stan Bailes
054: */
055: public class TagJspSetProperty extends TagJsp {
056: public TagJspSetProperty() {
057: }
058:
059: public TagJspSetProperty(TagContext context) {
060: super (context);
061: }
062:
063: public TagInstance makeInstance(TagContext context) {
064: return new TagJspSetProperty(context);
065: }
066:
067: public void doStartTag(String tagName, AttributeList attributes)
068: throws JspException {
069: super .doStartTag(tagName, attributes);
070: context.addPageDirective("import",
071: "com.quadcap.http.servlets.jsp.PropertyUtils");
072:
073: PrintWriter w = context.getPrintWriter();
074: String name = attributes.getValue("name");
075: String prop = attributes.getValue("property");
076: if (prop.equals("*")) {
077: w.print(" PropertyUtils.");
078: w.print("setPropertiesFromRequest(");
079: w.print(name);
080: w.println(", request);");
081: return;
082: }
083:
084: String param = attributes.getValue("param");
085: if (param != null) {
086: w.print(" PropertyUtils.");
087: w.print("setPropertyFromRequestParameter(");
088: w.print(name);
089: w.print(", request, \"");
090: w.print(param);
091: w.println("\");");
092: return;
093: }
094:
095: String value = attributes.getValue("value").trim();
096: if (value != null) {
097: if (value.startsWith("<%=") && value.endsWith("%>")) {
098: value = value.substring(3);
099: value = value.substring(value.length() - 2).trim();
100: } else {
101: value = "\"" + value + "\"";
102: }
103: w.print(" PropertyUtils.");
104: w.print("setPropertyFromValue(");
105: w.print(name);
106: w.print(", String.valueOf(");
107: w.print(value);
108: w.println("));");
109: return;
110: }
111:
112: throw new JspException("Bad jsp:setProperty tag");
113: }
114: }
|