001: /*
002: * FileHistoryEntry.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: FileHistoryEntry.java,v 1.1.1.1 2002/09/24 16:08:05 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.util.Iterator;
025: import java.util.StringTokenizer;
026:
027: public final class FileHistoryEntry {
028: private static final String lineSeparator = System
029: .getProperty("line.separator");
030:
031: private String name;
032: private String encoding;
033: private String mode;
034: private long when;
035: private PropertyList properties = new PropertyList();
036:
037: public FileHistoryEntry() {
038: }
039:
040: public String toXml() {
041: FastStringBuffer sb = new FastStringBuffer(" <file name=\"");
042: sb.append(name);
043: sb.append("\"");
044: if (encoding != null) {
045: sb.append(" encoding=\"");
046: sb.append(encoding);
047: sb.append("\"");
048: }
049: sb.append(" mode=\"");
050: sb.append(mode);
051: sb.append("\"");
052: sb.append(" when=\"");
053: sb.append(String.valueOf(when));
054: sb.append("\"");
055: sb.append(">");
056: sb.append(lineSeparator);
057: Iterator it = properties.keyIterator();
058: if (it != null) {
059: while (it.hasNext()) {
060: Property property = (Property) it.next();
061: Object value = properties.getProperty(property);
062: sb.append(propertyToXml(property.getDisplayName(),
063: value.toString()));
064: }
065: }
066: sb.append(" </file>");
067: return sb.toString();
068: }
069:
070: private static String propertyToXml(String name, String value) {
071: FastStringBuffer sb = new FastStringBuffer(
072: " <property name=\"");
073: sb.append(name);
074: sb.append("\" value=\"");
075: sb.append(value);
076: sb.append("\"/>");
077: sb.append(lineSeparator);
078: return new String(sb.toString());
079: }
080:
081: public final PropertyList getProperties() {
082: return properties;
083: }
084:
085: public void setProperties(PropertyList props) {
086: properties = props;
087: }
088:
089: public String getName() {
090: return name;
091: }
092:
093: public void setName(String name) {
094: this .name = name;
095: }
096:
097: public String getEncoding() {
098: return encoding;
099: }
100:
101: public void setEncoding(String encoding) {
102: this .encoding = encoding;
103: }
104:
105: public String getMode() {
106: return mode;
107: }
108:
109: public void setMode(String mode) {
110: this .mode = mode.intern();
111: }
112:
113: public void setWhen(long when) {
114: this .when = when;
115: }
116:
117: public void setProperty(Property property, Object value) {
118: properties.setProperty(property, value);
119: }
120:
121: public void setProperty(Property property, boolean value) {
122: properties.setProperty(property, value);
123: }
124:
125: public void setProperty(Property property, int value) {
126: properties.setProperty(property, value);
127: }
128:
129: public boolean setPropertyFromString(Property property, String value) {
130: return properties.setPropertyFromString(property, value);
131: }
132:
133: public String getStringProperty(Property property) {
134: return properties.getStringProperty(property);
135: }
136:
137: public boolean getBooleanProperty(Property property) {
138: return properties.getBooleanProperty(property);
139: }
140:
141: public int getIntegerProperty(Property property) {
142: return properties.getIntegerProperty(property);
143: }
144: }
|