001 /*
002 * Copyright 2006-2008 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.rice.kns.web.format;
017
018 import java.util.Collection;
019
020
021 /**
022 * This class is used to prevent reformatting of String values.
023 */
024 public class NoOpStringFormatter extends Formatter {
025 /**
026 * Does absolutely nothing to the given String. Yes, this is actually a valuable way to prevent the POJO stuff from converting a
027 * simple String into a 1-element String array.
028 */
029 protected Object convertToObject(String target) {
030 return target;
031 }
032
033 /**
034 * Does absolutely nothing to the given String. Yes, this is actually a valuable way to prevent the POJO stuff from converting a
035 * simple String into a 1-element String array.
036 */
037 public Object format(Object value) {
038 if (value != null) {
039 if (!(value instanceof String)) {
040 throw new FormatException("the given " + value.getClass().getName() + " value is not a String");
041 }
042 }
043
044 return value;
045 }
046
047 public Object convertFromPresentationFormat(Object value) {
048 return super.convertFromPresentationFormat(value);
049 }
050
051 public Object formatArray(Object value) {
052 return super.formatArray(value);
053 }
054
055 public Object formatCollection(Collection value) {
056 return super.formatCollection(value);
057 }
058
059 public Object formatForPresentation(Object value) {
060 return super.formatForPresentation(value);
061 }
062
063 public Object formatObject(Object value) {
064 return super.formatObject(value);
065 }
066 }