1 package org.apache.velocity.tools.view; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 /** 23 * <p>ToolInfo implementation to handle "primitive" data types. 24 * It currently supports String, Number, and Boolean data.</p> 25 * 26 * <p>An example of data elements specified in your toolbox.xml 27 * might be: 28 * <pre> 29 * <data type="string"> 30 * <key>app_name</key> 31 * <value>FooWeb Deluxe</value> 32 * </data> 33 * <data type="number"> 34 * <key>app_version</key> 35 * <value>4.2</value> 36 * </data> 37 * <data type="boolean"> 38 * <key>debug</key> 39 * <value>true</value> 40 * </data> 41 * <data type="number"> 42 * <key>screen_width</key> 43 * <value>400</value> 44 * </data> 45 * </pre></p> 46 * 47 * @author Nathan Bubna 48 * @deprecated Use {@link org.apache.velocity.tools.config.Data} 49 * @version $Id: DataInfo.java 651469 2008-04-25 00:46:13Z nbubna $ 50 */ 51 @Deprecated 52 public class DataInfo implements ToolInfo 53 { 54 55 public static final String TYPE_STRING = "string"; 56 public static final String TYPE_NUMBER = "number"; 57 public static final String TYPE_BOOLEAN = "boolean"; 58 59 private static final int TYPE_ID_STRING = 0; 60 private static final int TYPE_ID_NUMBER = 1; 61 private static final int TYPE_ID_BOOLEAN = 2; 62 63 private String key = null; 64 private int type_id = TYPE_ID_STRING; 65 private Object data = null; 66 67 68 public DataInfo() {} 69 70 71 /*********************** Mutators *************************/ 72 73 public void setKey(String key) 74 { 75 this.key = key; 76 } 77 78 79 public void setType(String type) 80 { 81 if (TYPE_BOOLEAN.equalsIgnoreCase(type)) 82 { 83 this.type_id = TYPE_ID_BOOLEAN; 84 } 85 else if (TYPE_NUMBER.equalsIgnoreCase(type)) 86 { 87 this.type_id = TYPE_ID_NUMBER; 88 } 89 else /* if no type or type="string" */ 90 { 91 this.type_id = TYPE_ID_STRING; 92 } 93 } 94 95 96 public void setValue(String value) 97 { 98 if (type_id == TYPE_ID_BOOLEAN) 99 { 100 this.data = Boolean.valueOf(value); 101 } 102 else if (type_id == TYPE_ID_NUMBER) 103 { 104 if (value.indexOf('.') >= 0) 105 { 106 this.data = new Double(value); 107 } 108 else 109 { 110 this.data = new Integer(value); 111 } 112 } 113 else /* type is "string" */ 114 { 115 this.data = value; 116 } 117 } 118 119 120 /*********************** Accessors *************************/ 121 122 public String getKey() 123 { 124 return key; 125 } 126 127 128 public String getClassname() 129 { 130 return data != null ? data.getClass().getName() : null; 131 } 132 133 134 /** 135 * Returns the data. Always returns the same 136 * object since the data is a constant. Initialization 137 * data is ignored. 138 */ 139 public Object getInstance(Object initData) 140 { 141 return data; 142 } 143 144 }