1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Purpose: A Class that stores xml schema information
|
4
|
* Copyright: 2008 Regents of the University of California and the
|
5
|
* National Center for Ecological Analysis and Synthesis
|
6
|
* Authors: Michael Daigle
|
7
|
*
|
8
|
* '$Author: leinfelder $'
|
9
|
* '$Date: 2008-09-26 15:43:57 -0700 (Fri, 26 Sep 2008) $'
|
10
|
* '$Revision: 4399 $'
|
11
|
*
|
12
|
* This program is free software; you can redistribute it and/or modify
|
13
|
* it under the terms of the GNU General Public License as published by
|
14
|
* the Free Software Foundation; either version 2 of the License, or
|
15
|
* (at your option) any later version.
|
16
|
*
|
17
|
* This program is distributed in the hope that it will be useful,
|
18
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
20
|
* GNU General Public License for more details.
|
21
|
*
|
22
|
* You should have received a copy of the GNU General Public License
|
23
|
* along with this program; if not, write to the Free Software
|
24
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25
|
*/
|
26
|
|
27
|
package edu.ucsb.nceas.metacat.service;
|
28
|
|
29
|
import org.apache.log4j.Logger;
|
30
|
|
31
|
import edu.ucsb.nceas.metacat.util.SystemUtil;
|
32
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
33
|
|
34
|
public class XMLSchema {
|
35
|
|
36
|
private String fileNamespace = null;
|
37
|
private String externalFileUri = null;
|
38
|
private String fileName = null;
|
39
|
private String localFileUri = null;
|
40
|
private String localFileDir = null;
|
41
|
|
42
|
private Logger logMetacat = Logger.getLogger(XMLSchema.class);
|
43
|
|
44
|
/**
|
45
|
* Constructor - the schema file name will be extracted from the external
|
46
|
* file uri. The local file uri and local file dir will be constructed using
|
47
|
* system values and the file name.
|
48
|
*
|
49
|
* @param fileNamespace
|
50
|
* the file's name space
|
51
|
* @param externalFileUri
|
52
|
* the external uri where the schema is located
|
53
|
*/
|
54
|
public XMLSchema(String fileNamespace, String externalFileUri) {
|
55
|
setFileNamespace(fileNamespace);
|
56
|
setExternalFileUri(externalFileUri);
|
57
|
}
|
58
|
|
59
|
/**
|
60
|
* Constructor - sets the schema file namespace only. The file name will
|
61
|
* need to be added separately.
|
62
|
*
|
63
|
* @param namespace
|
64
|
* the file's name space
|
65
|
*/
|
66
|
public XMLSchema(String fileNamespace) {
|
67
|
setFileNamespace(fileNamespace);
|
68
|
}
|
69
|
|
70
|
/**
|
71
|
* Set the file name. The local file uri and local file dir will also get
|
72
|
* set using system context url and dir values and the schema directory
|
73
|
* value.
|
74
|
*
|
75
|
* @param fileName
|
76
|
* the file name to set
|
77
|
*/
|
78
|
public void setFileName(String fileName) {
|
79
|
if (fileName.startsWith(XMLSchemaService.SCHEMA_DIR)) {
|
80
|
fileName = fileName.substring(XMLSchemaService.SCHEMA_DIR.length());
|
81
|
}
|
82
|
this.fileName = fileName;
|
83
|
try {
|
84
|
this.localFileUri = SystemUtil.getContextURL() + XMLSchemaService.SCHEMA_DIR
|
85
|
+ fileName;
|
86
|
} catch (PropertyNotFoundException pnfe) {
|
87
|
localFileUri = XMLSchemaService.SCHEMA_DIR + fileName;
|
88
|
logMetacat.warn("Could not get context url. Setting localFileUri to: "
|
89
|
+ localFileUri);
|
90
|
}
|
91
|
try {
|
92
|
this.localFileDir = SystemUtil.getContextDir() + XMLSchemaService.SCHEMA_DIR
|
93
|
+ fileName;
|
94
|
} catch (PropertyNotFoundException pnfe) {
|
95
|
localFileDir = XMLSchemaService.SCHEMA_DIR + fileName;
|
96
|
logMetacat.warn("Could not get context directory. Setting localFileDir to: "
|
97
|
+ localFileDir);
|
98
|
}
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* Gets the file name
|
103
|
*
|
104
|
* @return string holding the file name
|
105
|
*/
|
106
|
public String getFileName() {
|
107
|
return fileName;
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Sets the file namespace
|
112
|
*
|
113
|
* @param fileNamespace
|
114
|
* the namespace to set
|
115
|
*/
|
116
|
public void setFileNamespace(String fileNamespace) {
|
117
|
this.fileNamespace = fileNamespace;
|
118
|
}
|
119
|
|
120
|
/**
|
121
|
* Gets the file namespace
|
122
|
*
|
123
|
* @return a string holding the file namespace
|
124
|
*/
|
125
|
public String getFileNamespace() {
|
126
|
return fileNamespace;
|
127
|
}
|
128
|
|
129
|
/**
|
130
|
* Sets the external file uri. Extracts the file name from the uri and sets
|
131
|
* the file name as well.
|
132
|
*
|
133
|
* @param externalFileUri
|
134
|
* the external file uri to set
|
135
|
*/
|
136
|
public void setExternalFileUri(String externalFileUri) {
|
137
|
this.externalFileUri = externalFileUri;
|
138
|
String fileName = XMLSchemaService.getSchemaFileNameFromUri(externalFileUri);
|
139
|
setFileName(fileName);
|
140
|
}
|
141
|
|
142
|
/**
|
143
|
* Gets the external file uri
|
144
|
* @return a string holding the external file uri
|
145
|
*/
|
146
|
public String getExternalFileUri() {
|
147
|
return externalFileUri;
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* Sets the local file uri. If the uri doesn't start with http:// the full
|
152
|
* uri is constructed using the system context url and the schema directory.
|
153
|
*
|
154
|
* @param localFileUri
|
155
|
* the base uri to set.
|
156
|
*/
|
157
|
public void setLocalFileUri(String localFileUri) {
|
158
|
if (!localFileUri.startsWith("http://")) {
|
159
|
try {
|
160
|
localFileUri = SystemUtil.getContextURL() + XMLSchemaService.SCHEMA_DIR + localFileUri;
|
161
|
} catch (PropertyNotFoundException pnfe) {
|
162
|
logMetacat.warn("Could not find context url: " + pnfe.getMessage() +
|
163
|
". Setting schema file uri to: " + XMLSchemaService.SCHEMA_DIR + localFileUri);
|
164
|
localFileUri = XMLSchemaService.SCHEMA_DIR + localFileUri;
|
165
|
}
|
166
|
}
|
167
|
this.localFileUri = localFileUri;
|
168
|
}
|
169
|
|
170
|
/**
|
171
|
* Gets the local file uri
|
172
|
*
|
173
|
* @return a string holding the local file uri
|
174
|
*/
|
175
|
public String getLocalFileUri() {
|
176
|
return localFileUri;
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* Gets the local file directory path
|
181
|
*
|
182
|
* @return a string holding the local file directory path
|
183
|
*/
|
184
|
public String getLocalFileDir() {
|
185
|
return localFileDir;
|
186
|
}
|
187
|
}
|