📄 cswprofiles.java
字号:
package com.esri.solutions.jitk.datasources.ogc.csw;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.net.URL;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Properties;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
/**
* The collection of CSw profiles
*
* @version 1.0
* @created 25-Jul-2007 1:44:09 PM
*/
public class CswProfiles {
// Stores created profiles
private AbstractMap<String, CswProfile> map = new HashMap<String, CswProfile>();
private String configuration_folder_path = "";
public CswProfiles() {
}
/**
* Add a key value pair to profile collection.
*
* @remark Add to profile collection.
* @param ="param1" The key which is the url hashcode for the profile
* @param ="param2" The profile object
*
* @param key
* @param profile
*/
public void addProfile(CswProfile profile) {
map.put(profile.getId(), profile);
}
/**
* Loads the profile details from configuration file.
*
* @remark The profiles details are loaded in the collection. Duplicate or invalid
* profiles are ignored.
* @param ="param2" the profile configuration file
*
* @param filename
* @throws ParserConfigurationException
* @throws SAXException
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws XPathExpressionException
*/
public void loadProfilefromConfig(String filename)
throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException {
String PROFILE_TAG = "Profile";
CswProfile profile = null;
if ((filename == null) || (filename.length() == 0)) {
// Create absolute path to file
Properties properties = new Properties();
final URL url = CswProfiles.class.getResource(
"CswCommon.properties");
properties.load(url.openStream());
filename = properties.getProperty("DEFAULT_PROFILE_FILE");
configuration_folder_path = properties.getProperty(
"DEFAULT_CONFIGURATION_FOLDER_PATH");
}
// XML parser load doc specified by filename
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = (Document) builder.parse(configuration_folder_path +
filename);
// Get a list of nodes of which root is Profile tag
NodeList profileNodes = doc.getElementsByTagName(PROFILE_TAG);
for (int i = 0; i < profileNodes.getLength(); i++) {
// Get "profile" node
Node currProfile = profileNodes.item(i);
XPath xpath = XPathFactory.newInstance().newXPath();
String id = xpath.evaluate("ID", currProfile);
String name = xpath.evaluate("Name", currProfile);
String description = xpath.evaluate("Description", currProfile);
String requestXslt = xpath.evaluate("GetRecords/XSLTransformations/Request",
currProfile);
String responseXslt = xpath.evaluate("GetRecords/XSLTransformations/Response",
currProfile);
String getRecordByIdKVPs = xpath.evaluate("GetRecordByID/RequestKVPs",
currProfile); // GetRecordByID
// Xslt to transform the response from GetRecordByID
String getRepositoryItemKVPs = xpath.evaluate("GetRepositoryItem/RequestKVPs",
currProfile);
String metadataXslt = xpath.evaluate("GetRecordByID/XSLTransformations/Response",
currProfile);
boolean liveDataMaps = Boolean.parseBoolean(xpath.evaluate(
"SupportSpatialQuery", currProfile));
boolean extentSearch = Boolean.parseBoolean(xpath.evaluate(
"SupportContentTypeQuery", currProfile));
boolean usesMetadataResourceUrl = Boolean.parseBoolean(xpath.evaluate(
"UsesMetadataResourceUrl", currProfile));
profile = new CswProfile(id, name, description, getRecordByIdKVPs,
getRepositoryItemKVPs, requestXslt, responseXslt,
metadataXslt, liveDataMaps, extentSearch,
usesMetadataResourceUrl);
addProfile(profile);
}
}
/**
* Get csw profile with its id
* @param key
*/
public CswProfile getProfileById(String id) {
return (CswProfile) map.get(id);
}
public Collection<CswProfile> getProfilesAsCollection() {
return map.values();
}
public int getSize() {
return map.values().size();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -