List of usage examples for java.util Vector indexOf
public int indexOf(Object o)
From source file:org.apache.struts2.jasper.compiler.JspUtil.java
/** * Checks if all mandatory attributes are present and if all attributes * present have valid names. Checks attributes specified as XML-style * attributes as well as attributes specified using the jsp:attribute * standard action.//w w w . j a v a 2s . c o m * * @param typeOfTag type of tag * @param n node * @param validAttributes valid attributes * @param err error dispatcher * @throws JasperException in case of Jasper errors */ public static void checkAttributes(String typeOfTag, Node n, ValidAttribute[] validAttributes, ErrorDispatcher err) throws JasperException { Attributes attrs = n.getAttributes(); Mark start = n.getStart(); boolean valid = true; // AttributesImpl.removeAttribute is broken, so we do this... int tempLength = (attrs == null) ? 0 : attrs.getLength(); Vector temp = new Vector(tempLength, 1); for (int i = 0; i < tempLength; i++) { String qName = attrs.getQName(i); if ((!qName.equals("xmlns")) && (!qName.startsWith("xmlns:"))) temp.addElement(qName); } // Add names of attributes specified using jsp:attribute Node.Nodes tagBody = n.getBody(); if (tagBody != null) { int numSubElements = tagBody.size(); for (int i = 0; i < numSubElements; i++) { Node node = tagBody.getNode(i); if (node instanceof Node.NamedAttribute) { String attrName = node.getAttributeValue("name"); temp.addElement(attrName); // Check if this value appear in the attribute of the node if (n.getAttributeValue(attrName) != null) { err.jspError(n, "jsp.error.duplicate.name.jspattribute", attrName); } } else { // Nothing can come before jsp:attribute, and only // jsp:body can come after it. break; } } } /* * First check to see if all the mandatory attributes are present. * If so only then proceed to see if the other attributes are valid * for the particular tag. */ String missingAttribute = null; for (ValidAttribute validAttribute : validAttributes) { int attrPos; if (validAttribute.mandatory) { attrPos = temp.indexOf(validAttribute.name); if (attrPos != -1) { temp.remove(attrPos); valid = true; } else { valid = false; missingAttribute = validAttribute.name; break; } } } // If mandatory attribute is missing then the exception is thrown if (!valid) err.jspError(start, "jsp.error.mandatory.attribute", typeOfTag, missingAttribute); // Check to see if there are any more attributes for the specified tag. int attrLeftLength = temp.size(); if (attrLeftLength == 0) return; // Now check to see if the rest of the attributes are valid too. String attribute = null; for (int j = 0; j < attrLeftLength; j++) { valid = false; attribute = (String) temp.elementAt(j); for (ValidAttribute validAttribute : validAttributes) { if (attribute.equals(validAttribute.name)) { valid = true; break; } } if (!valid) err.jspError(start, "jsp.error.invalid.attribute", typeOfTag, attribute); } // XXX *could* move EL-syntax validation here... (sb) }
From source file:org.codecover.eclipse.views.CoverageGraphView.java
private edu.uci.ics.jung.graph.Graph<CoverageGraphNode, CoverageGraphLink> createGraph(String Criterion, String SUTLevel, String TestLevel, Boolean ShowOnlyCovered, Boolean CompleteName) { edu.uci.ics.jung.graph.Graph<CoverageGraphNode, CoverageGraphLink> graph = new SparseMultigraph<CoverageGraphNode, CoverageGraphLink>(); try {//from w w w . j a v a2s. c om Set<CoverableItem> coverableItemSet = CreateCoverableItemSet(Criterion); Vector<CoverageGraphNode> SUTItems = new Vector<CoverageGraphNode>(); Vector<String> SUTItemsId = new Vector<String>(); Vector<CoverageGraphNode> TestItems = new Vector<CoverageGraphNode>(); Vector<String> TestItemsId = new Vector<String>(); int NumOfSUTNodes = 0; int NumOfTestNodes = 0; if (selectedTestCases.size() != 0) { CoverageGraphNode SUTNode; CoverageGraphNode TestNode; List<CoverableItem> SUTItemList = new ArrayList<CoverableItem>(coverableItemSet); List<CoverableItem> CoveredItemList; //Adding all of the SUT Nodes to the graph: //----------------------------------------- for (int j = 0; j < SUTItemList.size(); j++) { boolean ex = false; HierarchyLevel methodLevel = null; try { methodLevel = getSUTItemMethod(SUTItemList.get(j)); } catch (IllegalArgumentException e1) { // the item is a condition, it is not possible to get the parent statement in the tree (it's parent is null) ex = true; } catch (Exception e2) { ex = true; } if (methodLevel != null && !ex) { String PackageName = getSUTItemPackage(getSUTItemClass(methodLevel)); String ClassName = getSUTItemClass(methodLevel).getName(); String MethodName = methodLevel.getName(); String ItemName = getSUTItemId(SUTItemList.get(j).getId()); String nodeName = getNodeLable(SUTLevel, PackageName, ClassName, MethodName, ItemName); if (!SUTItemsId.contains(nodeName)) { SUTNode = new CoverageGraphNode("SUT", SUTLevel, PackageName, ClassName, getSUTItemClass(methodLevel).getLocation().getLocations().get(0), MethodName, methodLevel.getLocation().getLocations().get(0), ItemName, loc, StContent, methodLevel, CompleteName); SUTItemsId.add(SUTNode.getLable()); SUTItems.add(SUTNode); NumOfSUTNodes++; if (!ShowOnlyCovered) graph.addVertex(SUTNode); } } } Set<CoverableItem> coveredItemSet; int testsize = 0; if (!selectedTestCases.equals(null)) testsize = selectedTestCases.size(); for (int i = 0; i < testsize; i++) { //Adding Test Nodes to the graph: //------------------------------- TestCase tc = (TestCase) selectedTestCases.get(i); TestNode = new CoverageGraphNode("Test", TestLevel, getTestNodeName(tc.getName(), "Package"), getTestNodeName(tc.getName(), "Class"), getTestNodeName(tc.getName(), "Method"), CompleteName); String testNodeName = TestNode.getLable(); if (!TestItemsId.contains(testNodeName)) { TestItemsId.add(TestNode.getLable()); TestItems.add(TestNode); graph.addVertex(TestNode); TestNode.Testcases.add(tc); NumOfTestNodes++; } else { for (int k = 0; k < NumOfTestNodes; k++) if (TestItems.get(k).getLable().compareTo(testNodeName) == 0) TestNode = TestItems.get(k); TestNode.Testcases.add(tc); } Map<CoverableItem, Long> CoveredItemMap = tc.getCoverageData(); coveredItemSet = new HashSet<CoverableItem>(); for (int j = 0; j < SUTItemList.size(); j++) { coveredItemSet.add(SUTItemList.get(j)); } coveredItemSet.retainAll(CoveredItemMap.keySet()); CoveredItemList = new ArrayList<CoverableItem>(coveredItemSet); String nodeName = ""; for (int j = 0; j < CoveredItemList.size(); j++) { boolean ex = false; HierarchyLevel methodLevel = null; HierarchyLevel currentlevel = null; try { methodLevel = getSUTItemMethod(CoveredItemList.get(j)); } catch (Exception ec) { ex = true; } if (methodLevel != null && !ex) { String PackageName = getSUTItemPackage(getSUTItemClass(methodLevel)); String ClassName = getSUTItemClass(methodLevel).getName(); String MethodName = methodLevel.getName(); String ItemName = getSUTItemId(CoveredItemList.get(j).getId()); nodeName = getNodeLable(SUTLevel, PackageName, ClassName, MethodName, ItemName); //Adding Edges to the graph: //-------------------------- Integer id = graph.getEdgeCount() + 1; CoverageGraphLink CoverageLink = graph.findEdge(TestItems.lastElement(), SUTItems.elementAt(SUTItemsId.indexOf(nodeName))); if (CoverageLink == null) { CoverageLink = new CoverageGraphLink(id); CoverageLink.SUTLevel = SUTLevel; } else graph.removeEdge(CoverageLink); CoverageLink.times++; CoverageGraphNode CurrentNode = new CoverageGraphNode(); for (int k = 0; k < NumOfSUTNodes; k++) if (SUTItems.get(k).getLable().compareTo(nodeName) == 0) CurrentNode = SUTItems.get(k); if (CurrentNode != null) { if (ShowOnlyCovered) graph.addVertex(CurrentNode); //For calculating Ratio: if (SUTLevel.compareTo("Method") == 0) currentlevel = methodLevel; else if (SUTLevel.compareTo("Class") == 0) currentlevel = topLevel.getParent(methodLevel); else if (SUTLevel.compareTo("Package") == 0) { currentlevel = topLevel.getParent(methodLevel); currentlevel = topLevel.getParent(currentlevel); } if (currentlevel != null) { CoverageResult coverageResult = null; if (Criterion.compareTo("Statement") == 0) { StatementCoverage coverageMetric = StatementCoverage.getInstance(); coverageResult = coverageMetric.getCoverage(TestNode.Testcases, currentlevel); } else if (Criterion.compareTo("Branch") == 0) { BranchCoverage coverageMetric = BranchCoverage.getInstance(); coverageResult = coverageMetric.getCoverage(TestNode.Testcases, currentlevel); } else if (Criterion.compareTo("Loop") == 0) { LoopCoverage coverageMetric = LoopCoverage.getInstance(); coverageResult = coverageMetric.getCoverage(TestNode.Testcases, currentlevel); } else if (Criterion.compareTo("Term") == 0) { TermCoverage coverageMetric = TermCoverage.getInstance(); coverageResult = coverageMetric.getCoverage(TestNode.Testcases, currentlevel); } if (coverageResult != null) { float coverage = 0f; if (coverageResult.getTotalItems() > 0) { coverage = ((float) coverageResult.getCoveredItems() / coverageResult.getTotalItems()); } CoverageLink.ratio = coverage; } } else CoverageLink.ratio = 2; graph.addEdge(CoverageLink, TestItems.lastElement(), CurrentNode, EdgeType.DIRECTED); } } } coveredItemSet.clear(); } } } catch (Exception ex) { return null; } return graph; }
From source file:org.ejbca.core.protocol.cmp.CmpRAUnidTest.java
@Override protected void checkDN(String sExpected, X509Name actual) { final X509Name expected = new X509Name(sExpected); final Vector<DERObjectIdentifier> expectedOIDs = expected.getOIDs(); final Vector<String> expectedValues = expected.getValues(); final Vector<DERObjectIdentifier> actualOIDs = actual.getOIDs(); final Vector<String> actualValues = actual.getValues(); assertEquals("Not the expected number of elements in the created certificate.", expectedOIDs.size(), actualOIDs.size());/*from www . jav a 2 s . com*/ for (int i = 0; i < expectedOIDs.size(); i++) { final DERObjectIdentifier oid = expectedOIDs.get(i); final int j = actualOIDs.indexOf(oid); if (!oid.equals(X509Name.SN)) { log.debug("Check that " + oid.getId() + " is OK. Expected '" + expectedValues.get(i) + "'. Actual '" + actualValues.get(j) + "'."); assertEquals("Not expected " + oid, expectedValues.get(i), actualValues.get(j)); continue; } log.debug("Special handling of the SN " + oid.getId() + ". Input '" + expectedValues.get(i) + "'. Transformed '" + actualValues.get(j) + "'."); final String expectedSNPrefix = UNIDPREFIX + LRA; final String actualSNPrefix = actualValues.get(j).substring(0, expectedSNPrefix.length()); assertEquals("New serial number prefix not as expected.", expectedSNPrefix, actualSNPrefix); final String actualSNRandom = actualValues.get(j).substring(expectedSNPrefix.length()); assertTrue("Random in serial number not OK: " + actualSNRandom, Pattern.compile("^\\w{6}$").matcher(actualSNRandom).matches()); } }
From source file:org.glite.slcs.pki.bouncycastle.Codec.java
/** * Gets the first value of the {@link X509Principal} corresponding to the * given oid./* w w w . j a v a2 s .com*/ * * @param certificate * The X509 certificate, containing the X509Principal. * @param oid * The OID of the desired value. * @return The value or <code>null</code> if the principal doesn't contain * the oid. * @throws GeneralSecurityException * If a crypto error occurs. */ static public String getPrincipalValue(X509Certificate certificate, DERObjectIdentifier oid) throws GeneralSecurityException { X509Principal subject = PrincipalUtil.getSubjectX509Principal(certificate); Vector oids = subject.getOIDs(); int valueIndex = oids.indexOf(oid); if (valueIndex < 0) { // oid not found return null; } Vector values = subject.getValues(); String value = values.get(valueIndex).toString(); return value; }
From source file:tufts.oki.dr.fedora.DR.java
public osid.dr.AssetIterator getAssets(java.io.Serializable searchCriteria, osid.shared.Type searchType) throws osid.dr.DigitalRepositoryException { SearchCriteria lSearchCriteria = null; if (searchCriteria instanceof String) { lSearchCriteria = new SearchCriteria(); lSearchCriteria.setKeywords((String) searchCriteria); lSearchCriteria.setMaxReturns("10"); lSearchCriteria.setSearchOperation(SearchCriteria.FIND_OBJECTS); lSearchCriteria.setResults(0);/*w ww .ja v a2 s .co m*/ } else if (searchCriteria instanceof SearchCriteria) { lSearchCriteria = (SearchCriteria) searchCriteria; } else { throw new osid.dr.DigitalRepositoryException(osid.dr.DigitalRepositoryException.UNKNOWN_TYPE); } if ((searchType.getKeyword().equals("Search"))) { return (FedoraSoapFactory.search(this, lSearchCriteria)); } else if (searchType.getKeyword().equals("Advanced Search")) { return (FedoraSoapFactory.advancedSearch(this, lSearchCriteria)); } else { if (!(searchCriteria instanceof String)) { throw new osid.dr.DigitalRepositoryException(osid.dr.DigitalRepositoryException.UNKNOWN_TYPE); } try { java.util.Vector results = new java.util.Vector(); java.util.Vector ids = new java.util.Vector(); java.util.StringTokenizer st = new java.util.StringTokenizer((String) searchCriteria, ","); while (st.hasMoreTokens()) { String nextKeyword = st.nextToken().trim(); lSearchCriteria = new SearchCriteria(); lSearchCriteria.setKeywords(nextKeyword); lSearchCriteria.setMaxReturns("10"); lSearchCriteria.setSearchOperation(SearchCriteria.FIND_OBJECTS); lSearchCriteria.setResults(0); osid.dr.AssetIterator ai = FedoraSoapFactory.search(this, lSearchCriteria); while (ai.hasNext()) { osid.dr.Asset asset = ai.next(); String idString = asset.getId().getIdString(); if (ids.indexOf(idString) == -1) { results.addElement(asset); ids.addElement(idString); } } } return new AssetIterator(results); } catch (Throwable t) { throw new osid.dr.DigitalRepositoryException(osid.dr.DigitalRepositoryException.OPERATION_FAILED); } } }
From source file:tufts.vue.PublishUtil.java
public static File createIMSCP(Vector resourceVector) throws IOException, URISyntaxException, CloneNotSupportedException { String IMSCPMetadata = ""; String IMSCPOrganization = ""; String IMSCPResources = ""; int resourceCount = 2; //resourceIdentifier 1 is used for map Properties props = tufts.vue.VUE.getActiveMap().getMetadata().asProperties(); IMSCPMetadata += getMetadataString(props); IMSCPResources += getResourceTag(props, IMSCP.MAP_FILE, 1); IMSCPOrganization += "<organization identifier=\"TOC1\" structure=\"hierarchical\">"; IMSCPOrganization += "<title>IMS Content Package of VUE Map</title> "; IMSCPOrganization += "<item identifier=\"ITEM1\" identifierref=\"RESOURCE1\">"; IMSCPOrganization += "<title> VUE Cocept Map</title>"; LWMap saveMap = (LWMap) tufts.vue.VUE.getActiveMap().clone(); IMSCP imscp = new IMSCP(); Iterator i = resourceVector.iterator(); while (i.hasNext()) { Vector vector = (Vector) i.next(); Resource r = (Resource) (vector.elementAt(1)); Boolean b = (Boolean) (vector.elementAt(0)); File file = new File(new URL(r.getSpec()).getFile()); //File file = new File((String)vector.elementAt(1)); if (b.booleanValue()) { System.out.println("FileName = " + file.getName() + " index =" + resourceVector.indexOf(vector)); //resourceTable.setValueAt("Processing",resourceVector.indexOf(vector),STATUS_COL); String entry = IMSCP.RESOURCE_FILES + File.separator + file.getName(); imscp.putEntry(entry, file); IMSCPResources += getResourceTag(r.getProperties().asProperties(), entry, resourceCount); IMSCPOrganization += getItemTag("ITEM" + resourceCount, "RESOURCE" + resourceCount, "Resource " + resourceCount + " in Concept Map"); //resourceTable.setValueAt("Done",resourceVector.indexOf(vector),STATUS_COL); replaceResource(saveMap, r,/*from w ww.ja va2 s .c om*/ Resource.getFactory().get(IMSCP.RESOURCE_FILES + File.separatorChar + file.getName())); //replaceResource(saveMap,r,new MapResource(IMSCP.RESOURCE_FILES+File.separatorChar+file.getName())); resourceCount++; } } saveMap(saveMap); imscp.putEntry(IMSCP.MAP_FILE, activeMapFile); IMSCPOrganization += "</item>"; IMSCPOrganization += "</organization>"; IMSManifest = readRawManifest(); IMSManifest = IMSManifest.replaceAll(IMSCP_MANIFEST_METADATA, IMSCPMetadata).trim(); IMSManifest = IMSManifest.replaceAll(IMSCP_MANIFEST_ORGANIZATION, IMSCPOrganization); IMSManifest = IMSManifest.replaceAll(IMSCP_MANIFEST_RESOURCES, IMSCPResources); File IMSManifestFile = File.createTempFile("imsmanifest", ".xml"); BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(IMSManifestFile)); fos.write(IMSManifest.getBytes()); fos.close(); imscp.putEntry(IMSCP.MANIFEST_FILE, IMSManifestFile); System.out.println("Writing Active Map : " + activeMapFile.getName()); imscp.closeZOS(); return imscp.getFile(); }