/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/DbDirectoryInfo.java
ViewVC logotype

Contents of /jlscp/trunk/src/org/linuxsampler/lscp/DbDirectoryInfo.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1202 - (show annotations) (download)
Thu May 24 20:17:25 2007 UTC (16 years, 11 months ago) by iliev
File size: 5245 byte(s)
* updated to version 0.5a

1 /*
2 * jlscp - a java LinuxSampler control protocol API
3 *
4 * Copyright (C) 2005-2007 Grigor Iliev <grigor@grigoriliev.com>
5 *
6 * This file is part of jlscp.
7 *
8 * jlscp is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * jlscp 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 jlscp; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23 package org.linuxsampler.lscp;
24
25 import java.text.DateFormat;
26 import java.text.ParseException;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29
30
31 /**
32 * Provides information about a database instrument directory.
33 * @author Grigor Iliev
34 */
35 public class DbDirectoryInfo {
36 private String name = "";
37 private String description = "";
38 private final Date dateCreated = new EnhancedDate();
39 private final Date dateModified = new EnhancedDate();
40 private String parentDirectoryPath = null;
41 private boolean showAbsolutePath = false;
42
43 private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
44 private static DateFormat dateFormat2 = DateFormat.getInstance();
45
46 /**
47 * Creates a new instance of <code>DbDirectoryInfo</code>.
48 * @param resultSet An array with information categories about a DB directory.
49 */
50 public
51 DbDirectoryInfo(String[] resultSet) throws LscpException {
52 for(String s : resultSet)
53 if(!parse(s)) Client.getLogger().info(LscpI18n.getLogMsg("unknownLine", s));
54 }
55
56 /**
57 * Gets the name of this directory.
58 * @return The name of this directory.
59 */
60 public String
61 getName() { return name; }
62
63 /**
64 * Sets the name of this directory.
65 * @param name The name of this directory.
66 */
67 public void
68 setName(String name) { this.name = name; }
69
70 /**
71 * Gets a brief description about this directory.
72 * @return A brief description about this directory.
73 */
74 public String
75 getDescription() { return description; }
76
77 /**
78 * Returns the date when the directory is created.
79 **/
80 public Date
81 getDateCreated() { return dateCreated; }
82
83 /**
84 * Returns the date when the directory is last modified.
85 **/
86 public Date
87 getDateModified() { return dateModified; }
88
89 /**
90 * Returns the absolute path name of the directory or
91 * <code>null</code> if the parent directory path is not set.
92 **/
93 public String
94 getDirectoryPath() {
95 if(getParentDirectoryPath() == null && getName().equals("/")) return "/";
96 if(getParentDirectoryPath() == null) return null;
97 if(getParentDirectoryPath().length() == 1) {
98 if(!getParentDirectoryPath().equals("/")) return null;
99 return getParentDirectoryPath() + getName();
100 }
101
102 return getParentDirectoryPath() + "/" + getName();
103 }
104
105 /**
106 * Returns the absolute path name of the directory containing this directory.
107 **/
108 public String
109 getParentDirectoryPath() { return parentDirectoryPath; }
110
111 /**
112 * Sets the absolute path name of the directory containing this directory.
113 **/
114 public void
115 setParentDirectoryPath(String dir) { parentDirectoryPath = dir; }
116
117 /**
118 * Parses a line of text.
119 * @param s The string to be parsed.
120 * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
121 * @throws LscpException If some error occurs.
122 */
123 public boolean
124 parse(String s) throws LscpException {
125 if(s.startsWith("DESCRIPTION: ")) {
126 description = s.substring("DESCRIPTION: ".length());
127 } else if(s.startsWith("CREATED: ")) {
128 s = s.substring("CREATED: ".length());
129 try { dateCreated.setTime(dateFormat.parse(s).getTime()); }
130 catch(ParseException e) { throw new LscpException(e.getMessage()); }
131 } else if(s.startsWith("MODIFIED: ")) {
132 s = s.substring("MODIFIED: ".length());
133 try { dateModified.setTime(dateFormat.parse(s).getTime()); }
134 catch(ParseException e) { throw new LscpException(e.getMessage()); }
135 } else return false;
136
137 return true;
138 }
139
140 /**
141 * Determines whether the <code>toString()</code>
142 * method should return the directory name or
143 * the absolute path name of the directory.
144 * The default value is <code>false</code>.
145 */
146 public boolean
147 getShowAbsolutePath() { return showAbsolutePath; }
148
149 /**
150 * Sets whether the <code>toString()</code> method
151 * should return the absolute path name of the directory.
152 * @param b If <code>true</code> the <code>toString()</code>
153 * method will return the absolute path name of the directory
154 * instead of the directory name.
155 */
156 public void
157 setShowAbsolutePath(boolean b) { showAbsolutePath = b; }
158
159 /**
160 * Returns the name or the absolute path name of
161 * the directory as specified by {@link #getShowAbsolutePath}.
162 * @see #setShowAbsolutePath
163 */
164 public String
165 toString() {
166 if(getShowAbsolutePath()) return getDirectoryPath();
167 return getName();
168 }
169
170 private class EnhancedDate extends Date {
171 public String
172 toString() { return dateFormat2.format(this); }
173 }
174 }

  ViewVC Help
Powered by ViewVC