1 package org.opensync.engine.server;
2
3 import java.io.*;
4
5 import org.opensync.engine.server.OpenSync;
6
7 /***
8 * This class encapsulate the concept of a business view in the OpenSync application
9 */
10
11 public class View implements Serializable {
12 /***
13 * The name of the view
14 *
15 */
16 protected String name;
17
18 /***
19 * The theme of the view
20 *
21 */
22 protected String theme;
23
24 /***
25 * The descriptor (in/out) used by the adapter transform the source fomat in OpenSync format.
26 *
27 */
28 protected String descriptor;
29 /***
30 * Set the descriptor (in only) used by the adapter transform the source fomat in OpenSync format.
31 *
32 */
33 protected String descriptorIn;
34 /***
35 * Set the descriptor (out only) used by the adapter transform the source fomat in OpenSync format.
36 *
37 */
38 protected String descriptorOut;
39 /***
40 * The file name of the file produice or import by OpenSync for this view
41 *
42 */
43 protected String file;
44
45 /***
46 * Construct a view object
47 *
48 */
49 public View() {
50 }
51
52 /***
53 * Set the name of the view
54 *
55 * @param name the name of the view
56 */
57 public void setName(String name) {
58 this.name = name;
59 }
60 /***
61 * Get the theme of the view
62 *
63 */
64 public String getTheme() {
65 return theme;
66 }
67
68 /***
69 * Set the theme of the view
70 *
71 * @param theme the theme of the view
72 */
73 public void setTheme(String theme) {
74 this.theme = theme;
75 }
76 /***
77 * Get the name of the view
78 *
79 */
80 public String getName() {
81 return name;
82 }
83
84 /***
85 * Set the descriptor (in/out) used by the adapter transform the source fomat in OpenSync format.
86 * It may be an xsl sheet or a txt file descriptor
87 *
88 * @param descriptor the in/out descriptor of the view
89 */
90 public void setDescriptor(String descriptor) {
91 this.descriptor = descriptor;
92 }
93 /***
94 * Get the descriptor (in/out) used by the adapter transform the source fomat in OpenSync format.
95 *
96 */
97 public String getDescriptor() {
98 return descriptor;
99 }
100 /***
101 * Set the file name of the file produice or import by OpenSync for this view
102 *
103 * @param file
104 */
105 public void setFile(String file) {
106 this.file = file;
107 }
108 /***
109 * Get the file name of the file produice or import by OpenSync for this view
110 *
111 */
112 public String getFile() {
113 return file;
114 }
115 /***
116 * Set the descriptor (in only) used by the adapter transform the source fomat in OpenSync format.
117 * It may be an xsl sheet or a txt file descriptor
118 *
119 * @param descriptorIn
120 */
121 public void setDescriptorIn(String descriptorIn) {
122 this.descriptorIn = descriptorIn;
123 }
124 /***
125 * Get the descriptor (in only) used by the adapter transform the source fomat in OpenSync format.
126 *
127 */
128 public String getDescriptorIn() {
129 return (descriptorIn == null || descriptorIn.length() == 0)
130 ? descriptor : descriptorIn;
131 }
132 /***
133 * Set the descriptor (out only) used by the adapter transform the source fomat in OpenSync format.
134 * It may be an xsl sheet or a txt file descriptor
135 *
136 * @param descriptorOut
137 */
138 public void setDescriptorOut(String descriptorOut) {
139 this.descriptorOut = descriptorOut;
140 }
141 /***
142 * get the descriptor (out only) used by the adapter transform the source fomat in OpenSync format.
143 *
144 */
145 public String getDescriptorOut() {
146 return (descriptorOut == null || descriptorOut.length() == 0)
147 ? descriptor : descriptorOut;
148 }
149
150
151 public long lastModifiedTo(String descriptorsPath) throws OpenSyncException, IOException {
152
153 long lastModified = -1;
154 String path = OpenSync.getInstance().getDirectoryPath(descriptorsPath, true);
155 File file = new File(path);
156 if (!(file.exists() && file.isDirectory())){
157 throw new OpenSyncException("error.directory.not-found",new Object[]{path});
158 }
159 lastModified = new File(path + "/" + this.getDescriptor()).lastModified();
160
161
162 return lastModified;
163 }
164
165 public long lastModifiedFrom(String descriptorsPath, String folder) throws OpenSyncException, IOException {
166
167 long lastModified = -1;
168 String path = OpenSync.getInstance().getDirectoryPath(descriptorsPath, true);
169 File file = new File(path);
170 if (!(file.exists() && file.isDirectory())){
171 throw new OpenSyncException("error.directory.not-found",new Object[]{path});
172 }
173 lastModified = new File(path + "/" + this.getDescriptor()).lastModified();
174
175 String fileSeparator = System.getProperty("file.separator");
176 path = folder;
177 file = new File(path);
178 if (!(file.exists() && file.isDirectory())){
179 String configFolder = System.getProperty("opensync.configfolder");
180 configFolder = (configFolder == null ? "" : configFolder);
181
182 path = OpenSync.getInstance().getDirectoryPath("etc"+fileSeparator+configFolder+fileSeparator+path, true);
183 file = new File(path);
184 if(!(file.exists() && file.isDirectory())){
185 throw new OpenSyncException("error.directory.not-found",new Object[]{path});
186 }
187 }
188 lastModified = Math.max(lastModified, new File(path + fileSeparator + this.getFile()).lastModified());
189
190 return lastModified;
191 }
192
193 /***
194 * Convert a view to a string. (Use for debug only)
195 *
196 */
197 public String toString(){
198 StringBuffer buffer = new StringBuffer();
199 buffer.append("View{\n");
200 buffer.append("\tname : ").append(name).append("\n");
201 buffer.append("\tdescriptor : ").append(descriptor).append("\n");
202 buffer.append("\tdescriptorIn : ").append(descriptorIn).append("\n");
203 buffer.append("\tdescriptorOut : ").append(descriptorOut).append("\n");
204 buffer.append("\tfile : ").append(file).append("\n");
205 return buffer.toString();
206 }
207 }