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

📄 webresultsutil.java

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.log4j.Logger;

import com.esri.adf.web.data.query.QueryResult;
import com.esri.adf.web.data.results.ResultNode;
import com.esri.adf.web.data.results.WebResults;

public class WebResultsUtil {

	private static final Logger logger = Logger.getLogger( WebResultsUtil.class);
	
	private WebResultsUtil() {
	}
	
	@SuppressWarnings("unchecked")
	public static void toggleHighlightResultNode( ResultNode resultNode, boolean highlight ) {
		if( resultNode != null ) {
			// check the children as well
			List children = resultNode.getChildren();
			if( children != null && children.size() > 0 ) {
				for( Object childrenObj : children ) {
					if( childrenObj != null && childrenObj instanceof ResultNode ) {
						// call recursively to toggle highlight of children
						toggleHighlightResultNode( (ResultNode) childrenObj, highlight );
					}
				}
			}
			// check the root level ResultNode
			Object result = resultNode.getResult();
		    if( result != null && result instanceof QueryResult ) {
		    	// cast the results into a QueryResult and call highlight
		    	QueryResult queryResult = (QueryResult) result;
		    	if( highlight ) {
		    	    queryResult.highlight();
		    	} else {
		    		queryResult.clearGraphic();
		    	}
		    }
		}
	}
	
	@SuppressWarnings("unchecked")
	public static ResultNode getLatestResultNode( final WebResults webResults ) {
		// check the web results
		if( webResults == null ) {
			return null;
		}
		// check the result node list
		List topLevelResults = webResults.getResultNodes();
		if( ! isResultNodeListValid( topLevelResults ) ) {
			return null;
		}
		// grab the last result
		ResultNode resultNode = 
			(ResultNode) topLevelResults.get( topLevelResults.size() -1 ) ;
		return resultNode;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isResultNodeListValid( List topLevelResults ) {
		if( topLevelResults == null || topLevelResults.size() == 0 ) {
			logger.debug( "There is no current selection." );
			// add the result node
			return false;
		}
		List latestResults = ( (ResultNode) topLevelResults.get( topLevelResults.size() -1 ) ).getChildren();
		if (latestResults == null || latestResults.size()==0) {
			logger.debug( "Current selection contains nothing." );
			return false;
		}
		return true;
	}
	
	@SuppressWarnings("unchecked")
    public static QueryResult getFirstQueryResult( ResultNode resultNode ) {
		
		if( resultNode != null ) {
		    // check the children to see if the QueryResult exist first
			List children = resultNode.getChildren();
			if( children != null && children.size() > 0 ){
				ResultNode child = (ResultNode) children.get( 0 );
				if( child != null ) {
					Object childResult = child.getResult();
					if( childResult != null && childResult instanceof QueryResult ) {
						return (QueryResult) childResult;
					}
				}
			}
			// if no QueryResult has been found then check the root level ResultNode
			Object result = resultNode.getResult();
		    if( result != null && result instanceof QueryResult ) {
		    	return (QueryResult) result;
		    }
		}
		return null;
	}
    
	@SuppressWarnings("unchecked")
    public static List<QueryResult> getQueryResults( ResultNode resultNode ) {
		List<QueryResult> queryResults = new ArrayList<QueryResult>();
		if( resultNode != null ) {
		    // check the children to see if the QueryResult exist first
			List children = resultNode.getChildren();
			if( children != null && children.size() > 0 ){
				// iterate through the children
				for( Object childObject : children ) {
					ResultNode child = (ResultNode) childObject;
					if( child != null ) {
						Object childResult = child.getResult();
						if( childResult != null && childResult instanceof QueryResult ) {
							queryResults.add( (QueryResult) childResult );
						}
					}
				}
			}
		}
		return queryResults;
	}
	
	public static void printResultNode( ResultNode resultNode ) {
		if( resultNode != null ) {
			logger.debug( "ResultNode[" + resultNode.getDisplayName() + "] - "  + resultNode.getClass() );
			
			Object queryResultObj = resultNode.getResult();
			if( queryResultObj != null ) {
				if( queryResultObj instanceof QueryResult ) {
					QueryResult queryResult = (QueryResult) queryResultObj;
					
					logger.debug( "QueryResult[" + queryResult.getName() + "] - " + queryResult.getClass() );
					Map queryDetails = queryResult.getDetails();
					if( queryDetails != null && queryDetails.size() > 0 ) {
						printMap( "QueryDetails", queryDetails );
					} else {
						logger.debug( "QueryResults Details is null!" );
					}
				} else if( queryResultObj instanceof String ){
					logger.debug( "QueryResult[" + queryResultObj + "] - " + queryResultObj.getClass() );
				} else {
					logger.debug( "Found a QueryResult[" + queryResultObj + "] but type is unknown: " + queryResultObj.getClass() );
				}
				
			} else {
				logger.debug( "QueryResult is null!" );
			}
			
			if( resultNode.isHasDetails() ) {
				logger.debug( "ResultNode has details." );
				Map resultDetails = resultNode.getDetails();
				printMap( "ResultDetails", resultDetails );
			} else {
				logger.debug( "ResultNode doesnt have any details." );
			}
			
			List children = resultNode.getChildren();
			if( children != null && children.size() > 0 ) {
			    for( Object objNode : children ) {
			    	if( objNode != null && objNode instanceof ResultNode ) {
			    		printResultNode( (ResultNode) objNode );
			    	}
			    }
			} else {
				logger.debug( "ResultNode has no Children." ); 
			}
			
		} else {
			logger.debug( "ResultNode is null cannot print it." );
		}
	}
	
	@SuppressWarnings("unchecked")
	public static void printMap( final String name, Map map ) {
		logger.debug( "Printing Map[" + name + "] : " );
		if( map != null ) {
			Set keys = map.keySet();
			Iterator keysItr = keys.iterator();
			while( keysItr.hasNext() ) {
				String key = (String) keysItr.next();
				logger.debug( name + "[" + key + "] = " + map.get(key) );
			}
		}
	}
}

⌨️ 快捷键说明

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