📄 datainfo.java
字号:
package org.apache.velocity.tools.view;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* <p>ToolInfo implementation to handle "primitive" data types.
* It currently supports String, Number, and Boolean data.</p>
*
* <p>An example of data elements specified in your toolbox.xml
* might be:
* <pre>
* <data type="string">
* <key>app_name</key>
* <value>FooWeb Deluxe</value>
* </data>
* <data type="number">
* <key>app_version</key>
* <value>4.2</value>
* </data>
* <data type="boolean">
* <key>debug</key>
* <value>true</value>
* </data>
* <data type="number">
* <key>screen_width</key>
* <value>400</value>
* </data>
* </pre></p>
*
* @author Nathan Bubna
*
* @version $Id: DataInfo.java 479724 2006-11-27 18:49:37Z nbubna $
*/
public class DataInfo implements ToolInfo
{
public static final String TYPE_STRING = "string";
public static final String TYPE_NUMBER = "number";
public static final String TYPE_BOOLEAN = "boolean";
private static final int TYPE_ID_STRING = 0;
private static final int TYPE_ID_NUMBER = 1;
private static final int TYPE_ID_BOOLEAN = 2;
private String key = null;
private int type_id = TYPE_ID_STRING;
private Object data = null;
public DataInfo() {}
/*********************** Mutators *************************/
public void setKey(String key)
{
this.key = key;
}
public void setType(String type)
{
if (TYPE_BOOLEAN.equalsIgnoreCase(type))
{
this.type_id = TYPE_ID_BOOLEAN;
}
else if (TYPE_NUMBER.equalsIgnoreCase(type))
{
this.type_id = TYPE_ID_NUMBER;
}
else /* if no type or type="string" */
{
this.type_id = TYPE_ID_STRING;
}
}
public void setValue(String value)
{
if (type_id == TYPE_ID_BOOLEAN)
{
this.data = Boolean.valueOf(value);
}
else if (type_id == TYPE_ID_NUMBER)
{
if (value.indexOf('.') >= 0)
{
this.data = new Double(value);
}
else
{
this.data = new Integer(value);
}
}
else /* type is "string" */
{
this.data = value;
}
}
/*********************** Accessors *************************/
public String getKey()
{
return key;
}
public String getClassname()
{
return data != null ? data.getClass().getName() : null;
}
/**
* Returns the data. Always returns the same
* object since the data is a constant. Initialization
* data is ignored.
*/
public Object getInstance(Object initData)
{
return data;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -