/[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 1346 - (show annotations) (download)
Thu Sep 13 22:02:03 2007 UTC (16 years, 7 months ago) by iliev
File size: 5378 byte(s)
* added support for escape sequences to all
  instruments db related methods

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

  ViewVC Help
Powered by ViewVC