public void parse(NativeElement rootTag) { NativeNodeList orgs = rootTag.getElementsByTagName("organization"); for (int i = 0; i < orgs.getLength(); i++) { NativeElement curTag = orgs.elementAt(i); Organization organization = new Organization( curTag.getAttribute("title"), curTag.getAttribute("shortTitle"), curTag, true); organizations.add(organization); } }
private String batchCreate(Request request, String username) { NativeDocument doc = NativeDocumentFactory.newNativeDocument(); StringBuffer successfulIDs = new StringBuffer(); StringBuffer extantIDs = new StringBuffer(); StringBuffer unsuccessfulIDs = new StringBuffer(); try { String text = request.getEntity().getText(); doc.parse(text); AssessmentFilter filter = AssessmentFilter.parseXML( doc.getDocumentElement() .getElementsByTagName(AssessmentFilter.HEAD_TAG) .elementAt(0)); NativeNodeList nodes = doc.getDocumentElement().getElementsByTagName("taxon"); boolean useTemplate = Boolean.parseBoolean( doc.getDocumentElement() .getElementsByTagName("useTemplate") .elementAt(0) .getTextContent()); System.out.println("Using template? " + useTemplate); for (int i = 0; i < nodes.getLength(); i++) { TaxonNode taxon = TaxaIO.readNode(nodes.elementAt(i).getTextContent(), vfs); AssessmentData curAss = null; curAss = doCreateAssessmentForBatch( request.getChallengeResponse().getIdentifier(), filter, useTemplate, taxon); try { AssessmentIOWriteResult result = assignIDAndSave(curAss, username); if (result.status.isSuccess()) successfulIDs.append( curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", ")); else unsuccessfulIDs.append( curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", ")); } catch (RegionConflictException e) { extantIDs.append(curAss.getSpeciesName() + (i == nodes.getLength() - 1 ? "" : ", ")); } } StringBuilder ret = new StringBuilder(); if (unsuccessfulIDs.length() > 0) ret.append( "<div>Unable to create an assessment for the following species: " + unsuccessfulIDs + "</div>\r\n"); if (extantIDs.length() > 0) ret.append( "<div>The following species already have draft assessments with the specific locality: " + extantIDs + "</div>\r\n"); if (successfulIDs.length() > 0) ret.append( "<div>Successfully created an assessment for the following species: " + successfulIDs + "</div>\r\n"); return ret.toString(); } catch (IOException e) { e.printStackTrace(); return null; } catch (NullPointerException e) { e.printStackTrace(); return null; } catch (Exception e) { e.printStackTrace(); return null; } }