001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.global.dto;
006:
007: import org.vfny.geoserver.global.GeoServer;
008: import java.nio.charset.Charset;
009: import java.util.logging.Level;
010: import javax.servlet.ServletContext;
011:
012: /**
013: * Data Transfer Object for Global GeoServer Configuration information.
014: *
015: * <p>
016: * Data Transfer object are used to communicate between the GeoServer
017: * application and its configuration and persistent layers. As such the class
018: * is final - to allow for its future use as an on-the-wire message.
019: * </p>
020: *
021: * @author David Zwiers, Refractions Research, Inc.
022: * @version $Id: GeoServerDTO.java 8406 2008-02-14 19:49:39Z saul.farber $
023: */
024: public final class GeoServerDTO implements DataTransferObject {
025: public static class Defaults {
026: /**
027: * The default MaxFeatures is 10000
028: *
029: * @see #getMaxFeatures(int)
030: */
031: public static final int MaxFeatures = 10000;
032:
033: /**
034: * The default encoding for GeoServer it UTF-8.
035: *
036: * @see #getCharSet()
037: */
038: public static final Charset Encoding = Charset.forName("UTF-8");
039:
040: /** The default verbosity is true, human readable. */
041: public static final boolean Verbose = true;
042:
043: /** Default is four decimal places. */
044: public static final int NumDecimals = 4;
045:
046: /** The default Administrator's user name (admin) */
047: public static final String AdminUserName = "admin";
048:
049: /** The default Administrator's password (geoserver) */
050: public static final String AdminPassword = "geoserver";
051:
052: /**
053: * The default verboseExceptions is false, so that by default the
054: * service exceptions don't look like someone 'kacked'.
055: */
056: public static final boolean VerboseExceptions = false;;
057: public static final long JaiMemoryCapacity = 200 * 1024 * 1024;
058: public static final double JaiMemoryThreshold = 0.75;
059: public static final int JaiTileThreads = 7;
060: public static final int JaiTilePriority = Thread.NORM_PRIORITY;
061: public static final Boolean JaiRecycling = Boolean.TRUE;
062: public static final Boolean ImageIOCache = Boolean.FALSE;
063: public static final Boolean JaiJPEGNative = Boolean.TRUE;
064: public static final Boolean JaiPNGNative = Boolean.TRUE;
065: public static final String BaseURL = null;
066: public static final String Log4jConfigFile = null;
067: /** Default of wether to log to StdOut as well **/
068: public static final boolean SuppressStdOutLogging = false;
069: /** Default logging location on disk **/
070: public static final String LogLocation = null;
071: }
072:
073: /** Sets the max number of Features returned by GetFeature */
074: private int maxFeatures = Defaults.MaxFeatures;
075:
076: /**
077: * XML Verbosity.
078: *
079: * <p>
080: * Whether newlines and indents should be returned in XML responses.
081: * </p>
082: *
083: * <p>
084: * This should be called something other than verbose. Verbose should
085: * control things like printing out "magic" comments that tell people how
086: * to edit the xml files by hand.
087: * </p>
088: * Default is false
089: */
090: private boolean verbose = Defaults.Verbose;
091:
092: /**
093: * Number of decimal places returned in a GetFeature response.
094: *
095: * <p>
096: * Sets the max number of decimal places past the zero returned in a
097: * GetFeature response. Default is 4.
098: * </p>
099: * DZ - should it be moved to FeatureTypeInfo level? JG - no WMS also has a
100: * getFeature response
101: */
102: private int numDecimals = Defaults.NumDecimals;
103:
104: /**
105: * Sets the global character set.
106: *
107: * <p>
108: * This could use some more testing from international users. What it does
109: * is sets the encoding globally for all postgis database connections (the
110: * charset tag in FeatureTypeInfo), as well as specifying the encoding in
111: * the return
112: * <code>org.vfny.geoserver.config.org.vfny.geoserver.global.xml</code>
113: * header and mime type.
114: * </p>
115: *
116: * <p>
117: * The default is UTF-8
118: * </p>
119: *
120: * <p>
121: * Also be warned that GeoServer does not check if the CharSet is valid
122: * before attempting to use it, so it will fail miserably if a bad charset
123: * is used.
124: * </p>
125: */
126: private Charset charSet = Defaults.Encoding;
127:
128: /**
129: * The public network URL base, to be used when Geoserver is behind a reverse proxy
130: * so that getCapabilities return the proper URLs.
131: */
132: private String proxyBaseUrl;
133:
134: /**
135: * Define a base url for the location of the wfs schemas.
136: *
137: * <p>
138: * By default GeoServer loads and references its own at
139: * <code>/data/capabilities</code>.
140: * </p>
141: *
142: * <p>
143: * The standalone Tomcat server needs SchemaBaseUrl defined for validation.
144: * </p>
145: */
146: private String schemaBaseUrl;
147:
148: /**
149: * Defines the Application logging level.
150: *
151: * <p>
152: * Common options are SEVERE, WARNING, INFO, CONFIG, FINER, FINEST, in
153: * order of Increasing statements logged.
154: * </p>
155: *
156: * <p>
157: * There may be more then one point of control - the web containers often
158: * controls logging, the jakarta commons logging system is used by struts,
159: * these names seem taken from the jdk14 logging framework and GeoServer
160: * seems to also use log4j.
161: * </p>
162: */
163: private String log4jConfigFile = Defaults.Log4jConfigFile;
164:
165: private boolean suppressStdOutLogging = Defaults.SuppressStdOutLogging;
166: private String logLocation = Defaults.LogLocation;
167:
168: /** The Server contact person and their contact information. */
169: private ContactDTO contact = null;
170:
171: /** The username for the administrator log-in to perform configuration */
172: private String adminUserName = Defaults.AdminUserName;
173:
174: /** The password for the administrator log-in to perform configuration */
175: private String adminPassword = Defaults.AdminPassword;
176:
177: /** Whether the exceptions returned to the client should contain full stack traces */
178: private boolean verboseExceptions = Defaults.VerboseExceptions;
179:
180: private double jaiMemoryCapacity = Defaults.JaiMemoryCapacity;
181: private double jaiMemoryThreshold = Defaults.JaiMemoryThreshold;
182: private int jaiTileThreads = Defaults.JaiTileThreads;
183: private int jaiTilePriority = Defaults.JaiTilePriority;
184: private Boolean jaiRecycling = Defaults.JaiRecycling;
185: private Boolean imageIOCache = Defaults.ImageIOCache;
186: private Boolean jaiJPEGNative = Defaults.JaiJPEGNative;
187: private Boolean jaiPNGNative = Defaults.JaiPNGNative;
188:
189: /** tile cache location, full url or relative path */
190: private String tileCache;
191:
192: /** the current update sequence **/
193: private int updateSequence;
194:
195: /**
196: * GlobalConfig constructor.
197: *
198: * <p>
199: * does nothing
200: * </p>
201: */
202: public GeoServerDTO() {
203: }
204:
205: /**
206: * GlobalConfig constructor.
207: *
208: * <p>
209: * Creates a copy of the GlobalConfig object provided, or sets the values
210: * to default if one is not provided. Charset is not cloned, everything
211: * else is.
212: * </p>
213: *
214: * @param g
215: *
216: * @throws NullPointerException DOCUMENT ME!
217: */
218: public GeoServerDTO(GeoServerDTO g) {
219: if (g == null) {
220: throw new NullPointerException();
221: }
222:
223: maxFeatures = g.getMaxFeatures();
224: verbose = g.isVerbose();
225: numDecimals = g.getNumDecimals();
226: charSet = g.getCharSet();
227: schemaBaseUrl = g.getSchemaBaseUrl();
228: proxyBaseUrl = g.getProxyBaseUrl();
229: log4jConfigFile = g.getLog4jConfigFile();
230: verboseExceptions = g.isVerboseExceptions();
231:
232: suppressStdOutLogging = g.getSuppressStdOutLogging();
233: logLocation = g.getLogLocation();
234:
235: jaiMemoryCapacity = g.getJaiMemoryCapacity();
236: jaiMemoryThreshold = g.getJaiMemoryThreshold();
237: jaiTileThreads = g.getJaiTileThreads();
238: jaiTilePriority = g.getJaiTilePriority();
239: jaiRecycling = g.getJaiRecycling();
240: imageIOCache = g.getImageIOCache();
241: jaiJPEGNative = g.getJaiJPEGNative();
242: jaiPNGNative = g.getJaiPNGNative();
243:
244: tileCache = g.getTileCache();
245:
246: if (g.getContact() != null) {
247: contact = (ContactDTO) (g.getContact().clone());
248: } else {
249: contact = new ContactDTO();
250: }
251: }
252:
253: /**
254: * Implement clone.
255: *
256: * <p>
257: * Charset is not cloned, everything else is. Strings are reference copied
258: * because of the Hashtable implementation in memory.
259: * </p>
260: *
261: * @return A new GlobalConfig object which is a copy of this object.
262: *
263: * @see java.lang.Object#clone()
264: */
265: public Object clone() {
266: return new GeoServerDTO(this );
267: }
268:
269: /**
270: * Implement equals.
271: *
272: * <p>
273: * Compares the equality of the two objects.
274: * </p>
275: *
276: * @param obj The object to checked for equivalence.
277: *
278: * @return true when the objects are the same.
279: *
280: * @see java.lang.Object#equals(java.lang.Object)
281: */
282: public boolean equals(Object obj) {
283: if ((obj == null) || !(obj instanceof GeoServerDTO)) {
284: return false;
285: }
286:
287: GeoServerDTO g = (GeoServerDTO) obj;
288: boolean r = true;
289: r = r && (maxFeatures == g.getMaxFeatures());
290: r = r && (verbose == g.isVerbose());
291: r = r && (numDecimals == g.getNumDecimals());
292:
293: if (charSet != null) {
294: r = r && charSet.equals(g.getCharSet());
295: } else if (g.getCharSet() != null) {
296: return false;
297: }
298:
299: r = r && (schemaBaseUrl == g.getSchemaBaseUrl());
300:
301: r = r && (proxyBaseUrl == g.getProxyBaseUrl());
302:
303: if (contact != null) {
304: r = r && contact.equals(g.getContact());
305: } else if (g.getContact() != null) {
306: return false;
307: }
308:
309: r = r && (log4jConfigFile.equals(g.getLog4jConfigFile()));
310:
311: if (logLocation != null) {
312: r = r && logLocation.equals(g.getLogLocation());
313: } else if (g.getLogLocation() != null) {
314: return false;
315: }
316:
317: if (tileCache != null) {
318: r = r && tileCache.equals(g.getTileCache());
319: } else if (g.getTileCache() != null) {
320: return false;
321: }
322:
323: r = r && (jaiMemoryCapacity == g.getJaiMemoryCapacity());
324: r = r && (jaiMemoryThreshold == g.getJaiMemoryThreshold());
325: r = r && (jaiTileThreads == g.getJaiTileThreads());
326: r = r && (jaiTilePriority == g.getJaiTilePriority());
327: r = r && (jaiRecycling == g.getJaiRecycling());
328: r = r && (imageIOCache == g.getImageIOCache());
329: r = r && (jaiJPEGNative == g.getJaiJPEGNative());
330: r = r && (jaiPNGNative == g.getJaiPNGNative());
331:
332: return r;
333: }
334:
335: public int hashCode() {
336: int i = 1;
337:
338: if (maxFeatures != 0) {
339: i *= maxFeatures;
340: }
341:
342: if (numDecimals != 0) {
343: i *= numDecimals;
344: }
345:
346: if (schemaBaseUrl != null) {
347: i *= schemaBaseUrl.hashCode();
348: }
349:
350: return i;
351: }
352:
353: /**
354: * getCharSet purpose.
355: *
356: * <p>
357: * Description ...
358: * </p>
359: *
360: * @return
361: */
362: public Charset getCharSet() {
363: return charSet;
364: }
365:
366: /**
367: * getContact purpose.
368: *
369: * <p>
370: * Description ...
371: * </p>
372: *
373: * @return
374: */
375: public ContactDTO getContact() {
376: return contact;
377: }
378:
379: /**
380: * getLoggingLevel purpose.
381: *
382: * <p>
383: * Description ...
384: * </p>
385: *
386: * @return
387: */
388:
389: //public Level getLoggingLevel() {
390: // return loggingLevel;
391: //}
392: /**
393: * getMaxFeatures purpose.
394: *
395: * <p>
396: * Description ...
397: * </p>
398: *
399: * @return
400: */
401: public int getMaxFeatures() {
402: return maxFeatures;
403: }
404:
405: /**
406: * getNumDecimals purpose.
407: *
408: * <p>
409: * Description ...
410: * </p>
411: *
412: * @return
413: */
414: public int getNumDecimals() {
415: return numDecimals;
416: }
417:
418: /**
419: * Getter for the {@link #proxyBaseUrl} property
420: * @return
421: */
422: public String getProxyBaseUrl() {
423: return proxyBaseUrl;
424: }
425:
426: /**
427: * getSchemaBaseUrl purpose.
428: *
429: * <p>
430: * Description ...
431: * </p>
432: *
433: * @return
434: */
435: public String getSchemaBaseUrl() {
436: return schemaBaseUrl;
437: }
438:
439: /**
440: * isVerbose purpose.
441: *
442: * <p>
443: * Description ...
444: * </p>
445: *
446: * @return
447: */
448: public boolean isVerbose() {
449: return verbose;
450: }
451:
452: /**
453: * setCharSet purpose.
454: *
455: * <p>
456: * Description ...
457: * </p>
458: *
459: * @param charset
460: */
461: public void setCharSet(Charset charset) {
462: if (charset == null) {
463: charset = Charset.forName("ISO-8859-1");
464: }
465:
466: charSet = charset;
467: }
468:
469: /**
470: * setContact purpose.
471: *
472: * <p>
473: * Description ...
474: * </p>
475: *
476: * @param contact
477: */
478: public void setContact(ContactDTO contact) {
479: if (contact == null) {
480: contact = new ContactDTO();
481: }
482:
483: this .contact = contact;
484: }
485:
486: /**
487: * setMaxFeatures purpose.
488: *
489: * <p>
490: * Description ...
491: * </p>
492: *
493: * @param i
494: */
495: public void setMaxFeatures(int i) {
496: maxFeatures = i;
497: }
498:
499: /**
500: * setNumDecimals purpose.
501: *
502: * <p>
503: * Description ...
504: * </p>
505: *
506: * @param i
507: */
508: public void setNumDecimals(int i) {
509: numDecimals = i;
510: }
511:
512: /**
513: * setSchemaBaseUrl purpose.
514: *
515: * <p>
516: * Description ...
517: * </p>
518: *
519: * @param url
520: */
521: public void setSchemaBaseUrl(String url) {
522: schemaBaseUrl = url;
523: }
524:
525: /**
526: * Setter for the {@linkplain #proxyBaseUrl} property
527: * @param url
528: */
529: public void setProxyBaseUrl(String url) {
530: proxyBaseUrl = url;
531: }
532:
533: /**
534: * setVerbose purpose.
535: *
536: * <p>
537: * Description ...
538: * </p>
539: *
540: * @param b
541: */
542: public void setVerbose(boolean b) {
543: verbose = b;
544: }
545:
546: /**
547: * getLoggingLevel purpose.
548: *
549: * <p>
550: * Description ...
551: * </p>
552: *
553: * @return
554: */
555: public String getLog4jConfigFile() {
556: return log4jConfigFile;
557: }
558:
559: /**
560: * setLoggingLevel purpose.
561: *
562: * <p>
563: * Description ...
564: * </p>
565: *
566: * @param level
567: */
568: public void setLog4jConfigFile(String s) {
569: log4jConfigFile = s;
570: }
571:
572: /**
573: * Gets the user name of the administrator of GeoServer, for login
574: * purposes.
575: *
576: * @return The administrator's password.
577: */
578: public String getAdminUserName() {
579: return adminUserName;
580: }
581:
582: /**
583: * Sets the user name of the administrator of GeoServer, for login
584: * purposes.
585: *
586: * @param username the String to set as the admin username.
587: */
588: public void setAdminUserName(String username) {
589: this .adminUserName = username;
590: }
591:
592: /**
593: * Gets the password of the administrator of GeoServer, for login purposes.
594: *
595: * @return The password of the administrator.
596: */
597: public String getAdminPassword() {
598: return adminPassword;
599: }
600:
601: /**
602: * Sets the password of the administrator of GeoServer, for login purposes.
603: *
604: * @param password The password to set as the login password.
605: */
606: public void setAdminPassword(String password) {
607: this .adminPassword = password;
608: }
609:
610: /**
611: * Should we display stackTraces or not? (And give them a nice little
612: * message instead?)
613: *
614: * @return Returns the showStackTraces.
615: */
616: public boolean isVerboseExceptions() {
617: return verboseExceptions;
618: }
619:
620: /**
621: * If set to true, response exceptions will throw their stack trace back to
622: * the end user.
623: *
624: * @param showStackTraces The showStackTraces to set.
625: */
626: public void setVerboseExceptions(boolean showStackTraces) {
627: this .verboseExceptions = showStackTraces;
628: }
629:
630: /**
631: * Returns the location of where the server ouputs logs. Note that this may
632: * not reference an actual physical location on disk.
633: * Call {@link GeoServer#getLogLocation(String, ServletContext)} to map this
634: * string to a file on disk.
635: *
636: */
637: public String getLogLocation() {
638: return logLocation;
639: }
640:
641: /**
642: * @param logLocation The string representation of the path on disk in which
643: * the server logs to.
644: */
645: public void setLogLocation(String logLocation) {
646: this .logLocation = logLocation;
647: }
648:
649: /**
650: * @return True if the server is logging to file, otherwise false.
651: */
652: public boolean getSuppressStdOutLogging() {
653: return suppressStdOutLogging;
654: }
655:
656: /**
657: * Toggles server also sending logging stream to stdout via ConsoleLogger.
658: */
659: public void setSuppressStdOutLogging(boolean b) {
660: this .suppressStdOutLogging = b;
661: }
662:
663: public String toString() {
664: StringBuffer dto = new StringBuffer("[GeoServerDTO: \n");
665: dto.append(" maxFeatures - " + maxFeatures);
666: dto.append("\n verbose - " + verbose);
667: dto.append("\n numDecimals - " + numDecimals);
668: dto.append("\n charSet - " + charSet);
669: dto.append("\n logLocation - " + logLocation);
670: dto.append("\n adminUserName - " + adminUserName);
671: dto.append("\n adminPassword - " + adminPassword);
672: dto.append("\n contact - " + contact);
673:
674: return dto.toString();
675: }
676:
677: public double getJaiMemoryCapacity() {
678: return jaiMemoryCapacity;
679: }
680:
681: public void setJaiMemoryCapacity(double jaiMemoryCapacity) {
682: this .jaiMemoryCapacity = jaiMemoryCapacity;
683: }
684:
685: public Boolean getJaiRecycling() {
686: return jaiRecycling;
687: }
688:
689: public void setJaiRecycling(Boolean jaiRecycling) {
690: this .jaiRecycling = jaiRecycling;
691: }
692:
693: public Boolean getJaiJPEGNative() {
694: return jaiJPEGNative;
695: }
696:
697: public void setJaiJPEGNative(Boolean jaiJPEGNative) {
698: this .jaiJPEGNative = jaiJPEGNative;
699: }
700:
701: public Boolean getJaiPNGNative() {
702: return jaiPNGNative;
703: }
704:
705: public void setJaiPNGNative(Boolean jaiPNGNative) {
706: this .jaiPNGNative = jaiPNGNative;
707: }
708:
709: public double getJaiMemoryThreshold() {
710: return jaiMemoryThreshold;
711: }
712:
713: public void setJaiMemoryThreshold(double jaiMemoryThreshold) {
714: this .jaiMemoryThreshold = jaiMemoryThreshold;
715: }
716:
717: /**
718: * @return Returns the imageIOCache.
719: */
720: public Boolean getImageIOCache() {
721: return imageIOCache;
722: }
723:
724: /**
725: * @param imageIOCache The imageIOCache to set.
726: */
727: public void setImageIOCache(Boolean imageIOCache) {
728: this .imageIOCache = imageIOCache;
729: }
730:
731: public int getJaiTilePriority() {
732: return jaiTilePriority;
733: }
734:
735: public void setJaiTilePriority(int jaiTilePriority) {
736: this .jaiTilePriority = jaiTilePriority;
737: }
738:
739: public int getJaiTileThreads() {
740: return jaiTileThreads;
741: }
742:
743: public void setJaiTileThreads(int jaiTileThreads) {
744: this .jaiTileThreads = jaiTileThreads;
745: }
746:
747: /**
748: * tile cache parameter
749: * @see GeoServer#getTileCache()
750: */
751: public String getTileCache() {
752: return tileCache;
753: }
754:
755: public void setTileCache(String tileCache) {
756: this .tileCache = tileCache;
757: }
758:
759: /**
760: * @return the updateSequence
761: */
762: public int getUpdateSequence() {
763: return updateSequence;
764: }
765:
766: /**
767: * @param updateSequence the updateSequence to set
768: */
769: public void setUpdateSequence(int updateSequence) {
770: this.updateSequence = updateSequence;
771: }
772: }
|