Skip to content

Commit

Permalink
update #333
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and alberto committed Jan 27, 2016
1 parent 3640c1c commit d686996
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
public class VirtualCollectionsManager {

private static final Logger logger = Logger.getLogger(VirtualCollectionsManager.class.getName());
static final String SPARQL_NS = "http://www.w3.org/2001/sw/DataAccess/rf1/result";
static final String TEXT_DS_PREFIX = "TEXT_";


Expand Down Expand Up @@ -112,6 +113,72 @@ public static VirtualCollection doVC(String pid, FedoraAccess fedoraAccess, Arra
return null;
}
}

public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception {
try {
IResourceIndex g = ResourceIndexService.getResourceIndexImpl();
Document doc = g.getVirtualCollections();

NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result");
NodeList children;
Node child;
String name;
String pid;
boolean canLeave;


ArrayList<String> langs = new ArrayList<String>();

if(languages == null || languages.isEmpty()){
String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
for (int i = 0; i < ls.length; i++) {
String lang = ls[++i];
langs.add(lang);
}
}else{
langs = new ArrayList<String>(languages);
}

List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
for (int i = 0; i < nodes.getLength(); i++) {
canLeave = false;
name = null;
pid = null;
Node node = nodes.item(i);
children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
child = children.item(j);
if ("title".equals(child.getLocalName())) {
name = child.getFirstChild().getNodeValue();
} else if ("object".equals(child.getLocalName())) {
pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", "");
} else if ("canLeave".equals(child.getLocalName())) {
canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "").substring(("canLeave:").length()));
}
}

if (name != null && pid != null) {
try {
VirtualCollection vc = new VirtualCollection(name, pid, canLeave);

for (String lang : langs) {
String dsName = TEXT_DS_PREFIX + lang;
String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName), Charset.forName("UTF8"), true);
vc.addDescription(lang, value);
}
vcs.add(vc);
} catch (Exception vcex) {
logger.log(Level.WARNING, "Could not get virtual collection for " + pid + ": " + vcex.toString());

}
}
}
return vcs;
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error getting virtual collections", ex);
throw new Exception(ex);
}
}

public static List<VirtualCollection> getVirtualCollections(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public List<VirtualCollection> getVirtualCollections() throws Exception {
return VirtualCollectionsManager.getVirtualCollections(this.fedoraAccess, languageCodes());
}

public List<VirtualCollection> getVirtualCollectionsFromFedora() throws Exception {
return VirtualCollectionsManager.getVirtualCollectionsFromFedora(this.fedoraAccess, languageCodes());
}

public List<VirtualCollection> getVirtualCollectionsLocale() throws Exception {
Locale locale = this.localeProvider.get();
ArrayList<String> l = new ArrayList<String>();
Expand Down
2 changes: 1 addition & 1 deletion search/web/inc/admin/_virtual_collection_admin.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<th><view:msg>administrator.dialogs.virtualcollections.canLeave</view:msg></th>
<th></th>
</thead>
<c:forEach var="col" items="${cols.virtualCollections}">
<c:forEach var="col" items="${cols.virtualCollectionsFromFedora}">
<tr id="vc_${col.pid}">
<td>${col.pid}</td>
<c:forEach items="${buttons.languageItems}" var="langitm">
Expand Down

0 comments on commit d686996

Please sign in to comment.