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

📄 basicxmlwriter.java

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

import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebContextInitialize;
import com.esri.adf.web.data.geometry.WebSpatialReference;

/**
 * @author vlad2928
 *
 */
public class BasicXMLWriter implements WebContextInitialize {

	protected WebContext webContext;
	protected final String nl = "\n";
	
	public BasicXMLWriter(WebContext webContext) { init(webContext); }
	public void init(WebContext webContext) { if(webContext != null) setContext(webContext); }
	public void setContext(WebContext webContext) { this.webContext = webContext; }
	public void destroy() { this.webContext = null; }
	public boolean isInitialized() { return (webContext != null); }
	
	// Inner helper class to generate xml tags
	protected class Tag {
		
		private String _name;
		private String[][] _atts;
		private String _value;
		private boolean _hasChild = false;
		
		protected Tag(String name, String[][] atts, String value, boolean hasChild) {
			this._name = name;
			this._atts = atts;
			this._value = value;
			this._hasChild = hasChild;
		}
		
		private boolean isValid() {
			return (chkStr(this._name, null) != null);
		}
		
		protected StringBuffer open() {
			StringBuffer buf = new StringBuffer();
			
			if(isValid()) {
				// Open tag
				buf.append("<").append(_name);
			
				// Add tag attributes if any
				if(_atts != null)
				for(int i=0; i < _atts.length; i++) {
					buf.append(" ").append(_atts[i][0]).append("=\"").append(_atts[i][1]).append("\"");
				}
			
				// Add tag value if any
				if(_value != null && _value.length() > 0)
					buf.append(">").append(_value).append("</").append(_name).append(">");
				else
					buf.append(_hasChild ? ">" : "/>");
			}
			
			return buf.append(nl);
		}
		
		protected StringBuffer close() {
			StringBuffer buf = new StringBuffer();	
			if(isValid()) buf.append("</").append(_name).append(">");
			
			return buf.append(nl);
		}
	}
	
	protected StringBuffer valueTag(String tagName, String tagValue) {
		return (chkStr(tagValue, null) != null) ? new Tag(tagName, null, tagValue, false).open() : new StringBuffer();
	}
	
	protected StringBuffer attsTag(String tagName, String[][] atts) {
		return new Tag(tagName, atts, null, false).open();
	}
	
	protected StringBuffer attsValueTag(String tagName, String[][] atts, String tagValue) {
		return (chkStr(tagValue, null) != null) ? new Tag(tagName, atts, tagValue, true).open() : new StringBuffer();
	}
	
	protected String chkStr(String s, String defaultVal) {
		s = (s == null) ? "" : s.trim();
		return (s.length() == 0) ? defaultVal : s;
	}
	
	protected int getSRS(WebSpatialReference sr) {
		if(sr != null) {
			if(sr.getId() != -1) {
				return sr.getId();
			
			} else if(chkStr(sr.getDefinitionString(), null) != null) {
				return WebSpatialReference.getWebSpatialReferenceId(sr.getDefinitionString());
			}
		}
		
		return -1;
	}
}

⌨️ 快捷键说明

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