List of usage examples for java.util Vector addElement
public synchronized void addElement(E obj)
From source file:Main.java
public static Vector<String> extractList(Element elem, String name) { NodeList nl = elem.getElementsByTagName(name); Vector<String> values = new Vector<String>(nl.getLength()); String retval = null;// w w w.j a v a 2s . com for (int n = 0; n < nl.getLength(); n++) { Element element = (Element) nl.item(n); retval = getSimpleElementText(element); if (retval != null) values.addElement(retval); } return values; }
From source file:Main.java
/** * getStringListFromXPath// w w w . j av a 2s .com * Gets a list of strings from an xml. * @param rootNode The root node to perform the listExpression on. * @param listExpression Evaluated on the rootNode, gets a NodeList. * @return A list of the text contents of the nodes returned by evaluating the listExpression. */ public static List<String> getStringListFromXPath(Node rootNode, XPath xpath, String listExpression) { synchronized (xpath) { if (rootNode instanceof Document) rootNode = ((Document) rootNode).getDocumentElement(); Vector<String> result = new Vector<String>(); try { NodeList nodes = (NodeList) xpath.evaluate(listExpression, rootNode, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { result.addElement(nodes.item(i).getTextContent()); } } catch (Exception e) { System.err.println("Error evaluating xpath expression: " + listExpression); e.printStackTrace(); } return result; } }
From source file:Main.java
/** * Vector of child elements of an element *//*from w w w. ja v a 2s. com*/ public static Vector<Element> childElements(Element el) { Vector<Element> res = new Vector<Element>(); NodeList nodes = el.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node nd = nodes.item(i); if (nd instanceof Element) { Element eg = (Element) nd; res.addElement(eg); } } return res; }
From source file:Main.java
/** * Resolve a link relative to an absolute base. The path to resolve could * itself be absolute or relative.//from w w w . ja v a 2 s . com * * e.g. * resolvePath("http://www.server.com/some/dir", "../img.jpg"); * returns http://www.server.com/some/img.jpg * * @param base The absolute base path * @param link The link given relative to the base * @return */ public static String resolveLink(String base, String link) { String linkLower = link.toLowerCase(); int charFoundIndex; charFoundIndex = linkLower.indexOf("://"); if (charFoundIndex != -1) { boolean isAllChars = true; char cc; for (int i = 0; i < charFoundIndex; i++) { cc = linkLower.charAt(i); isAllChars &= ((cc > 'a' && cc < 'z') || (cc > '0' && cc < '9') || cc == '+' || cc == '.' || cc == '-'); } //we found :// and all valid scheme name characters before; path itself is absolute if (isAllChars) { return link; } } //Check if this is actually a data: link which should not be resolved if (link.startsWith("data:")) { return link; } if (link.length() > 2 && link.charAt(0) == '/' && link.charAt(1) == '/') { //we want the protocol only from the base String resolvedURL = base.substring(0, base.indexOf(':') + 1) + link; return resolvedURL; } if (link.length() > 1 && link.charAt(0) == '/') { //we should start from the end of the server int serverStartPos = base.indexOf("://") + 3; int serverFinishPos = base.indexOf('/', serverStartPos + 1); return base.substring(0, serverFinishPos) + link; } //get rid of query if it's present in the base path charFoundIndex = base.indexOf('?'); if (charFoundIndex != -1) { base = base.substring(0, charFoundIndex); } //remove the filename component if present in base path //if the base path ends with a /, remove that, because it will be joined to the path using a / charFoundIndex = base.lastIndexOf(FILE_SEP); base = base.substring(0, charFoundIndex); String[] baseParts = splitString(base, FILE_SEP); String[] linkParts = splitString(link, FILE_SEP); Vector resultVector = new Vector(); for (int i = 0; i < baseParts.length; i++) { resultVector.addElement(baseParts[i]); } for (int i = 0; i < linkParts.length; i++) { if (linkParts[i].equals(".")) { continue; } if (linkParts[i].equals("..")) { resultVector.removeElementAt(resultVector.size() - 1); } else { resultVector.addElement(linkParts[i]); } } StringBuffer resultSB = new StringBuffer(); int numElements = resultVector.size(); for (int i = 0; i < numElements; i++) { resultSB.append(resultVector.elementAt(i)); if (i < numElements - 1) { resultSB.append(FILE_SEP); } } return resultSB.toString(); }
From source file:Main.java
/** * Extracts attribute values from tag string. * /* w w w. ja v a2 s .c o m*/ * @param tag * whole tag name * @return A vector with all attribute values * @deprecated use TagClass.getAttrList() instead */ public static Vector getAttributeValues(String tag) { Vector values = new Vector(); int start = tag.indexOf('='); int end; while (start != -1) { start = tag.indexOf('"', start + 1); end = tag.indexOf('"', start + 1); if ((start == -1) || (end == -1)) { break; } values.addElement(tag.substring(start + 1, end).intern()); start = tag.indexOf('=', end + 1); } return values; }
From source file:Main.java
/** * J2ME implementation of String.split(). Is very fragile. * /* w w w . ja v a 2 s.c om*/ * @param string * @param separator * @return */ public static String[] stringSplit(String string, char separator) { Vector parts = new Vector(); int start = 0; for (int i = 0; i <= string.length(); i++) { if ((i == string.length()) || (string.charAt(i) == separator)) { if (start == i) { // no data between separators parts.addElement(""); } else { // data between separators String part = string.substring(start, i); parts.addElement(part); } // start of next part is the char after this separator start = i + 1; } } // return as array String[] partsArray = new String[parts.size()]; for (int i = 0; i < partsArray.length; i++) { partsArray[i] = (String) parts.elementAt(i); } return partsArray; }
From source file:Main.java
/** Returns all child <code>Node</code>s with the given name stored in a * <code>Vector</code>.//from w ww . ja v a 2s . c om * * @param node The parent node to be searched for * @param name The element name to search for * @return <code>Vector</code> of found </code>Node</code>s */ public static Vector getSubnodesByName(Node node, String name) { Vector retVal = null; NodeList nl = node.getChildNodes(); if (nl != null && nl.getLength() != 0) { for (int i = 0; i < nl.getLength(); i++) { if (nl.item(i).getNodeName().equals(name)) { if (retVal == null) retVal = new Vector(); retVal.addElement(nl.item(i)); } } } return retVal; }
From source file:Main.java
public static Collection or(Collection collection1, Collection collection2) { Vector completeList = new Vector(collection1); if (collection2 == null) return collection1; Iterator i = collection2.iterator(); // Do the long way tro make sure no dups while (i.hasNext()) { Object addlItem = i.next(); if (collection1.contains(addlItem) == false) { completeList.addElement(addlItem); }/* w w w . j a v a 2 s .co m*/ } return completeList; }
From source file:JRadioButtonSelectedElements.java
public static Enumeration<String> getSelectedElements(Container container) { Vector<String> selections = new Vector<String>(); Component components[] = container.getComponents(); for (int i = 0, n = components.length; i < n; i++) { if (components[i] instanceof AbstractButton) { AbstractButton button = (AbstractButton) components[i]; if (button.isSelected()) { selections.addElement(button.getText()); }// www .j a va2s.c om } } return selections.elements(); }
From source file:Main.java
/** * Add all elements from the map to the vector. * The map element is assumed to be an object or a {@link Vector}. * @param vec/* w w w . j a v a2s .co m*/ * @param map */ public static void addAllWithNestableValues(final Vector vec, final Hashtable map) { for (Enumeration e = map.elements(); e.hasMoreElements();) { final Object next = e.nextElement(); if (next instanceof Vector) { // values might be nested in another vector : addAll(vec, (Vector) next); } else { // simple value just add it : vec.addElement(next); } } }