01: /* TextType
02: *
03: * $Id: TextField.java 3799 2005-09-01 18:13:23Z stack-sf $
04: *
05: * Created on Mar 26, 2004
06: *
07: * Copyright (C) 2004 Internet Archive.
08: *
09: * This file is part of the Heritrix web crawler (crawler.archive.org).
10: *
11: * Heritrix is free software; you can redistribute it and/or modify
12: * it under the terms of the GNU Lesser Public License as published by
13: * the Free Software Foundation; either version 2.1 of the License, or
14: * any later version.
15: *
16: * Heritrix is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU Lesser Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser Public License
22: * along with Heritrix; if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: */
25: package org.archive.crawler.settings;
26:
27: import java.io.Serializable;
28:
29: import org.archive.util.TextUtils;
30:
31: /** Class to hold values for text fields.
32: *
33: * Objects of this class could be used instead of {@link java.lang.String} to
34: * hold text strings with newlines in it. SimpleTypes with values wrapped in
35: * objects of this class will show up in the UI as multiline text areas.
36: *
37: * @author John Erik Halse
38: *
39: */
40: public class TextField implements CharSequence, Serializable {
41: private static final long serialVersionUID = -2853908867414076703L;
42: private String value;
43:
44: /** Constructs a new TextField object.
45: *
46: * @param value the string represented by this TextField.
47: */
48: public TextField(String value) {
49: this .value = TextUtils.replaceAll("\r\n", value, "\n").trim();
50: }
51:
52: /* (non-Javadoc)
53: * @see java.lang.CharSequence#length()
54: */
55: public int length() {
56: return value.length();
57: }
58:
59: /* (non-Javadoc)
60: * @see java.lang.CharSequence#charAt(int)
61: */
62: public char charAt(int index) {
63: return value.charAt(index);
64: }
65:
66: /* (non-Javadoc)
67: * @see java.lang.CharSequence#subSequence(int, int)
68: */
69: public CharSequence subSequence(int start, int end) {
70: return value.subSequence(start, end);
71: }
72:
73: public boolean equals(Object obj) {
74: return obj instanceof TextField && value.equals(obj);
75: }
76:
77: /* (non-Javadoc)
78: * @see java.lang.Object#hashCode()
79: */
80: public int hashCode() {
81: return value.hashCode();
82: }
83:
84: /* (non-Javadoc)
85: * @see java.lang.Object#toString()
86: */
87: public String toString() {
88: return value;
89: }
90: }
|