001: /*
002: * SessionBufferEntry.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: SessionBufferEntry.java,v 1.2 2003/03/20 15:21:00 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:
026: public final class SessionBufferEntry {
027: private static final String lineSeparator = System
028: .getProperty("line.separator");
029:
030: private Buffer buffer;
031: private String path;
032: private String modeName;
033: private int dotLineNumber;
034: private int dotOffset;
035: private long lastActivated;
036:
037: public SessionBufferEntry() {
038: }
039:
040: public SessionBufferEntry(Buffer buffer, int index) {
041: this .buffer = buffer;
042: if (buffer.getFile() != null)
043: path = buffer.getFile().netPath();
044: else
045: path = "";
046: if (buffer.getMode() != null)
047: modeName = buffer.getMode().toString();
048: else
049: modeName = "";
050: lastActivated = buffer.getLastActivated();
051: View view = buffer.getLastView();
052: if (view != null) {
053: dotLineNumber = view.lineNumber;
054: dotOffset = view.offs;
055: }
056: }
057:
058: public final String getPath() {
059: return path;
060: }
061:
062: public final void setPath(String path) {
063: this .path = path;
064: }
065:
066: public final Mode getMode() {
067: return Editor.getModeList().getModeFromModeName(modeName);
068: }
069:
070: public final void setMode(String modeName) {
071: this .modeName = modeName;
072: }
073:
074: public final int getModeId() {
075: return Editor.getModeList().getModeIdFromModeName(modeName);
076: }
077:
078: public final int getDotLineNumber() {
079: return dotLineNumber;
080: }
081:
082: public final void setDotLineNumber(int lineNumber) {
083: dotLineNumber = lineNumber;
084: }
085:
086: public final int getDotOffset() {
087: return dotOffset;
088: }
089:
090: public final void setDotOffset(int offset) {
091: dotOffset = offset;
092: }
093:
094: public final long getLastActivated() {
095: return lastActivated;
096: }
097:
098: public final void setLastActivated(long l) {
099: lastActivated = l;
100: }
101:
102: public String toXml() {
103: FastStringBuffer sb = new FastStringBuffer();
104: sb.append(" <buffer");
105: sb.append(" path=\"");
106: sb.append(path);
107: sb.append('"');
108: sb.append(" mode=\"");
109: sb.append(modeName);
110: sb.append('"');
111: sb.append(" dot=\"");
112: sb.append(String.valueOf(dotLineNumber));
113: sb.append(',');
114: sb.append(String.valueOf(dotOffset));
115: sb.append('"');
116: sb.append(" when=\"");
117: sb.append(String.valueOf(lastActivated));
118: sb.append('"');
119: PropertyList properties = buffer.getProperties();
120: if (properties.size() > 0) {
121: sb.append(">");
122: sb.append(lineSeparator);
123: Iterator it = properties.keyIterator();
124: if (it != null) {
125: while (it.hasNext()) {
126: Property property = (Property) it.next();
127: Object value = properties.getProperty(property);
128: sb.append(propertyToXml(property.getDisplayName(),
129: value.toString()));
130: }
131: }
132: sb.append(" </buffer>");
133: } else
134: sb.append("/>");
135: return sb.toString();
136: }
137:
138: private static String propertyToXml(String name, String value) {
139: FastStringBuffer sb = new FastStringBuffer(
140: " <property name=\"");
141: sb.append(name);
142: sb.append("\" value=\"");
143: sb.append(value);
144: sb.append("\"/>");
145: sb.append(lineSeparator);
146: return sb.toString();
147: }
148: }
|