⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dispatcherxmlreader.java

📁 电子地图服务器,搭建自己的地图服务
💻 JAVA
字号:
/* Copyright (c) 2001 - 2007 TOPP - www.openplans.org.  All rights reserved.
 * This code is licensed under the GPL 2.0 license, availible at the root
 * application directory.
 */
package org.vfny.geoserver.util.requests.readers;

import org.apache.xerces.parsers.SAXParser;
import org.vfny.geoserver.ServiceException;
import org.vfny.geoserver.util.requests.DispatcherHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import java.io.IOException;
import java.io.Reader;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;


/**
 * This reads in a request and figures out what servlet to dispatch it to.
 * This does not extend XmlRequestReader, since it does not actually create
 * the Request, it is just used to pass on the request to a service that can
 * make the request. The Reader passed in should never be the one directly
 * from the HttpServletRequest, if that is used then the next xml reader to
 * get the request will not work.  A new  BufferedReader should be constructed
 * from the reader of HttpServletRequest, and its mark should be set and then
 * reset after this reader is done with it.  Nothing else seems to work, for
 * some reason.
 *
 * <p>
 * In an ideal, refactored world we would implement our handlers better, and
 * the xml reader could dynamically figure out which handler to pass it to.
 * But we have no time for that now, so we'll just live with this.
 * </p>
 *
 * @author Chris Holmes
 * @version $Id: DispatcherXmlReader.java 7746 2007-11-13 15:38:35Z aaime $
 *
 * @task REVISIT: This might be better implemented to extend XmlRequestReader,
 *       and to actually construct the requests with the DispatcherHandler.
 *       This way it could really handle WMS dispatching as well, since it
 *       could figure out the service as  well as the request.  The
 *       getRequestType would be complemented by getServiceType, and each
 *       would just extract the information from the Request that was made.
 *       But right now we don't have much in the way of
 */
public class DispatcherXmlReader {
    /** Class logger */
    private static Logger LOGGER = org.geotools.util.logging.Logging.getLogger("org.vfny.geoserver.requests.readers");

    /** Handler for request interpretation duties. */
    private DispatcherHandler currentRequest;

    public DispatcherXmlReader() {
    }

    /**
     * Constructor with raw request string.  Calls parent.
     *
     * @param reader A reader of the request from the http client.
     * @param req The actual request made.
     *
     * @throws ServiceException DOCUMENT ME!
     */
    public void read(Reader reader, HttpServletRequest req)
        throws ServiceException {
        //InputSource requestSource = new InputSource((Reader) tempReader);
        InputSource requestSource = new InputSource(reader);

        // instantiante parsers and content handlers
        XMLReader parser = new SAXParser();
        this.currentRequest = new DispatcherHandler();

        // read in XML file and parse to content handler
        try {
            parser.setContentHandler(currentRequest);
            parser.parse(requestSource);
        } catch (SAXException e) {
            throw new ServiceException(e, "XML request parsing error",
                DispatcherXmlReader.class.getName());
        } catch (IOException e) {
            throw new ServiceException(e, "XML request input error",
                DispatcherXmlReader.class.getName());
        }
    }

    /**
     * @return The service, WFS,WMS,WCS,etc...
     */
    public String getService() {
        return currentRequest.getService();
    }

    /**
     * @return The request, GetCapabilities,GetMap,etc...
     */
    public String getRequest() {
        LOGGER.info("getting request type from " + currentRequest);

        return currentRequest.getRequest();
    }

    //JD: kill these
    //    /**
    //     * Returns the guessed request type..
    //     *
    //     * @return Request type.
    //     */
    //    public int getRequestType() {
    //        
    //
    //        return currentRequest.getRequestType();
    //    }
    //
    //    public int getServiceType() {
    //        return currentRequest.getServiceType();
    //    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -