private String addChildren( WebappDaoFactory wadf, VClass parent, int position, String ontologyUri, int counter, VitroRequest vreq) { String rowElts = addVClassDataToResultsList(wadf, parent, position, ontologyUri, counter); int childShift = (rowElts.length() > 0) ? 1 : 0; // if addVClassDataToResultsList filtered out the result, don't shift the children // over int length = rowElts.length(); String leaves = ""; leaves += rowElts; List<String> childURIstrs = vcDao.getSubClassURIs(parent.getURI()); if ((childURIstrs.size() > 0) && position < MAXDEPTH) { List<VClass> childClasses = new ArrayList<VClass>(); Iterator<String> childURIstrIt = childURIstrs.iterator(); while (childURIstrIt.hasNext()) { String URIstr = childURIstrIt.next(); try { VClass child = vcDao.getVClassByURI(URIstr); if (!child.getURI().equals(OWL.Nothing.getURI())) { childClasses.add(child); } } catch (Exception e) { } } sortForPickList(childClasses, vreq); Iterator<VClass> childClassIt = childClasses.iterator(); while (childClassIt.hasNext()) { VClass child = (VClass) childClassIt.next(); leaves += addChildren(wadf, child, position + childShift, ontologyUri, counter, vreq); if (!childClassIt.hasNext()) { if (ontologyUri == null) { leaves += " }] "; } else if (ontologyUri != null && length > 0) { // need this for when we show the classes associated with an ontology String ending = leaves.substring(leaves.length() - 2, leaves.length()); if (ending.equals("] ")) { leaves += "}]"; } else if (ending.equals(" [")) { leaves += "] "; } else { leaves += "}]"; } } } } } else { if (ontologyUri == null) { leaves += "] "; } else if (ontologyUri != null && length > 0) { leaves += "] "; } } return leaves; }
@Override public Map<String, String> getOptions( EditConfigurationVTwo editConfig, String fieldName, WebappDaoFactory wDaoFact) throws Exception { // now create an empty HashMap to populate and return HashMap<String, String> optionsMap = new LinkedHashMap<String, String>(); // for debugging, keep a count of the number of options populated int optionsCount = 0; if (vclassUri == null || vclassUri.equals("")) { throw new Exception( "no vclassUri found for field \"" + fieldName + "\" in SelectListGenerator.getOptions() when OptionsType CHILD_VCLASSES specified"); } else { // first test to see whether there's a default "leave blank" value specified with the literal // options if (defaultOptionLabel != null) { optionsMap.put(LEFT_BLANK, defaultOptionLabel); } // now populate the options VClassDao vclassDao = wDaoFact.getVClassDao(); List<String> subClassList = vclassDao.getAllSubClassURIs(vclassUri); if (subClassList == null || subClassList.size() == 0) { log.debug( "No subclasses of " + vclassUri + " found in the model so only default value from field's literalOptions will be used"); } else { for (String subClassUri : subClassList) { VClass subClass = vclassDao.getVClassByURI(subClassUri); if (subClass != null && !OWL.Nothing.getURI().equals(subClassUri)) { optionsMap.put(subClassUri, subClass.getName().trim()); ++optionsCount; } } } } log.debug("added " + optionsCount + " options for field \"" + fieldName + "\""); return optionsMap; }