/* * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at . * * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT * WARRANTY OF ANY KIND, either express or implied. See the License for the specific * language governing rights and limitations under the License. * * The Original Code is the Venice Web Communities System. * * The Initial Developer of the Original Code is Eric J. Bowersox , * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. * * Contributor(s): */ package com.silverwrist.venice.servlets.format; import java.io.Writer; import java.io.IOException; import com.silverwrist.util.StringUtil; import com.silverwrist.venice.ValidationException; public abstract class CDBaseFormFieldReverse implements CDFormField, ColorSelectors { private String name; private String caption; private String caption2; private boolean required; private String value = null; private boolean enabled; protected CDBaseFormFieldReverse(String name, String caption, String caption2, boolean required) { this.name = name; this.caption = caption; this.caption2 = caption2; this.required = required; this.enabled = true; } // end constructor protected CDBaseFormFieldReverse(CDBaseFormFieldReverse other) { this.name = other.name; this.caption = other.caption; this.caption2 = other.caption2; this.required = other.required; this.enabled = true; // N.B.: do NOT copy value! } // end constructor protected abstract void renderActualField(Writer out, RenderData rdat) throws IOException; protected void validateContents(String value) throws ValidationException { // this is a do-nothing value } // end validateContents protected final String getCaption() { return caption; } // end getCaption public void renderHere(Writer out, RenderData rdat) throws IOException { out.write("\n"); renderActualField(out,rdat); out.write("\n" + StringUtil.encodeHTML(caption)); if (caption2!=null) out.write(" " + StringUtil.encodeHTML(caption2)); out.write(""); if (required) out.write(rdat.getRequiredBullet()); out.write("\n\n"); } // end renderHere public String getName() { return name; } // end getName public String getValue() { return value; } // end getValue public void setValue(String value) { this.value = value; } // end setValue public boolean isRequired() { return required; } // end isRequired public CDCommandButton findButton(String name) { return null; } // end findButton public void validate() throws ValidationException { if (required && enabled && StringUtil.isStringEmpty(value)) throw new ValidationException("The '" + caption + "' field is required."); validateContents(value); } // end validate public boolean isEnabled() { return enabled; } // end isEnabled public void setEnabled(boolean flag) { enabled = flag; } // end setEnabled } // end CDBaseFormFieldReverse