List of usage examples for java.util Vector get
public synchronized E get(int index)
From source file:io.calq.android.analytics.ApiDispatcher.java
/** * Builds a payload based on the batch content. *//*from w w w.ja v a 2 s. co m*/ private StringEntity buildPayload(Vector<QueuedApiCall> batch) throws UnsupportedEncodingException { // Single item? if (batch.size() == 1) { return new StringEntity(batch.firstElement().getPayload(), "UTF-8"); } else { StringBuilder payload = new StringBuilder(); payload.append("["); for (int n = 0; n < batch.size(); n++) { if (n > 0) { payload.append(","); } QueuedApiCall apiCall = batch.get(n); payload.append(apiCall.getPayload()); } payload.append("]"); return new StringEntity(payload.toString(), "UTF-8"); } }
From source file:com.xmlcalabash.io.ReadableDocument.java
private void readDoc(StepContext stepContext) { runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > LOADING..."); c_init.close(stepContext.curChannel); if (uri == null) { documents.addChannel(stepContext.curChannel); runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > NOTHING"); } else {/*from ww w. ja va 2 s . co m*/ if (doc == null) { try { // What if this is a directory? String fn = uri; if (fn.startsWith("file:")) { fn = fn.substring(5); if (fn.startsWith("///")) { fn = fn.substring(2); } } File f = new File(fn); if (f.isDirectory()) { if (pattern == null) { pattern = Pattern.compile("^.*\\.xml$"); } for (File file : f.listFiles(new RegexFileFilter(pattern))) { doc = runtime.parse(file.getCanonicalPath(), base); documents.newPipedDocument(stepContext.curChannel, doc); } } else { doc = null; boolean json = false; try { doc = runtime.parse(uri, base); } catch (XProcException xe) { if (runtime.transparentJSON()) { try { URI baseURI = new URI(base); URL url = baseURI.resolve(uri).toURL(); URLConnection conn = url.openConnection(); InputStreamReader reader = new InputStreamReader(conn.getInputStream()); JSONTokener jt = new JSONTokener(reader); doc = JSONtoXML.convert(runtime.getProcessor(), jt, runtime.jsonFlavor()); documents.newPipedDocument(stepContext.curChannel, doc); json = true; } catch (Exception e) { throw xe; } } else { throw xe; } } if (!json) { if (fn.contains("#")) { int pos = fn.indexOf("#"); String ptr = fn.substring(pos + 1); if (ptr.matches("^[\\w]+$")) { ptr = "element(" + ptr + ")"; } XPointer xptr = new XPointer(ptr); Vector<XdmNode> nodes = xptr.selectNodes(runtime, doc); if (nodes.size() == 1) { doc = nodes.get(0); } else if (nodes.size() != 0) { throw new XProcException(node, "XPointer matches more than one node!?"); } } } } } catch (Exception except) { throw XProcException.dynamicError(11, node, except, "Could not read: " + uri); } } documents.newPipedDocument(stepContext.curChannel, doc); runtime.getTracer().debug(null, stepContext, -1, this, null, " DOCU > LOADED"); } // close documents documents.close(stepContext.curChannel); }
From source file:no.met.jtimeseries.netcdf.NetcdfChartProvider.java
public void getCsv(PrintStream out, Iterable<String> variables) throws ParseException, IOException { Vector<NumberPhenomenon> data = getWantedPhenomena(variables); // header//from w w w.j a v a2 s . c om out.print("# Time"); for (NumberPhenomenon p : data) out.print(",\t" + p.getPhenomenonName() + " (" + p.getPhenomenonUnit() + ")"); out.println(); TreeMap<Date, Double[]> displayData = new TreeMap<Date, Double[]>(); for (int i = 0; i < data.size(); i++) { for (NumberValueItem atom : data.get(i)) { Double[] d = displayData.get(atom.getTimeFrom()); if (d == null) { d = new Double[data.size()]; displayData.put(atom.getTimeFrom(), d); } d[i] = atom.getValue(); } } SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); for (Entry<Date, Double[]> element : displayData.entrySet()) { out.print(format.format(element.getKey())); Double[] d = element.getValue(); for (int i = 0; i < d.length; i++) out.print(",\t" + d[i]); out.println(); } }
From source file:de.nrw.hbz.regal.sync.Syncer.java
void pidl(String pidFile) { Vector<String> pids; pids = readPidlist(pidFile);//from w w w . ja v a 2 s . com int size = pids.size(); for (int i = 0; i < size; i++) { try { logger.info((i + 1) + " / " + size); String pid = pids.get(i); String baseDir = downloader.download(pid, false); if (!downloader.hasUpdated()) { DigitalEntity dtlBean = builder.build(baseDir, pids.get(i)); ingester.ingest(dtlBean); dtlBean = null; logger.info((i + 1) + "/" + size + " " + pid + " has been processed!\n"); } else if (downloader.hasUpdated()) { DigitalEntity dtlBean = builder.build(baseDir, pids.get(i)); ingester.ingest(dtlBean); dtlBean = null; logger.info((i + 1) + "/" + size + " " + pid + " has been updated!\n"); } } catch (Exception e) { logger.error(e.toString(), e); } } }
From source file:net.sf.ginp.commands.UploadConfig.java
/** * Handle admin request to upload an new configuration file. * * @param model Description of the Parameter * @param params Description of the Parameter *//*from w w w . ja v a 2s . co m*/ public final void action(final GinpModel model, final Vector params) { // Check we do not have a state of bad config. if (Configuration.configOK()) { return; } File confFile = new File(Configuration.getConfigfilelocation()); // check that file is not there. if (confFile.exists()) { log.error("Config File there but NOT OK. Fix it or remove it."); return; } for (int i = 0; i < params.size(); i++) { CommandParameter param = (CommandParameter) params.get(i); log.debug(param.getName() + " = " + param.getValue()); if (param.getName().equals("configfile")) { try { InputStream is = (InputStream) param.getObject(); InputStreamReader isr = new InputStreamReader(is); FileWriter fw = new FileWriter(confFile); int b = isr.read(); while (b != -1) { fw.write(b); b = isr.read(); } fw.flush(); } catch (Exception ex) { log.error("Error writing Config File from upload stream.", ex); } } } if (Configuration.configOK()) { log.info("Uploaded valid Config"); } model.setUserName("admin"); model.setCurrentPage("setup2.jsp"); }
From source file:eionet.gdem.qa.XQueryService.java
/** * Request from XML/RPC client Stores the source files and starts a job in the workqueue. * * @param files - Structure with XMLschemas as a keys and values are list of XML Files * @return Hashtable result: Structure with JOB ids as a keys and source files as values *///w w w . jav a2 s . co m public Vector analyzeXMLFiles(Hashtable files) throws GDEMException { Vector result = new Vector(); if (files == null) { return result; } Enumeration _schemas = files.keys(); while (_schemas.hasMoreElements()) { String _schema = _schemas.nextElement().toString(); Vector _files = (Vector) files.get(_schema); if (Utils.isNullVector(_files)) { continue; } for (int i = 0; i < _files.size(); i++) { String _file = (String) _files.get(i); analyzeXMLFiles(_schema, _file, result); } } return result; }
From source file:com.frameworkset.platform.cms.driver.htmlconverter.CmsHtmlTagRemoveFactory.java
/** * @see org.htmlparser.PrototypicalNodeFactory#createTagNode(org.htmlparser.lexer.Page, int, * int, java.util.Vector)//from w ww . ja v a 2s . c o m */ public Tag createTagNode(Page arg0, int arg1, int arg2, Vector arg3) { try { String tagName = ((Attribute) arg3.get(0)).getName().toLowerCase(); // end tags have names like "/a".... if (tagName.charAt(0) == '/') { tagName = tagName.substring(1); } Tag result = super.createTagNode(arg0, arg1, arg2, arg3); if (m_invisibleTags.contains(tagName)) { result = new CmsInvisibleTag(result); } return result; } catch (RuntimeException rte) { if (LOG.isErrorEnabled()) { // log here, as htmlparser 1.5 did swallow exceptions from here and threw NPEs from // other places LOG.error(rte); } throw rte; } }
From source file:com.xpn.xwiki.plugin.calendar.CalendarData.java
/** * List populating method. It iterates the CalendarEvent objects stored in the given document and creates Java * wrappers that can be used by the Calendar plugin. * // w ww .ja v a 2 s. c o m * @param doc The source document, populated with CalendarEvent objects. * @param defaultUser The username to be used ig objects do not have a User field. * @throws XWikiException */ public void addCalendarData(XWikiDocument doc, String defaultUser, XWikiContext context) throws XWikiException { if (doc == null) { return; } if (!context.getWiki().getRightService().hasAccessLevel("view", context.getUser(), doc.getFullName(), context)) { return; } if (defaultUser == null) { BaseObject bobj = doc.getObject("XWiki.XWikiUsers"); if (bobj == null) { defaultUser = doc.getCreator(); } else { defaultUser = doc.getFullName(); } } String defaultDescription = ""; String defaultURL = ""; defaultDescription = "[" + doc.getDisplayTitle(context) + ">" + doc.getFullName() + "]"; defaultURL = doc.getURL("view", context); Vector bobjs = doc.getObjects("XWiki.CalendarEvent"); if (bobjs != null) { for (int i = 0; i < bobjs.size(); ++i) { try { BaseObject bobj = (BaseObject) bobjs.get(i); String user = ""; try { user = (String) ((StringProperty) bobj.get("user")).getValue(); } catch (Exception e) { } String description = ""; try { description = (String) ((LargeStringProperty) bobj.get("description")).getValue(); } catch (Exception e) { } String title = ""; try { title = (String) ((StringProperty) bobj.get("title")).getValue(); } catch (Exception e) { } if (StringUtils.isBlank(title)) { title = doc.getDisplayTitle(context); } String url = ""; try { url = (String) ((StringProperty) bobj.get("url")).getValue(); } catch (Exception e) { } String location = ""; try { location = (String) ((StringProperty) bobj.get("location")).getValue(); } catch (Exception e) { } List category = null; try { category = (List) ((StringListProperty) bobj.get("category")).getValue(); } catch (Exception e) { } Date dateStart = null; try { dateStart = (Date) ((DateProperty) bobj.get("startDate")).getValue(); } catch (Exception e) { } Date dateEnd = null; try { dateEnd = (Date) ((DateProperty) bobj.get("endDate")).getValue(); } catch (Exception e) { } if ((user == null) || user.equals("")) { user = defaultUser; } if (dateStart == null) { dateStart = dateEnd; } if (dateEnd == null) { dateEnd = dateStart; } if ((dateStart == null) || (dateEnd == null)) { continue; } if (dateStart.getTime() > dateEnd.getTime()) { Date dateTemp = dateStart; dateStart = dateEnd; dateEnd = dateTemp; } if ((description == null) || description.equals("")) { description = defaultDescription; } if ((url == null) || url.equals("")) { url = defaultURL; } Calendar cdateStart = Calendar.getInstance(); cdateStart.setTime(dateStart); Calendar cdateEnd = Calendar.getInstance(); cdateEnd.setTime(dateEnd); addCalendarData(new CalendarEvent(cdateStart, cdateEnd, user, description, title, category, url, location)); } catch (Exception e) { // Let's continue in case of failure e.printStackTrace(); } } } }
From source file:com.bt.aloha.sipstone.GenGraph.java
public Map<String, List<Double>> readFile(String fileName) { File f = new File(fileName); HashMap<String, List<Double>> ret = new HashMap<String, List<Double>>(); try {//w w w.ja va 2 s . c om BufferedReader br = new BufferedReader(new FileReader(f)); String line; List<String> headers = null; Vector<String> lines = new Vector<String>(); while (null != (line = br.readLine())) { lines.add(line); } // last two lines are not needed lines.remove(1); lines.remove(1); lines.remove(lines.size() - 1); for (int row = 0; row < lines.size(); row++) { line = lines.get(row); System.out.println(line); if (row == 0) { headers = populateMapWithHeaders(ret, line); } else { populateMapWithData(ret, line, headers); } } } catch (FileNotFoundException e) { throw new IllegalArgumentException("Unable to open " + fileName); } catch (IOException e) { throw new IllegalArgumentException("Unable to read " + fileName); } return ret; }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
/****************************************************************************************** * Generates information to send to the server * Server looks for name-value pairs to retrieve data ****************************************************************************************** * @param tripId Unique ID for each trip sent. Unique to ALL RIDERS * @return Returns the data the server reads and stores * @throws JSONException/*from w w w .j a v a 2 s . c o m*/ ******************************************************************************************/ private String getPostData(long tripId) throws JSONException { JSONObject coords = getCoordsJSON(tripId); JSONObject user = getUserJSON(); String deviceId = getDeviceId(); Vector<String> tripData = getTripData(tripId); String notes = tripData.get(0); String purpose = tripData.get(1); String startTime = tripData.get(2); // String endTime = tripData.get(3); Log.d("KENNY", "USER AGREEMENT: " + agreement); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("coords", coords.toString())); nameValuePairs.add(new BasicNameValuePair("user", user.toString())); nameValuePairs.add(new BasicNameValuePair("device", deviceId)); nameValuePairs.add(new BasicNameValuePair("notes", notes)); nameValuePairs.add(new BasicNameValuePair("purpose", purpose)); nameValuePairs.add(new BasicNameValuePair("start", startTime)); // nameValuePairs.add(new BasicNameValuePair("end", endTime)); nameValuePairs.add(new BasicNameValuePair("version", "" + kSaveProtocolVersion)); double distDouble = Double.parseDouble(distance); String codedPostData = "purpose=" + purpose + "&user=" + user.toString() + "¬es=" + notes + "&coords=" + coords.toString() + "&version=" + String.valueOf(kSaveProtocolVersion) + "&start=" + startTime + "&device=" + deviceId + "&distance=" + distance + "&cotwo=" + co2 + "&kcal=" + kcal + "&avgcost=" + avgCost + "&score=" + (distDouble * 10); return codedPostData; }