com\esri\arcgis\sample\upload\UploadBean.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package com.esri.arcgis.sample.upload; import com.esri.adf.web.data.GraphicElement; import com.esri.adf.web.data.WebContext; import com.esri.adf.web.data.WebGraphics; import com.esri.adf.web.data.geometry.WebPoint; import com.esri.adf.web.data.geometry.WebSpatialReference; import com.esri.adf.web.data.symbol.WebSimpleMarkerSymbol; import com.esri.adf.web.util.WebUtil; import java.io.BufferedReader; import java.io.StringReader; import java.util.Map; import java.util.Random; import java.util.StringTokenizer; /** * Bean to handle uploading of comma separated points file */ public class UploadBean { private String id; //upload id private String filename; //upload filename private WebContext webContext; public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getFilename() { return this.filename; } public void setFilename(String filename) { this.filename = filename; } public WebContext getWebContext() { return this.webContext; } public void setWebContext(WebContext webContext) { this.webContext = webContext; } /** * This method parses the points stored in the uploaded file and adds the points * to the web graphics. */ public void drawPoints() { try { //get data from session map Map sessionMap = WebUtil.getExternalContext().getSessionMap(); byte[] data = (byte[]) sessionMap.get(this.id); sessionMap.remove(this.id); //get spatial reference & web graphics for current web context WebSpatialReference sprf = webContext.getSpatialReference(); WebGraphics graphics = webContext.getWebGraphics(); //set symbology to use for all points WebSimpleMarkerSymbol markerSymbol = new WebSimpleMarkerSymbol(); markerSymbol.setAngle(0); Random rand = new Random(); String colorStr = (rand.nextInt(255)+1) + "," + (rand.nextInt(255)+1) + "," + (rand.nextInt(255)+1); markerSymbol.setColor(colorStr); markerSymbol.setMarkerType(WebSimpleMarkerSymbol.CIRCLE); markerSymbol.setOutlineColor("0,0,0"); markerSymbol.setTransparency(1.0); markerSymbol.setWidth(50); //parse uploaded file BufferedReader in = new BufferedReader(new StringReader(new String(data))); String line; while ((line = in.readLine()) != null) { StringTokenizer tokenizer = new StringTokenizer(line, ","); double x = Double.parseDouble(tokenizer.nextToken()); double y = Double.parseDouble(tokenizer.nextToken()); WebPoint point = new WebPoint(x, y, sprf); //add graphic elements to the web graphics GraphicElement element = new GraphicElement(); element.setSymbol(markerSymbol); element.setGeometry(point); graphics.addGraphics(element); } } catch (Exception e) { e.printStackTrace(); } } }