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

📄 wcscapabilitiesparser.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
/**
 * 
 */
package com.esri.solutions.jitk.datasources.ogc.wcs.parsing.version110;

import java.io.InputStream;

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

import com.esri.solutions.jitk.datasources.exceptions.ResponseParsingException;
import com.esri.solutions.jitk.datasources.ogc.wcs.Val;
import com.esri.solutions.jitk.datasources.ogc.wcs.info.WCSCapabilities;
import com.esri.solutions.jitk.datasources.ogc.wcs.info.WCSCoverageInfoBrief;
import com.esri.solutions.jitk.datasources.ogc.wcs.info.WCSEnvelope;
import com.esri.solutions.jitk.datasources.ogc.wcs.parsing.IWCSCapabilitiesParser;
import com.esri.solutions.jitk.datasources.ogc.wcs.parsing.WCSParserBase;

/**
 * @author vlad2928
 *
 */
public class WCSCapabilitiesParser extends WCSParserBase implements IWCSCapabilitiesParser {
	
	private boolean _doResponse;
	private boolean _doServiceIdentification;
	private boolean _doKeywords;
	private boolean _doOperationsMetadata;
	private boolean _doOperation;
	private boolean _doFormat;
	private boolean _doContents;
	private boolean _doCoverageSummary;
	
	private String _version;
	private StringBuffer _operation;
	private WCSEnvelope _lonLatEnvelope;
	private WCSCoverageInfoBrief _coverageInfo;
	private WCSCapabilities _capabilities; 
	
	public WCSCapabilitiesParser() {
		this.version = "1.1.0";
	}
	
	/* (non-Javadoc)
	 * @see com.esri.solutions.jitk.datasources.ogc.wcs.xml.parsing.IWCSCapabilitiesParser#parse(java.lang.String)
	 */
	public WCSCapabilities parse(InputStream is) throws ResponseParsingException {
		super.parse(is, this);
		return _capabilities;
	}
	
	@Override
	public void startDocument() throws SAXException {
		_doResponse = _doServiceIdentification = _doKeywords = _doOperationsMetadata = _doOperation = _doFormat = _doContents = _doCoverageSummary = false;
		_version = "";
		_operation = null;
		_lonLatEnvelope = null;
		_coverageInfo = null;
		_capabilities = null;
		_characters = null;
	}

	@Override
	public void startElement(String uri, String localName, String name, Attributes atts) throws SAXException {
		
		String sTagName = name.replaceFirst("^\\w*:", "");
		
		if(_doResponse) {
			doResponse(sTagName, atts);
		}
		
		if(sTagName.equalsIgnoreCase("Capabilities")) {
			_version = Val.chkStr(atts.getValue("version"));
			_doResponse = (_version.equals(this.getVersion()));
			
			if(_doResponse) {
				_capabilities = new WCSCapabilities();
				_capabilities.setVersion(_version);
				
			} else {
				throw new SAXException(this.getClass().getName() + " can not parse WCS GetCapabilities response ver. " + _version + ". Incompatible version.");
			}
		}
	}
	
	private void doResponse(String name, Attributes atts) {
		
		_characters = new StringBuffer();
		
		if(_doServiceIdentification) {
			doServiceIdentification(name, atts);
			
		} else if(_doOperationsMetadata) {
			doOperationsMetadata(name, atts);
		
		} else if(_doContents) {
			doContents(name, atts);
			
		} else if(name.equalsIgnoreCase("ServiceIdentification")) {
			_doServiceIdentification = true;
		
		} else if(name.equalsIgnoreCase("OperationsMetadata")) {
			_doOperationsMetadata = true;
		
		} else if(name.equalsIgnoreCase("Contents")) {
			_doContents = true;	
		}
	}
	
	private void doServiceIdentification(String name, Attributes atts) {
		if(name.equalsIgnoreCase("keywords")) {
			_doKeywords = true;
		}
	}
	
	private void doOperationsMetadata(String name, Attributes atts) {
		
		if(_doOperation) {
			 
			if(name.equalsIgnoreCase("Get")) {
				_operation.append("|").append(Val.chkStr(atts.getValue("xlink:href")));
			
			} else if(name.equalsIgnoreCase("Parameter") && Val.chkStr(atts.getValue("name")).equalsIgnoreCase("format")) {
				_doFormat = true;
			} 
			
			
		} else if(name.equalsIgnoreCase("Operation")) {
			String opName = Val.chkStr(atts.getValue("name"));
			
			if(opName.equalsIgnoreCase("GetCapabilities") || opName.equalsIgnoreCase("DescribeCoverage") || opName.equalsIgnoreCase("GetCoverage")) {
				_operation = new StringBuffer();
				_operation.append(opName);
				_doOperation = true;
			}	
		}
	}
	
	private void doContents(String name, Attributes atts) {
		
		if(_doCoverageSummary) {
			
			if(name.equalsIgnoreCase("WGS84BoundingBox")) {
				_lonLatEnvelope = new WCSEnvelope();
				_lonLatEnvelope.setCRS("WGS84(DD)");
			}
		
		} else if(name.equalsIgnoreCase("CoverageSummary")) {
			_coverageInfo = new WCSCoverageInfoBrief();
			_doCoverageSummary = true;
		}
	}
	
	@Override
	public void endElement(String uri, String localName, String name) throws SAXException {
		
		String sTagName = name.replaceFirst("^\\w*:", "");
		
		if(_doServiceIdentification) {
			
			if(_doKeywords) {
				
				if(sTagName.equalsIgnoreCase("keyword")) {
					_capabilities.getKeywords().add(_characters.toString());
				
				} else if(sTagName.equalsIgnoreCase("keywords")) {
					_doKeywords = false;
				}
				
			} else if(sTagName.equalsIgnoreCase("title")) {
				_capabilities.setName(Val.escapeXmlForBrowser(_characters.toString()));
			
			} else if(sTagName.equalsIgnoreCase("ServiceIdentification")) {
				_doServiceIdentification = false;
			}
			
		} else if(_doOperationsMetadata) {
			
			if(_doOperation) {
				
				if(sTagName.equalsIgnoreCase("Operation")) {
					String[] operation = _operation.toString().split("\\|");
					
					if(operation.length == 2) {
						
						if(operation[0].equalsIgnoreCase("GetCapabilities")) {
							_capabilities.setGetCapabilitiesURL(operation[1]);
						
						} else if(operation[0].equalsIgnoreCase("DescribeCoverage")) {
							_capabilities.setDescribeCoverageURL(operation[1]);
						
						} else if(operation[0].equalsIgnoreCase("GetCoverage")) {
							_capabilities.setGetCoverageURL(operation[1]);
						}
					}
					
					_doOperation = false;
					
				} else if(_doFormat) {
					
					if(sTagName.equalsIgnoreCase("Value")) {
						_capabilities.addSupportedImageFormat(_characters.toString());
						
					} else if(sTagName.equalsIgnoreCase("Parameter")) {
						_doFormat = false;
					}
				}
					
			
			} else if(sTagName.equalsIgnoreCase("OperationsMetadata")) {
				_doOperationsMetadata = false;
			}
		
		} else if(_doContents) {
			
			if(_doCoverageSummary) {
				
				if(sTagName.equalsIgnoreCase("Title")) {
					_coverageInfo.setLabel(Val.escapeXmlForBrowser(_characters.toString()));
				
				} else if(sTagName.equalsIgnoreCase(Val.escapeXmlForBrowser("Abstract"))) {
					_coverageInfo.setDescription(_characters.toString());
				
				} else if(sTagName.equalsIgnoreCase("Identifier")) {
					_coverageInfo.setId(_characters.toString());
				
				} else if(sTagName.equalsIgnoreCase("CoverageSummary")) {
					_capabilities.getCoverageInfos().put(_coverageInfo.getName(), _coverageInfo);
					_coverageInfo = null;
					_doCoverageSummary = false;
				
				} else if(_lonLatEnvelope != null) {
					
					if(sTagName.equalsIgnoreCase("LowerCorner")) {				
						String[] coords = _characters.toString().split(" ");
						if(coords.length == 2) {
							_lonLatEnvelope.setMinX(Val.chkDbl(coords[0], Double.NaN));
							_lonLatEnvelope.setMinY(Val.chkDbl(coords[1], Double.NaN));
						}
					
					} else if(sTagName.equalsIgnoreCase("UpperCorner")) {
						String[] coords = _characters.toString().split(" ");
						if(coords.length == 2) {
							_lonLatEnvelope.setMaxX(Val.chkDbl(coords[0], Double.NaN));
							_lonLatEnvelope.setMaxY(Val.chkDbl(coords[1], Double.NaN));
						}
					} else if(sTagName.equalsIgnoreCase("WGS84BoundingBox")) {
						_coverageInfo.setLonLatEnvelope(_lonLatEnvelope);
						_lonLatEnvelope = null;
					}
				}
				
			}  else if(sTagName.equalsIgnoreCase("SupportedCRS")) {
				_capabilities.addSupportedProjection(_characters.toString());
				
			} else if(sTagName.equalsIgnoreCase("SupportedFormat")) {
				_capabilities.addSupportedImageFormat(_characters.toString());
			
			} else if(sTagName.equalsIgnoreCase("Contents")) {
				_doContents = false;
			}	
		}
	}
}

⌨️ 快捷键说明

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