001: package org.apache.turbine.services.intake.model;
002:
003: /*
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: import org.apache.commons.lang.StringUtils;
023:
024: import org.apache.torque.om.StringKey;
025:
026: import org.apache.turbine.services.intake.IntakeException;
027: import org.apache.turbine.services.intake.validator.StringValidator;
028: import org.apache.turbine.services.intake.xmlmodel.XmlField;
029:
030: /**
031: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
032: * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
033: * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
034: * @version $Id: StringKeyField.java 534527 2007-05-02 16:10:59Z tv $
035: * @deprecated Use String instead
036: */
037: public class StringKeyField extends Field {
038:
039: /**
040: * Constructor.
041: *
042: * @param field xml field definition object
043: * @param group xml group definition object
044: * @throws IntakeException thrown by superclass
045: */
046: public StringKeyField(XmlField field, Group group)
047: throws IntakeException {
048: super (field, group);
049: }
050:
051: /**
052: * Produces the fully qualified class name of the default validator.
053: *
054: * @return class name of the default validator
055: */
056: protected String getDefaultValidator() {
057: return StringValidator.class.getName();
058: }
059:
060: /**
061: * Sets the default value for a String field
062: *
063: * @param prop Parameter for the default values
064: */
065: public void setDefaultValue(String prop) {
066: if (prop == null) {
067: return;
068: }
069:
070: defaultValue = new StringKey(prop);
071: }
072:
073: /**
074: * Set the empty Value. This value is used if Intake
075: * maps a field to a parameter returned by the user and
076: * the corresponding field is either empty (empty string)
077: * or non-existant.
078: *
079: * @param prop The value to use if the field is empty.
080: */
081: public void setEmptyValue(String prop) {
082: if (prop == null) {
083: return;
084: }
085:
086: emptyValue = new StringKey(prop);
087: }
088:
089: /**
090: * Sets the value of the field from data in the parser.
091: */
092: protected void doSetValue() {
093: if (isMultiValued) {
094: String[] ss = parser.getStrings(getKey());
095: StringKey[] ival = new StringKey[ss.length];
096: for (int i = 0; i < ss.length; i++) {
097: ival[i] = (StringUtils.isNotEmpty(ss[i])) ? new StringKey(
098: ss[i])
099: : (StringKey) getEmptyValue();
100: }
101: setTestValue(ival);
102: } else {
103: String val = parser.getString(getKey());
104: setTestValue((StringUtils.isNotEmpty(val)) ? new StringKey(
105: val) : (StringKey) getEmptyValue());
106: }
107: }
108: }
|