📄 xmlconfigreader.java
字号:
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("Info dir:").append(info).toString());
}
try { // Decode the URL of the FT. This is to catch colons
// used in filenames
FeatureTypeInfoDTO dto = loadFeature(info);
String ftName = null;
ftName = URLDecoder.decode(dto.getKey(), "UTF-8");
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.config("Decoding file name: " + ftName);
}
map.put(ftName, dto);
} catch (UnsupportedEncodingException e) {
// throw new ConfigurationException(e);
LOGGER.severe("unable to load featuretype from file " + info
+ ". Skipping that featuretype. Error was: " + e);
continue;
} catch (ConfigurationException ce) {
LOGGER.severe("unable to load featuretype from file " + info
+ ". Skipping that featuretype. Error was: " + ce);
continue;
}
}
}
return map;
}
/**
* Load FeatureTypeInfoDTO from a directory.
*
* <p>
* Expected directory structure:
* </p>
*
* <ul>
* <li> info.xml - required </li>
* <li> schema.xml - optional </li>
* </ul>
*
* <p>
* If a schema.xml file is not used, the information may be generated from a
* FeatureType using DataTransferObjectFactory.
* </p>
*
* @param infoFile
* a File to convert into a FeatureTypeInfo object. (info.xml)
*
* @return A complete FeatureTypeInfo object loaded from the File handle
* provided.
*
* @throws ConfigurationException
* When an error occurs.
* @throws IllegalArgumentException
* DOCUMENT ME!
*
* @see loadFeaturePt2(Element)
*/
protected FeatureTypeInfoDTO loadFeature(File infoFile) throws ConfigurationException {
if (!infoFile.exists()) {
throw new IllegalArgumentException("Info File not found:" + infoFile);
}
if (!infoFile.isFile()) {
throw new IllegalArgumentException("Info file is the wrong type:" + infoFile);
}
if (!isInfoFile(infoFile)) {
throw new IllegalArgumentException("Info File not valid:" + infoFile);
}
Element featureElem = null;
try {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.config(new StringBuffer("Loading configuration file: ").append(infoFile)
.toString());
}
Reader reader = XmlCharsetDetector.getCharsetAwareReader(new FileInputStream(infoFile));
featureElem = ReaderUtils.parse(reader);
reader.close();
} catch (FileNotFoundException fileNotFound) {
throw new ConfigurationException("Could not read info file:" + infoFile, fileNotFound);
} catch (Exception erk) {
throw new ConfigurationException("Could not parse info file:" + infoFile, erk);
}
FeatureTypeInfoDTO dto = loadFeaturePt2(featureElem);
File parentDir = infoFile.getParentFile();
dto.setDirName(parentDir.getName());
List attributeList;
File schemaFile = new File(parentDir, "schema.xml");
if (schemaFile.exists() && schemaFile.isFile()) {
// attempt to load optional schema information
//
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest(new StringBuffer("process schema file ").append(infoFile).toString());
}
try {
loadSchema(schemaFile, dto);
} catch (Exception badDog) {
badDog.printStackTrace();
attributeList = Collections.EMPTY_LIST;
}
} else {
dto.setSchemaAttributes(Collections.EMPTY_LIST);
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.config(new StringBuffer("added featureType ").append(dto.getName()).toString());
}
return dto;
}
/**
* loadFeaturePt2 purpose.
*
* <p>
* Converts a DOM tree into a FeatureTypeInfo object.
* </p>
*
* @param fTypeRoot
* a DOM tree to convert into a FeatureTypeInfo object.
*
* @return A complete FeatureTypeInfo object loaded from the DOM tree
* provided.
*
* @throws ConfigurationException
* When an error occurs.
*/
protected FeatureTypeInfoDTO loadFeaturePt2(Element fTypeRoot) throws ConfigurationException {
FeatureTypeInfoDTO ft = new FeatureTypeInfoDTO();
try {
ft.setName(ReaderUtils.getChildText(fTypeRoot, "name", true));
ft.setTitle(ReaderUtils.getChildText(fTypeRoot, "title", true));
ft.setAbstract(ReaderUtils.getChildText(fTypeRoot, "abstract"));
ft.setWmsPath(ReaderUtils.getChildText(fTypeRoot, "wmspath" /*
* ,
* true
*/));
String keywords = ReaderUtils.getChildText(fTypeRoot, "keywords");
if (keywords != null) {
List l = new LinkedList();
String[] ss = keywords.split(",");
for (int i = 0; i < ss.length; i++)
l.add(ss[i].trim());
ft.setKeywords(l);
}
Element urls = ReaderUtils.getChildElement(fTypeRoot, "metadataLinks");
if (urls != null) {
Element[] childs = ReaderUtils.getChildElements(urls, "metadataLink");
List l = new LinkedList();
for (int i = 0; i < childs.length; i++) {
l.add(getMetaDataLink(childs[i]));
}
ft.setMetadataLinks(l);
}
ft.setDataStoreId(ReaderUtils.getAttribute(fTypeRoot, "datastore", true));
ft.setSRS(Integer.parseInt(ReaderUtils.getChildText(fTypeRoot, "SRS", true)));
try {
String srsHandling = ReaderUtils.getChildText(fTypeRoot, "SRSHandling", false);
ft.setSRSHandling(srsHandling != null ? Integer.parseInt(srsHandling)
: FeatureTypeInfo.FORCE);
} catch (Exception e) {
ft.setSRSHandling(FeatureTypeInfo.FORCE);
}
Element tmp = ReaderUtils.getChildElement(fTypeRoot, "styles");
if (tmp != null) {
ft.setDefaultStyle(ReaderUtils.getAttribute(tmp, "default", false));
final NodeList childrens = tmp.getChildNodes();
final int numChildNodes = childrens.getLength();
Node child;
for (int n = 0; n < numChildNodes; n++) {
child = childrens.item(n);
if (child.getNodeType() == Node.ELEMENT_NODE) {
if (child.getNodeName().equals("style")) {
ft.addStyle(ReaderUtils.getElementText((Element) child));
}
}
}
}
Element cacheInfo = ReaderUtils.getChildElement(fTypeRoot, "cacheinfo");
if (cacheInfo != null) {
ft.setCacheMaxAge(ReaderUtils.getAttribute(cacheInfo, "maxage", false)); // not
// mandatory
ft.setCachingEnabled((new Boolean(ReaderUtils.getAttribute(cacheInfo, "enabled",
true))).booleanValue());
}
// Modif C. Kolbowicz - 06/10/2004
Element legendURL = ReaderUtils.getChildElement(fTypeRoot, "LegendURL");
if (legendURL != null) {
LegendURLDTO legend = new LegendURLDTO();
legend.setWidth(Integer
.parseInt(ReaderUtils.getAttribute(legendURL, "width", true)));
legend.setHeight(Integer.parseInt(ReaderUtils.getAttribute(legendURL, "height",
true)));
legend.setFormat(ReaderUtils.getChildText(legendURL, "Format", true));
legend.setOnlineResource(ReaderUtils.getAttribute(ReaderUtils.getChildElement(
legendURL, "OnlineResource", true), "xlink:href", true));
ft.setLegendURL(legend);
}
Envelope latLonBBox = loadBBox(ReaderUtils.getChildElement(fTypeRoot,
"latLonBoundingBox"));
// -- Modif C. Kolbowicz - 06/10/2004
ft.setLatLongBBox(latLonBBox);
Envelope nativeBBox = loadBBox(ReaderUtils.getChildElement(fTypeRoot, "nativeBBox"));
ft.setNativeBBox(nativeBBox);
Element numDecimalsElem = ReaderUtils.getChildElement(fTypeRoot, "numDecimals", false);
if (numDecimalsElem != null) {
ft.setNumDecimals(ReaderUtils.getIntAttribute(numDecimalsElem, "value", false, 8));
}
ft.setDefinitionQuery(loadDefinitionQuery(fTypeRoot));
} catch (Exception e) {
throw new ConfigurationException(e);
}
return ft;
}
/**
* This method loads all the coverages present under the geoserver data
* directory in a Map by using their respective DTOs.
*
* @see XMLConfigReader#loadCoverage(File)
* @param coverageRoot
* @return
* @throws ConfigurationException
*/
protected Map loadCoverages(File coverageRoot) throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINEST) && (coverageRoot != null)) {
LOGGER.finest(new StringBuffer("examining: ").append(coverageRoot.getAbsolutePath())
.toString());
LOGGER.finest(new StringBuffer("is dir: ").append(coverageRoot.isDirectory())
.toString());
}
if (coverageRoot == null) { // no coverages have been specified by the
// user (that is ok)
return Collections.EMPTY_MAP;
}
if (!coverageRoot.isDirectory()) {
throw new IllegalArgumentException("coverageRoot must be a directoy");
}
File[] directories = coverageRoot.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.isDirectory();
}
});
Map map = new HashMap();
File info;
CoverageInfoDTO dto;
final int numDirectories = directories.length;
for (int i = 0, n = numDirectories; i < n; i++) {
info = new File(directories[i], "info.xml");
if (info.exists() && info.isFile()) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("Info dir:").append(info).toString());
}
try {
dto = loadCoverage(info);
map.put(dto.getKey(), dto);
} catch (ConfigurationException e) {
LOGGER
.log(Level.WARNING, "Skipped misconfigured coverage " + info.getPath(),
e);
}
}
}
return map;
}
/**
* This method loads the coverage information DTO from an info.xml file on
* the disk.
*
* @param infoFile
* @return
* @throws ConfigurationException
*/
protected CoverageInfoDTO loadCoverage(File infoFile) throws ConfigurationException {
if (!infoFile.exists()) {
throw new IllegalArgumentException("Info File not found:" + infoFile);
}
if (!infoFile.isFile()) {
throw new IllegalArgumentException("Info file is the wrong type:" + infoFile);
}
if (!isInfoFile(infoFile)) {
throw new IllegalArgumentException("Info File not valid:" + infoFile);
}
Element coverageElem = null;
try {
Reader reader = XmlCharsetDetector.getCharsetAwareReader(new FileInputStream(infoFile));
coverageElem = ReaderUtils.parse(reader);
reader.close();
} catch (FileNotFoundException fileNotFound) {
throw new ConfigurationException("Could not read info file:" + infoFile, fileNotFound);
} catch (Exception erk) {
throw new ConfigurationException("Could not parse info file:" + infoFile, erk);
}
// loding the DTO.
CoverageInfoDTO dto = loadCoverageDTOFromXML(coverageElem);
Fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -