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.wcs.requests;
006:
007: import org.vfny.geoserver.wcs.servlets.WCService;
008: import org.xml.sax.Attributes;
009: import org.xml.sax.ContentHandler;
010: import org.xml.sax.SAXException;
011: import org.xml.sax.helpers.XMLFilterImpl;
012: import java.util.logging.Logger;
013: import javax.servlet.http.HttpServletRequest;
014:
015: /**
016: * DOCUMENT ME!
017: *
018: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last modification)
019: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last modification)
020: */
021: public class DescribeHandler extends XMLFilterImpl implements
022: ContentHandler {
023: /** Class logger */
024: private static Logger LOGGER = org.geotools.util.logging.Logging
025: .getLogger("org.vfny.geoserver.requests.wcs");
026:
027: /**
028: * Internal GetCapabilities request for construction.
029: */
030: private DescribeRequest request = null;
031:
032: /** Local variable to track current tag */
033: private String currentTag = new String();
034:
035: public DescribeHandler(WCService service) {
036: super ();
037: request = new DescribeRequest(service);
038: }
039:
040: /**
041: * Returns the DescribeCoverage request.
042: *
043: * @return DescribeCoverage request.
044: */
045: public DescribeRequest getRequest(HttpServletRequest req) {
046: request.setHttpServletRequest(req);
047:
048: return request;
049: }
050:
051: /* ***********************************************************************
052: * Standard SAX content handler methods *
053: * ***********************************************************************/
054:
055: /**
056: * Notes the start of the element and sets the current tag.
057: *
058: * @param namespaceURI URI for namespace appended to element.
059: * @param localName Local name of element.
060: * @param rawName Raw name of element.
061: * @param atts Element attributes.
062: *
063: * @throws SAXException For standard SAX errors.
064: */
065: public void startElement(String namespaceURI, String localName,
066: String rawName, Attributes atts) throws SAXException {
067: LOGGER.finest("found start element: " + localName);
068: currentTag = localName;
069:
070: if (currentTag.equals("DescribeCoverage")) {
071: final int length = atts.getLength();
072:
073: for (int i = 0; i < length; i++) {
074: if (atts.getLocalName(i).equals("outputFormat")) {
075: LOGGER.finest("found outputFormat: "
076: + atts.getValue(i));
077: request.setOutputFormat(atts.getValue(i));
078: } else if (atts.getLocalName(i).equals("service")) {
079: request.setService(atts.getValue(i));
080: } else if (atts.getLocalName(i).equals("version")) {
081: request.setVersion(atts.getValue(i));
082: }
083: }
084: }
085: }
086:
087: /**
088: * Notes the end of the element and sets the current tag.
089: *
090: * @param namespaceURI URI for namespace appended to element.
091: * @param localName Local name of element.
092: * @param rawName Raw name of element.
093: *
094: * @throws SAXException For standard SAX errors.
095: */
096: public void endElement(String namespaceURI, String localName,
097: String rawName) throws SAXException {
098: LOGGER.finest("found end element: " + localName);
099: currentTag = "";
100: }
101:
102: /**
103: * Checks if inside coverage name and adds to coverage list, if so.
104: *
105: * @param ch URI for namespace appended to element.
106: * @param start Local name of element.
107: * @param length Raw name of element.
108: *
109: * @throws SAXException For standard SAX errors.
110: */
111: public void characters(char[] ch, int start, int length)
112: throws SAXException {
113: String s = new String(ch, start, length);
114:
115: if (currentTag.equals("Coverage")) {
116: request.addCoverage(s);
117: LOGGER.finest("added coverage: " + s);
118: }
119: }
120: }
|