org.geoserver.config.util.LegacyServicesReader Maven / Gradle / Ivy
The newest version!
package org.geoserver.config.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.geoserver.catalog.util.ReaderUtils;
import org.geoserver.ows.util.XmlCharsetDetector;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
/**
* Reads the GeoServer services.xml file.
*
* Usage:
*
*
*
* File services = new File(".../services.xml");
* LegacyServicesReader reader = new LegacyServicesReader();
* reader.read(services);
* Map global = reader.global();
* Map wfs = reader.wfs();
*
*
*
*
*
* @author Justin Deoliveira, The Open Planning Project, [email protected]
*
*/
public class LegacyServicesReader {
/**
* Root serverConfiguration element.
*/
Element serverConfiguration;
/**
* Parses the servivces.xml file into a DOM.
*
* This method *must* be called before any other methods.
*
*
* @param file
* The services.xml file.
*
* @throws IOException
* In event of a parser error.
*/
public void read(File file) throws IOException {
Reader reader = XmlCharsetDetector.getCharsetAwareReader(new FileInputStream(file));
try {
serverConfiguration = ReaderUtils.parse(reader);
} finally {
reader.close();
}
}
/**
* Reads the "global" section of the configuration.
*
* The configuration key / value pairs are returned an a map.
*
*
*/
public Map global() throws Exception {
Element globalElement = ReaderUtils.getChildElement(
serverConfiguration, "global");
HashMap global = new HashMap();
value("verbose", globalElement, global, Boolean.class);
value("verboseExceptions", globalElement, global, Boolean.class);
value("charSet", globalElement, global, String.class);
text("updateSequence", globalElement, global, Integer.class, false, 0);
text("log4jConfigFile", globalElement, global, String.class, false, "DEFAULT_LOGGING.properties");
text("logLocation", globalElement, global, String.class, false, "logs/geoserver.log");
value("suppressStdOutLogging", globalElement, global, Boolean.class, false, Boolean.FALSE);
value("maxFeatures", globalElement, global, Integer.class );
value("numDecimals", globalElement, global, Integer.class );
text("onlineResource", globalElement, global, String.class, false, "http://geoserver.org");
text("ProxyBaseUrl", globalElement, global, String.class );
value("JaiMemoryCapacity", globalElement, global, Double.class);
value("JaiMemoryThreshold", globalElement, global, Double.class);
value("JaiTileThreads", globalElement, global, Integer.class);
value("JaiTilePriority", globalElement, global, Integer.class);
value("JaiRecycling", globalElement, global, Boolean.class);
value("ImageIOCache", globalElement, global, Boolean.class);
value("JaiJPEGNative", globalElement, global, Boolean.class);
value("JaiPNGNative", globalElement, global, Boolean.class);
return global;
}
public Map contact() throws Exception {
Element globalElement = ReaderUtils.getChildElement(
serverConfiguration, "global");
HashMap contact = new HashMap();
Element contactElement = ReaderUtils.getChildElement(globalElement, "ContactInformation");
if ( contactElement != null ) {
Element personPrimaryElement = ReaderUtils.getChildElement(contactElement, "ContactPersonPrimary" );
if ( personPrimaryElement != null ) {
text( "ContactPerson", personPrimaryElement, contact, String.class );
text( "ContactOrganization", personPrimaryElement, contact, String.class );
}
text( "ContactPosition", contactElement, contact, String.class );
Element addressElement = ReaderUtils.getChildElement( contactElement, "ContactAddress");
if ( addressElement != null ) {
text( "Address", addressElement, contact, String.class );
text( "AddressType", addressElement, contact, String.class );
text( "City", addressElement, contact, String.class );
text( "StateOrProvince", addressElement, contact, String.class );
text( "PostCode", addressElement, contact, String.class );
text( "Country", addressElement, contact, String.class );
}
text( "ContactVoiceTelephone", contactElement, contact, String.class );
text( "ContactFacsimileTelephone", contactElement, contact, String.class );
text( "ContactElectronicMailAddress", contactElement, contact, String.class );
}
return contact;
}
public Map wfs() throws Exception {
Element servicesElement = ReaderUtils.getChildElement(serverConfiguration, "services", true);
Element wfsElement = service( servicesElement, "WFS" );
Map wfs = readService( wfsElement );
value( "serviceLevel", wfsElement, wfs, Integer.class );
value( "srsXmlStyle", wfsElement, wfs, Boolean.class, false, Boolean.TRUE );
value( "featureBounding", wfsElement, wfs, Boolean.class, false, Boolean.FALSE );
return wfs;
}
public Map wms() throws Exception {
Element servicesElement = ReaderUtils.getChildElement(serverConfiguration, "services", true);
Element wmsElement = service( servicesElement, "WMS" );
Map wms = readService( wmsElement );
text( "globalWatermarking", wmsElement, wms, Boolean.class,false, Boolean.FALSE );
text( "globalWatermarkingURL", wmsElement, wms, String.class, false, null );
text( "globalWatermarkingTransparency", wmsElement, wms, Integer.class, false, 0 );
text( "globalWatermarkingPosition", wmsElement, wms, Integer.class, false, 8 );
text( "allowInterpolation", wmsElement, wms, String.class, false, "Nearest" );
text( "svgRenderer", wmsElement, wms, String.class, false, "Batik" );
text( "svgAntiAlias", wmsElement, wms, Boolean.class, false, Boolean.TRUE );
text( "capabilitiesCrsList", wmsElement, wms, String.class, false, null);
ArrayList