KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > SessionBufferEntry


1 /*
2  * SessionBufferEntry.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: SessionBufferEntry.java,v 1.2 2003/03/20 15:21:00 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.util.Iterator JavaDoc;
25
26 public final class SessionBufferEntry
27 {
28     private static final String JavaDoc lineSeparator =
29         System.getProperty("line.separator");
30
31     private Buffer buffer;
32     private String JavaDoc path;
33     private String JavaDoc modeName;
34     private int dotLineNumber;
35     private int dotOffset;
36     private long lastActivated;
37
38     public SessionBufferEntry()
39     {
40     }
41
42     public SessionBufferEntry(Buffer buffer, int index)
43     {
44         this.buffer = buffer;
45         if (buffer.getFile() != null)
46             path = buffer.getFile().netPath();
47         else
48             path = "";
49         if (buffer.getMode() != null)
50             modeName = buffer.getMode().toString();
51         else
52             modeName = "";
53         lastActivated = buffer.getLastActivated();
54         View view = buffer.getLastView();
55         if (view != null) {
56             dotLineNumber = view.lineNumber;
57             dotOffset = view.offs;
58         }
59     }
60
61     public final String JavaDoc getPath()
62     {
63         return path;
64     }
65
66     public final void setPath(String JavaDoc path)
67     {
68         this.path = path;
69     }
70
71     public final Mode getMode()
72     {
73         return Editor.getModeList().getModeFromModeName(modeName);
74     }
75
76     public final void setMode(String JavaDoc modeName)
77     {
78         this.modeName = modeName;
79     }
80
81     public final int getModeId()
82     {
83         return Editor.getModeList().getModeIdFromModeName(modeName);
84     }
85
86     public final int getDotLineNumber()
87     {
88         return dotLineNumber;
89     }
90
91     public final void setDotLineNumber(int lineNumber)
92     {
93         dotLineNumber = lineNumber;
94     }
95
96     public final int getDotOffset()
97     {
98         return dotOffset;
99     }
100
101     public final void setDotOffset(int offset)
102     {
103         dotOffset = offset;
104     }
105
106     public final long getLastActivated()
107     {
108         return lastActivated;
109     }
110
111     public final void setLastActivated(long l)
112     {
113         lastActivated = l;
114     }
115
116     public String JavaDoc toXml()
117     {
118         FastStringBuffer sb = new FastStringBuffer();
119         sb.append(" <buffer");
120         sb.append(" path=\"");
121         sb.append(path);
122         sb.append('"');
123         sb.append(" mode=\"");
124         sb.append(modeName);
125         sb.append('"');
126         sb.append(" dot=\"");
127         sb.append(String.valueOf(dotLineNumber));
128         sb.append(',');
129         sb.append(String.valueOf(dotOffset));
130         sb.append('"');
131         sb.append(" when=\"");
132         sb.append(String.valueOf(lastActivated));
133         sb.append('"');
134         PropertyList properties = buffer.getProperties();
135         if (properties.size() > 0) {
136             sb.append(">");
137             sb.append(lineSeparator);
138             Iterator JavaDoc it = properties.keyIterator();
139             if (it != null) {
140                 while (it.hasNext()) {
141                     Property property = (Property) it.next();
142                     Object JavaDoc value = properties.getProperty(property);
143                     sb.append(propertyToXml(property.getDisplayName(),
144                         value.toString()));
145                 }
146             }
147             sb.append(" </buffer>");
148         } else
149             sb.append("/>");
150         return sb.toString();
151     }
152
153     private static String JavaDoc propertyToXml(String JavaDoc name, String JavaDoc value)
154     {
155         FastStringBuffer sb = new FastStringBuffer(" <property name=\"");
156         sb.append(name);
157         sb.append("\" value=\"");
158         sb.append(value);
159         sb.append("\"/>");
160         sb.append(lineSeparator);
161         return sb.toString();
162     }
163 }
164
Popular Tags