/[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 2190 - (show annotations) (download)
Fri Jun 24 20:18:03 2011 UTC (12 years, 9 months ago) by iliev
File size: 5497 byte(s)
* Added support for send effects

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

  ViewVC Help
Powered by ViewVC