capabilitiesparse.java

来自「esri的ArcGIS Server超级学习模板程序(for java)」· Java 代码 · 共 95 行

JAVA
95
字号
package com.esri.solutions.jitk.datasources.ogc.csw;

import org.apache.log4j.Logger;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class CapabilitiesParse extends DefaultHandler {
    private static final Logger LOG = Logger.getLogger(CapabilitiesParse.class);
    StringBuffer text = new StringBuffer();
    CswCatalogCapabilities cap;
    boolean owsParameter = false;
    boolean capabilities = false;
    boolean getRecordById = false;
    boolean getRecords = false;
    boolean getRepositoryItem = false;

    public CapabilitiesParse(CswCatalogCapabilities capabilities) {
        cap = capabilities;
    }

    public void startElement(String uri, String localName, String qName,
        Attributes attrib) throws SAXException {
        tracking(localName, true);

        if (localName.equals("")) {
            localName = qName;
        }

        LOG.debug("ELEMENT BEGIN " + localName);

        // Define handling rules 
        text = new StringBuffer();

        if (capabilities && localName.equalsIgnoreCase("operation")) {
            if (attrib.getValue("name").equalsIgnoreCase("GetRecordById")) {
                getRecordById = true;
            } else {
                getRecordById = false;
            }

            if (attrib.getValue("name").equalsIgnoreCase("GetRecords")) {
                getRecords = true;
            } else {
                getRecords = false;
            }

            if (attrib.getValue("name").equalsIgnoreCase("GetRepositoryItem")) {
                getRepositoryItem = true;
            } else {
                getRepositoryItem = false;
            }
        }

        if (capabilities && getRecordById && localName.equalsIgnoreCase("GET")) {
            cap.set_getRecordByIDGetURL(attrib.getValue("xlink:href"));
        }

        if (capabilities && getRecords && localName.equalsIgnoreCase("POST")) {
            cap.set_getRecordsPostURL(attrib.getValue("xlink:href"));
        }

        if (capabilities && getRepositoryItem &&
                localName.equalsIgnoreCase("GET")) {
            cap.set_getRepositoryItemURL(attrib.getValue("xlink:href"));
        }
    }

    public void endElement(String uri, String localName, String qName)
        throws SAXException {
        if (localName.equals("")) {
            localName = qName;
        }

        LOG.debug("TEXT IN ELEMENT " + text);
        LOG.debug("ELEMENT END " + localName);
        text = new StringBuffer();
        tracking(localName, false);
    }

    private void tracking(String element, boolean alive) {
        if (element.equals("owsParameter")) {
            owsParameter = alive;
        } else if (element.equals("Capabilities")) {
            capabilities = alive;
        }
    }

    public void characters(char[] chars, int start, int length) {
        text.append(chars, start, length);
    }
}

⌨️ 快捷键说明

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