XMLConfiguration instConfigSection = null;
try {
instConfigSection = new XMLConfiguration(configurationFile);
} catch (ConfigurationException ce) {
throw new StartupException("Error loading institution portlet configuration file!", ce);
}
if (instConfigSection == null) { throw new StartupException("Error loading institution portlet configuration file!"); }
institutions = new FastHashMap();
for (Iterator iter = instConfigSection.getChildren("institution").iterator(); iter.hasNext();) {
Configuration instConfigEntry = (Configuration) iter.next(); // the institutions config entry
String shortName = instConfigEntry.getAttribute("shortname"); // short name of inst
if (shortName == null) { throw new StartupException("Institution portlet startup: No shortname given for one entry!"); }
try {
List<InstitutionPortletSupervisorEntry> supervisors = new ArrayList<InstitutionPortletSupervisorEntry>(1); // there may be more than one supervisor
for (Iterator it = instConfigEntry.getChildren(SUPERVISOR).iterator(); it.hasNext();) {
Configuration supervisorElement = (Configuration) it.next(); // one supervisor element
InstitutionPortletSupervisorEntry ipse = new InstitutionPortletSupervisorEntry(getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PERSON)),
getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_PHONE)),
getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_EMAIL)),
getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_URL)),
getSupervisorElementChild(supervisorElement.getChild(SUPERVISOR_BLOG)));
supervisors.add(ipse); // save it
}
//get polymorph links
List<Configuration> polymorphConfs = instConfigEntry.getChildren(POLYMORPHLINK);
List<PolymorphLink> polyList = new ArrayList<PolymorphLink>();
if (polymorphConfs != null && polymorphConfs.size() > 0) {
for(Configuration polymorphConf: polymorphConfs) {
List<PolymorphLinkElement> elemList = new ArrayList<PolymorphLinkElement>();
for (Iterator<Configuration> it = polymorphConf.getChildren(POLYMORPHLINK_ELEMENT).iterator(); it.hasNext();) {
Configuration tmp = it.next();
elemList.add(new PolymorphLinkElement(tmp.getAttribute(POLYMORPHLINK_ELEMENT_ATTRIBUT), tmp
.getAttribute(POLYMORPHLINK_ELEMENT_VALUE), tmp.getAttribute(POLYMORPHLINK_ELEMENT_ID), tmp
.getAttribute(POLYMORPHLINK_ELEMENT_CONDITION)));
}
PolymorphLink polyLink = new PolymorphLink(polymorphConf.getAttribute(POLYMORPHLINK_TARGETID), polymorphConf.getAttribute(POLYMORPHLINK_TYPE),
polymorphConf.getAttribute(POLYMORPHLINK_TEXT), elemList);
polyList.add(polyLink);
}
}
InstitutionPortletEntry ipe = new InstitutionPortletEntry(instConfigEntry.getChild(INSTITUTION_NAME).getAttribute(VALUE),
instConfigEntry.getChild(INSTITUTION_URL).getAttribute(VALUE), instConfigEntry.getChild(INSTITUTION_LOGO).getAttribute(VALUE),
supervisors, polyList);
institutions.put(shortName.toLowerCase(), ipe); // save inst entry
} catch (Exception e) {
e.printStackTrace();
throw new StartupException(e.getMessage(), e);
}
}
// from now on optimize for non-synchronized read access
institutions.setFast(true);