List of usage examples for java.util Vector addElement
public synchronized void addElement(E obj)
From source file:org.anonymous.dobroreaderme.networking.dobrochan.DobrochanApi.java
protected BoardPost parsePost(JSONObject post) throws JSONException { Vector attachmentsVector = new Vector(5); JSONArray attachments = post.getJSONArray("files"); for (int i = 0; i < attachments.length(); i++) { JSONObject file = attachments.getJSONObject(i); if (file.getString("type").equals("image")) { attachmentsVector.addElement(new BoardImage(file.getString("src"), file.getInt("file_id"), file.getInt("size"), file.getString("thumb"), 0, 0, file.getInt("thumb_height"))); } else {//from w w w. j a v a 2 s. c o m attachmentsVector.addElement( new BoardAttachment(file.getString("type"), file.getString("src"), file.getInt("file_id"), file.getInt("size"), file.getString("thumb"), file.getInt("thumb_height"))); } } return new BoardPost(post.getInt("display_id"), post.getString("message"), post.getString("date"), post.getString("subject"), post.getString("name"), attachmentsVector); }
From source file:org.apache.cactus.WebResponse.java
/** * @return the text of the response (excluding headers) as an array of * strings (each string is a separate line from the output stream). *//*from w w w.j a va 2 s.c o m*/ public String[] getTextAsArray() { Vector lines = new Vector(); try { // Read content first if (this.content == null) { getText(); } BufferedReader input = new BufferedReader(new StringReader(this.content)); String str; while (null != (str = input.readLine())) { lines.addElement(str); } input.close(); } catch (IOException e) { throw new ChainedRuntimeException(e); } // Dummy variable to explicitely tell the object type to copy. String[] dummy = new String[lines.size()]; return (String[]) (lines.toArray(dummy)); }
From source file:com.thoughtworks.cruise.util.command.CommandLine.java
public static String[] translateCommandLine(String toProcess) throws CommandLineException { if (toProcess == null || toProcess.length() == 0) { return new String[0]; }//from w ww . ja v a 2 s . co m // parse with a simple finite state machine final int normal = 0; final int inQuote = 1; final int inDoubleQuote = 2; int state = normal; StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true); Vector v = new Vector(); StringBuffer current = new StringBuffer(); while (tok.hasMoreTokens()) { String nextTok = tok.nextToken(); switch (state) { case inQuote: if ("\'".equals(nextTok)) { state = normal; } else { current.append(nextTok); } break; case inDoubleQuote: if ("\"".equals(nextTok)) { state = normal; } else { current.append(nextTok); } break; default: if ("\'".equals(nextTok)) { state = inQuote; } else if ("\"".equals(nextTok)) { state = inDoubleQuote; } else if (" ".equals(nextTok)) { if (current.length() != 0) { v.addElement(current.toString()); current.setLength(0); } } else { current.append(nextTok); } break; } } if (current.length() != 0) { v.addElement(current.toString()); } if (state == inQuote || state == inDoubleQuote) { throw new CommandLineException("unbalanced quotes in " + toProcess); } String[] args = new String[v.size()]; v.copyInto(args); return args; }
From source file:com.jaspersoft.ireport.designer.data.fieldsproviders.BeanInspectorPanel.java
@SuppressWarnings("unchecked") private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed DefaultTableModel dtm = (DefaultTableModel) getJTableFields().getModel(); TreePath[] paths = jTree1.getSelectionPaths(); if (paths == null) return;/*from w w w . j a va 2s . c om*/ for (int i = 0; i < paths.length; ++i) { boolean valid = true; TreePath tp = paths[i]; TreeJRField tjrf = (TreeJRField) ((DefaultMutableTreeNode) tp.getLastPathComponent()).getUserObject(); String returnType = Misc.getJRFieldType(tjrf.getObj().getName()); JRDesignField field = new JRDesignField(); field.setName(tjrf.getField().getName()); field.setValueClassName(returnType); field.setDescription(tjrf.getField().getDescription()); Vector row = new Vector(); row.addElement(field); row.addElement(field.getValueClassName()); row.addElement(field.getDescription()); if (isComboVisible() && jComboBox1.getSelectedItem() instanceof FieldClassWrapper) { FieldClassWrapper cw = (FieldClassWrapper) jComboBox1.getSelectedItem(); field.setName(cw.getFieldName() + "." + field.getDescription()); field.setDescription(field.getName()); } // Check for duplicates fields... boolean found = fieldAlreadyExists(field); String baseName = field.getName(); for (int j = 1; isPathOnDescription() && found; ++j) { field.setName(baseName + "_" + j); found = fieldAlreadyExists(field); } if (!found) { dtm.addRow(row); getJTableFields().getSelectionModel().addSelectionInterval(getJTableFields().getRowCount() - 1, getJTableFields().getRowCount() - 1); } } }
From source file:edu.umd.cfar.lamp.viper.util.StringHelp.java
/** * Split using a separator, but allow for the separator to occur * in nested parentheses without splitting. * <PRE>//w w w. j a v a 2 s. c om * E.g. "1", 2*("2,3"), "4" * would split into * -- "1" * -- 2*("2,3") * -- "4" * </PRE> * If the data has an odd number of "s, it will append a " character * to the end. In order to include a quote character without delimiting * a string, use the \". For a \, use \\. * @param line the string to split * @param sep the seperator character, e.g. a comma * @return the split string */ public static String[] splitBySeparatorQuoteAndParen(String line, char sep) { boolean withinQuotes = false; String newLine = new String(line); Vector temp = new Vector(); StringBuffer nextString = new StringBuffer(); int nesting = 0; for (int i = 0; i < newLine.length(); i++) { char c = newLine.charAt(i); if (c == '\\') { if ((++i >= newLine.length()) && (nextString.length() > 0)) { temp.addElement(nextString.toString()); break; } else { switch (newLine.charAt(i)) { case 'n': nextString.append('\n'); break; case '"': nextString.append('"'); break; default: nextString.append(newLine.charAt(i)); } } } else if (c == '"') { withinQuotes = !withinQuotes; nextString.append('"'); } else if (!withinQuotes) { if (c == '(') { nesting++; nextString.append('('); } else if (c == ')') { nesting--; nextString.append(')'); } else { if ((nesting == 0) && (c == sep)) { temp.addElement(nextString.toString()); nextString.delete(0, nextString.length()); } else { nextString.append(newLine.charAt(i)); } } } else { nextString.append(newLine.charAt(i)); } } if (withinQuotes) { nextString.append('"'); } temp.addElement(nextString.toString()); String[] result = new String[temp.size()]; for (int i = 0; i < result.length; i++) { result[i] = (String) temp.elementAt(i); } return (result); }
From source file:org.apache.jmeter.util.JMeterUtils.java
/** * Creates a vector of strings for all the properties that start with a * common prefix.// w ww .j a v a 2s . co m * * @param properties * Description of Parameter * @param name * Description of Parameter * @return The Vector value */ public static Vector<String> getVector(Properties properties, String name) { Vector<String> v = new Vector<>(); Enumeration<?> names = properties.keys(); while (names.hasMoreElements()) { String prop = (String) names.nextElement(); if (prop.startsWith(name)) { v.addElement(properties.getProperty(prop)); } } return v; }
From source file:com.netscape.cms.publish.publishers.FileBasedPublisher.java
/** * Returns the initial default parameters. *//*w ww . ja v a2s . c o m*/ public Vector<String> getDefaultParams() { Vector<String> v = new Vector<String>(); v.addElement(PROP_DIR + "="); v.addElement(PROP_DER + "=true"); v.addElement(PROP_B64 + "=false"); v.addElement(PROP_GMT + "=LocalTime"); v.addElement(PROP_LNK + "=false"); v.addElement(PROP_EXT + "="); v.addElement(PROP_ZIP + "=false"); v.addElement(PROP_LEV + "=9"); v.addElement(PROP_MAX_FULL_CRLS + "=0"); v.addElement(PROP_MAX_AGE + "=0"); return v; }
From source file:edu.indiana.lib.osid.base.repository.http.Asset.java
public org.osid.repository.RecordIterator getRecordsByRecordStructureType( org.osid.shared.Type recordStructureType) throws org.osid.repository.RepositoryException { if (recordStructureType == null) { throw new org.osid.repository.RepositoryException(org.osid.shared.SharedException.NULL_ARGUMENT); }//from w ww .j a v a 2 s . com if ((!recordStructureType.isEqual(this.recordStructureType)) && (!recordStructureType.isEqual(this.dcRecordStructureType)) && (!recordStructureType.isEqual(this.vueRecordStructureType))) { throw new org.osid.repository.RepositoryException(org.osid.shared.SharedException.UNKNOWN_TYPE); } java.util.Vector results = new java.util.Vector(); for (int i = 0, size = this.recordVector.size(); i < size; i++) { org.osid.repository.Record r = (org.osid.repository.Record) this.recordVector.elementAt(i); if (r.getRecordStructure().getType().isEqual(recordStructureType)) { results.addElement(r); } } return new RecordIterator(results); }
From source file:net.wastl.webmail.server.WebMailServer.java
public Provider[] getStoreProviders() { Vector<Provider> v = new Vector<Provider>(); for (int i = 0; i < store_providers.length; i++) { if (storage.getConfig("ENABLE " + store_providers[i].getProtocol().toUpperCase()).equals("YES")) { v.addElement(store_providers[i]); }// w w w .ja v a 2 s.com } Provider[] retval = new Provider[v.size()]; v.copyInto(retval); return retval; }
From source file:com.openmeap.json.JSONObjectBuilder.java
public Object fromJSON(JSONObject jsonObj, Object rootObject) throws JSONException { if (jsonObj == null) { return null; }//from w w w. ja v a 2 s. c o m if (!HasJSONProperties.class.isAssignableFrom(rootObject.getClass())) { throw new RuntimeException( "The rootObject being converted to JSON must implement the HashJSONProperties interface."); } JSONProperty[] properties = ((HasJSONProperties) rootObject).getJSONProperties(); for (int jsonPropertyIdx = 0; jsonPropertyIdx < properties.length; jsonPropertyIdx++) { JSONProperty property = properties[jsonPropertyIdx]; Class returnType = property.getReturnType(); String propertyName = property.getPropertyName(); try { // get the unparsed value from the JSONObject Object value = null; try { value = jsonObj.get(propertyName); } catch (JSONException e) { continue; } if (value == JSONObject.NULL) { continue; } if (Enum.class.isAssignableFrom(returnType)) { property.getGetterSetter().setValue(rootObject, value); } else if (value instanceof JSONArray) { JSONArray array = (JSONArray) value; Vector list = new Vector(); for (int i = 0; i < array.length(); i++) { Object obj = array.get(i); if (obj instanceof JSONObject) { Object newObj = (Object) returnType.newInstance(); list.addElement(fromJSON((JSONObject) obj, newObj)); } else { list.addElement(obj); } } if (property.getContainedType() != null) { property.getGetterSetter().setValue(rootObject, list); } else { property.getGetterSetter().setValue(rootObject, toTypedArray(list)); } } else if (value instanceof JSONObject) { Object obj = (Object) returnType.newInstance(); if (Hashtable.class.isAssignableFrom(returnType)) { Hashtable table = (Hashtable) obj; JSONObject jsonMap = (JSONObject) value; Enumeration keysEnum = jsonMap.keys(); while (keysEnum.hasMoreElements()) { String key = (String) keysEnum.nextElement(); Object thisValue = jsonMap.get(key); if (thisValue instanceof JSONObject) { Object newObj = (Object) returnType.newInstance(); table.put(key, fromJSON((JSONObject) thisValue, newObj)); } else { table.put(key, thisValue); } } property.getGetterSetter().setValue(rootObject, table); } else { // of the type correct for the property.getGetterSetter().setValue(rootObject, fromJSON((JSONObject) value, obj)); } } else if (isSimpleType(returnType)) { property.getGetterSetter().setValue(rootObject, correctCasting(returnType, value)); } } catch (Exception e) { throw new JSONException(e); } } return rootObject; }