List of usage examples for java.util Vector elements
public Enumeration<E> elements()
From source file:org.openxdata.designer.server.util.XmlUtil.java
/** * Gets the text or attribute value of an xpath expression from an xforms instance data node. * //ww w.jav a 2s. c o m * @param dataNode the instance data node. * @param xpath the xpath expression. * @return the text or attribute value. */ private static String getValue(Element dataNode, String xpath) { int pos = xpath.lastIndexOf('@'); String attributeName = null; if (pos > 0) { attributeName = xpath.substring(pos + 1, xpath.length()); xpath = xpath.substring(0, pos - 1); } XPathExpression xpls = new XPathExpression(dataNode, xpath); Vector<?> result = xpls.getResult(); for (Enumeration<?> e = result.elements(); e.hasMoreElements();) { Object obj = e.nextElement(); if (obj instanceof Element) { if (pos > 0) //Check if we are to set attribute value. return ((Element) obj).getAttribute(attributeName); else return ((Element) obj).getTextContent(); } } return null; }
From source file:Stats.java
/** * Converts a vector of Numbers into an array of double. This function does * not necessarily belong here, but is commonly required in order to apply * the statistical functions conveniently, since they only deal with arrays * of double. (Note that a Number of the common superclass of all the Object * versions of the primitives, such as Integer, Double etc.). *//* w w w . j a v a2s.c om*/ // package that at present just provides average and sd of a // vector of doubles // also enables writing the // Gnuplot comments begin with # // next need to find out how to select a particular line style // found it : // This plots sin(x) and cos(x) with linespoints, using the same line type // but different point types: // plot sin(x) with linesp lt 1 pt 3, cos(x) with linesp lt 1 pt 4 public static double[] v2a(Vector v) { double[] d = new double[v.size()]; int i = 0; for (Enumeration e = v.elements(); e.hasMoreElements();) d[i++] = ((Number) e.nextElement()).doubleValue(); return d; }
From source file:Main.java
/** * Searches parent node for matching child nodes and collects and returns * their matching attribute String values. * * @param node The parent node/*from w ww . ja v a2s. c om*/ * @param elemName The matching child node element name * @param attr The matching child node attribute name * @return List of attribute values */ public static Enumeration getChildrenAttributeValues(Node node, String elemName, String attr) { Vector vect = new Vector(); NodeList nl = node.getChildNodes(); int n = nl.getLength(); for (int i = 0; i < n; i++) { Node nd = nl.item(i); if (nd.getNodeName().equals(elemName)) { vect.add(getAttribute(nd, attr)); } } return vect.elements(); }
From source file:com.maverick.http.MultiStatusResponse.java
public static MultiStatusResponse[] createResponse(HttpResponse response) throws IOException { if (response.getStatus() != 207) { throw new IOException(Messages.getString("MultiStatusResponse.not207")); //$NON-NLS-1$ }//from ww w . java 2s. com ByteArrayOutputStream out = new ByteArrayOutputStream(); int read; byte[] buf = new byte[4096]; while ((read = response.getInputStream().read(buf)) > -1) { out.write(buf, 0, read); } // #ifdef DEBUG if (log.isDebugEnabled()) log.debug(new String(out.toByteArray())); // #endif try { IXMLParser parser = XMLParserFactory.createDefaultXMLParser(); IXMLReader reader = StdXMLReader.stringReader(new String(out.toByteArray(), "UTF8")); //$NON-NLS-1$ parser.setReader(reader); IXMLElement rootElement = (IXMLElement) parser.parse(); if (!rootElement.getName().equalsIgnoreCase("multistatus")) //$NON-NLS-1$ throw new IOException( Messages.getString("MultiStatusResponse.invalidDavRootElement") + rootElement.getName()); //$NON-NLS-1$ // Now process the responses Vector children = rootElement.getChildrenNamed("response", rootElement.getNamespace()); //$NON-NLS-1$ Vector responses = new Vector(); for (Enumeration e = children.elements(); e.hasMoreElements();) { responses.addElement(new MultiStatusResponse((IXMLElement) e.nextElement())); } MultiStatusResponse[] array = new MultiStatusResponse[responses.size()]; responses.copyInto(array); return array; } catch (Exception ex) { // #ifdef DEBUG log.error(Messages.getString("MultiStatusResponse.failedToProcessMultistatusResponse"), ex); //$NON-NLS-1$ // #endif throw new IOException(ex.getMessage()); } }
From source file:com.ibm.soatf.tool.ValidateTransferedValues.java
public static boolean validateValuesFromFile(File sqlScriptFile, File messageFile, Map<String, String> mappings) throws FileNotFoundException, ParseException, java.text.ParseException { if (sqlScriptFile == null || messageFile == null || !sqlScriptFile.exists() || !messageFile.exists()) { throw new FileNotFoundException(); }/*from ww w . jav a 2 s . com*/ ZqlParser zqlParser = new ZqlParser(); zqlParser.addCustomFunction("TO_DATE", 2); zqlParser.initParser(new FileInputStream(sqlScriptFile)); ZStatement zs = zqlParser.readStatement(); System.out.println("Input statement: " + zs.toString()); boolean valid = true; if (zs instanceof ZQuery) { System.out.println("Je to select statement"); } else if (zs instanceof ZInsert) { System.out.println("Je to insert statement"); ZInsert zi = (ZInsert) zs; int i = 0; Vector columns = zi.getColumns(); Vector values = zi.getValues(); Enumeration colEnum = columns.elements(); Enumeration valEnum = values.elements(); String dbColumnName = null; String dbValue = null; String messageElementName = null; String messageValue = null; Pattern pattern = Pattern.compile("'([^']+)'"); while (colEnum.hasMoreElements()) { boolean dateCompare = false; dbColumnName = colEnum.nextElement().toString(); if (mappings != null && mappings.containsKey(dbColumnName)) { messageElementName = mappings.get(dbColumnName); if (messageElementName == null || "".equals(messageElementName)) { //null v toColumnName - neporovnavam logger.debug("Skipping column " + dbColumnName); valEnum.nextElement(); continue; } } else { messageElementName = constructXMLElementNameFromDBColumn(dbColumnName); } dbValue = valEnum.nextElement().toString(); if (dbValue != null && dbValue.startsWith("TO_DATE")) dateCompare = true; Matcher matcher = pattern.matcher(dbValue); if (matcher.find()) { dbValue = matcher.group(1); } logger.debug("Comparing values for column " + dbColumnName + " and coresponding element " + messageElementName); messageValue = getElementFromFile(messageElementName, messageFile, false); boolean differ = false; if (dateCompare) { final Date dbDate = DatabaseComponent.DATE_FORMAT.parse(dbValue); //TODO: timezone //Date xmlDate = DatatypeConverter.parseDate(messageValue).getTime(); Date xmlDate = (messageValue == null || messageValue.length() < 19) ? null : JmsComponent.DATE_FORMAT.parse(messageValue.substring(0, 19)); differ ^= dbDate.equals(xmlDate); } else { if (dbValue == null) { if (messageValue != null) { differ = true; } else { differ = false; } } else { differ = !dbValue.equals(messageValue); } } if (differ) { logger.debug("values are different: " + dbValue + " <> " + messageValue); valid = false; } else { logger.debug("values are equal"); } } } return valid; }
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 av a 2 s.c om*/ } } return selections.elements(); }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
/** * //from w ww . j a v a 2 s. c o m * @param policyOIDs * @param values * @return */ static protected CertificateExtension createCertificatePoliciesExtension(Vector policyOIDs, String values) { ASN1EncodableVector policyInformations = new ASN1EncodableVector(); Enumeration pOids = policyOIDs.elements(); while (pOids.hasMoreElements()) { String policyOid = (String) pOids.nextElement(); DERObjectIdentifier policyIdentifier = new DERObjectIdentifier(policyOid); PolicyInformation policyInformation = new PolicyInformation(policyIdentifier); policyInformations.add(policyInformation); } DERSequence certificatePolicies = new DERSequence(policyInformations); X509Extension certificatePoliciesExtension = new X509Extension(false, new DEROctetString(certificatePolicies)); return new CertificateExtension(X509Extensions.CertificatePolicies, "CertificatePolicies", certificatePoliciesExtension, values); }
From source file:org.aselect.server.utils.Utils.java
/** * Serialize attributes contained in a HashMap. <br> * <br>/*from ww w . ja va 2 s . co m*/ * <b>Description:</b> <br> * This method serializes attributes contained in a HashMap: * <ul> * <li>They are formatted as attr1=value1&attr2=value2;... * <li>If a "&" or a "=" appears in either the attribute name or value, they are transformed to %26 or %3d * respectively. * <li>The end result is base64 encoded. * </ul> * <br> * * @param htAttributes - HashMap containing all attributes * @return Serialized representation of the attributes * @throws ASelectException - If serialization fails. */ public static String serializeAttributes(HashMap htAttributes) throws ASelectException { final String sMethod = "serializeAttributes"; try { if (htAttributes == null || htAttributes.isEmpty()) return null; StringBuffer sb = new StringBuffer(); Set keys = htAttributes.keySet(); for (Object s : keys) { String sKey = (String) s; // for (Enumeration e = htAttributes.keys(); e.hasMoreElements(); ) { // String sKey = (String)e.nextElement(); Object oValue = htAttributes.get(sKey); if (oValue instanceof Vector) {// it's a multivalue attribute Vector vValue = (Vector) oValue; sKey = URLEncoder.encode(sKey + "[]", "UTF-8"); Enumeration eEnum = vValue.elements(); while (eEnum.hasMoreElements()) { String sValue = (String) eEnum.nextElement(); // add: key[]=value sb.append(sKey).append("=").append(URLEncoder.encode(sValue, "UTF-8")); if (eEnum.hasMoreElements()) sb.append("&"); } } else if (oValue instanceof String) {// it's a single value attribute String sValue = (String) oValue; sb.append(URLEncoder.encode(sKey, "UTF-8")).append("=") .append(URLEncoder.encode(sValue, "UTF-8")); } // if (e.hasMoreElements()) sb.append("&"); } int len = sb.length(); String result = sb.substring(0, len - 1); BASE64Encoder b64enc = new BASE64Encoder(); return b64enc.encode(result.getBytes("UTF-8")); } catch (Exception e) { ASelectSystemLogger logger = ASelectSystemLogger.getHandle(); logger.log(Level.WARNING, MODULE, sMethod, "Could not serialize attributes", e); throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR); } }
From source file:org.glite.slcs.pki.CertificateExtensionFactory.java
/** * /*from www . j a v a 2 s. c o m*/ * @param prefixedAltNames * @param values * @return */ static protected CertificateExtension createSubjectAltNameExtension(Vector prefixedAltNames, String values) { ASN1EncodableVector altNames = new ASN1EncodableVector(); Enumeration typeAndNames = prefixedAltNames.elements(); while (typeAndNames.hasMoreElements()) { String typeAndName = (String) typeAndNames.nextElement(); typeAndName = typeAndName.trim(); if (typeAndName.startsWith("email:")) { String emailAddress = typeAndName.substring("email:".length()); GeneralName altName = new GeneralName(GeneralName.rfc822Name, emailAddress); altNames.add(altName); } else if (typeAndName.startsWith("dns:")) { String hostname = typeAndName.substring("dns:".length()); GeneralName altName = new GeneralName(GeneralName.dNSName, hostname); altNames.add(altName); } else { LOG.error("Unsupported subjectAltName: " + typeAndName); } } DERSequence subjectAltNames = new DERSequence(altNames); GeneralNames generalNames = new GeneralNames(subjectAltNames); X509Extension subjectAltNameExtension = new X509Extension(false, new DEROctetString(generalNames)); return new CertificateExtension(X509Extensions.SubjectAlternativeName, "SubjectAltName", subjectAltNameExtension, values); }
From source file:jnode.net.NetworkInterface.java
/** * Return an Enumeration of all available network interfaces * /* w ww . ja v a 2s . co m*/ * @exception SocketException * If an error occurs */ @SuppressWarnings("unchecked") public static Enumeration getNetworkInterfaces() throws SocketException { log.debug("getNetworkInterfaces"); final Vector list = new Vector(); for (Iterator i = VMNetUtils.getAPI().getNetDevices().iterator(); i.hasNext();) { final VMNetDevice dev = (VMNetDevice) i.next(); log.debug(dev.getId()); list.add(new NetworkInterface(dev)); } return list.elements(); }