📄 cswcatalogs.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.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;
/**
* Collections class for catalogs.
*
* @remark The collection support both sequential and random access objects based
* on key.
* @version 1.0
* @created 25-Jul-2007 1:40:02 PM
*/
public class CswCatalogs {
private AbstractMap<String, CswCatalog> map = new HashMap<String, CswCatalog>();
public CswCatalogs() {
}
/**
* Add a key value pair to catalog collection.
*
* @remark Add to catalog collection.
* @param ="param1" The key which is the url hashcode for the catalog
* @param ="param2" the catalog object
*
* @param key
* @param catalog
*/
public void addCatalog(String key, CswCatalog catalog) {
map.put(key, catalog);
}
/**
* Add a catalog using its id as a key.
* @param catalog
*/
public void addCatalog(CswCatalog catalog) {
map.put(catalog.getId(), catalog);
}
/**
* Add a new Catalog to the collection. The catalog details are also added to the
* configuration to the file.
*
* @remark The catalog details are added in the collection. The catalog details
* are also appended in the configuration file.
* @param ="param1" CswCatalog
* @param ="param2" the catalog configuration file
*
* @param catalog
* @param filename
*/
public void addCatalogtoConfig(CswCatalog catalog, String filename) {
// NO IMPLMENTATION NEEDED
}
/**
* Delete an existing Catalog from the configuration file.
*
* @remark The catalog details are deleted from the collection. The catalog
* details are also deleted from the configuration file.
* @param ="param1" CswCatalog
* @param ="param2" the catalog configuration file
*
* @param catalog
* @param filename
*/
public void deleteCatalogfromConfig(CswCatalog catalog, String filename) {
// NO IMPLMENTATION NEEDED
}
/**
* Loads the catalog details from configuration file.
*
* @remark The catalog details are loaded in the collection. Duplicate or invalid
* catalog are ignored. Invalid catalog includes catalogs with profiles
* information not present in profiles collection.
* @param ="param1" the catalog configuration file
* @param ="param2" the profiles collection
*
* @param filename
* @param profileList
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws XPathExpressionException
*/
public void loadCatalogfromConfig(String filename, CswProfiles profileList)
throws ParserConfigurationException, SAXException, IOException,
XPathExpressionException {
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_CONFIGURATION_FOLDER_PATH");
filename += properties.getProperty("DEFAULT_CATALOG_FILE");
}
String CATALOG_TAG = "CSWCatalog";
DocumentBuilder builder = DocumentBuilderFactory.newInstance()
.newDocumentBuilder();
Document doc = builder.parse(filename);
NodeList nodes = doc.getElementsByTagName(CATALOG_TAG);
for (int i = 0; i < nodes.getLength(); i++) {
Node currNode = nodes.item(i);
// Parse xml and get each value
XPath xpath = XPathFactory.newInstance().newXPath();
String url = xpath.evaluate("URL", currNode);
String name = xpath.evaluate("Name", currNode);
// get profile id from the current node
String profileId = xpath.evaluate("CSWProfile", currNode);
//String userName = xpath.evaluate("Credentials/Username", currNode);
//String password = xpath.evaluate("Credentials/Password", currNode);
// get the corresponding profile from CswProfiles
CswProfile profile = profileList.getProfileById(profileId);
CswCatalog catalog = new CswCatalog(url, name, profile);
addCatalog(catalog);
}
}
/**
*
* @param key
*/
public CswCatalog getCatalog(String id) {
return (CswCatalog) map.get(id);
}
public CswCatalog getCatalog(int index) {
String key = null;
key = (String) map.keySet().toArray()[index];
return (CswCatalog) map.get(key);
}
public int getSize() {
return map.values().size();
}
/**
* Update the name of an existing Catalog. The name is also updated in the
* configuration file.
*
* @remark The catalog name is updated from the collection. The catalog name is
* also updated from the configuration file.
* @param ="param1" CswCatalog
* @param ="param2" The string name
* @param ="param2" The string updated url
* @param ="param2" The string name
* @param ="param3" the catalog configuration file
*
* @param catalog
* @param displayname
* @param surl
* @param profile
* @param filename
*/
public void updateCatalogNameinConfig(CswCatalog catalog,
String displayname, String surl, CswProfile profile, String filename) {
// NO IMPLMENTATION NEEDED
}
/**
* Update the file with the collection details. The catalog details are also added
* to the configuration to the file.
*
* @remark The catalog details are populated from the collection. The catalog
* details are added to the configuration file.
* @param ="param1" the catalog configuration filename
*
* @param filename
*/
/*private void updateToFile(String fileName) {
// NO IMPLMENTATION NEEDED
}*/
/**
* replace special xml character
*
* @remark Encode special characters (such as &, ", <, >, ') to percent values.
* </remarks>
* <param name="data
*
* @param data
*/
/*private String XmlDatatoString(String data) {
//TODO: CHANGE THIS BY LOOKING AT C# CODE
return "";
}*/
/**
* replace special xml character
*
* @remark Encode special characters (such as &, ", <, >, ') to percent values.
* </remarks>
* <param name="data
*
* @param data
*/
/*private String XmlEscape(String data) {
//TODO: CHANGE THIS BY LOOKING AT C# CODE
return "";
}*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -