Skip to content

Commit d686996

Browse files
albertoalberto
authored andcommitted
update #333
1 parent 3640c1c commit d686996

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

common/src/main/java/cz/incad/kramerius/virtualcollections/VirtualCollectionsManager.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
public class VirtualCollectionsManager {
5454

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

5859

@@ -112,6 +113,72 @@ public static VirtualCollection doVC(String pid, FedoraAccess fedoraAccess, Arra
112113
return null;
113114
}
114115
}
116+
117+
public static List<VirtualCollection> getVirtualCollectionsFromFedora(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception {
118+
try {
119+
IResourceIndex g = ResourceIndexService.getResourceIndexImpl();
120+
Document doc = g.getVirtualCollections();
121+
122+
NodeList nodes = doc.getDocumentElement().getElementsByTagNameNS(SPARQL_NS, "result");
123+
NodeList children;
124+
Node child;
125+
String name;
126+
String pid;
127+
boolean canLeave;
128+
129+
130+
ArrayList<String> langs = new ArrayList<String>();
131+
132+
if(languages == null || languages.isEmpty()){
133+
String[] ls = KConfiguration.getInstance().getPropertyList("interface.languages");
134+
for (int i = 0; i < ls.length; i++) {
135+
String lang = ls[++i];
136+
langs.add(lang);
137+
}
138+
}else{
139+
langs = new ArrayList<String>(languages);
140+
}
141+
142+
List<VirtualCollection> vcs = new ArrayList<VirtualCollection>();
143+
for (int i = 0; i < nodes.getLength(); i++) {
144+
canLeave = false;
145+
name = null;
146+
pid = null;
147+
Node node = nodes.item(i);
148+
children = node.getChildNodes();
149+
for (int j = 0; j < children.getLength(); j++) {
150+
child = children.item(j);
151+
if ("title".equals(child.getLocalName())) {
152+
name = child.getFirstChild().getNodeValue();
153+
} else if ("object".equals(child.getLocalName())) {
154+
pid = ((Element) child).getAttribute("uri").replaceAll("info:fedora/", "");
155+
} else if ("canLeave".equals(child.getLocalName())) {
156+
canLeave = Boolean.parseBoolean(child.getFirstChild().getNodeValue().replaceAll("\"", "").substring(("canLeave:").length()));
157+
}
158+
}
159+
160+
if (name != null && pid != null) {
161+
try {
162+
VirtualCollection vc = new VirtualCollection(name, pid, canLeave);
163+
164+
for (String lang : langs) {
165+
String dsName = TEXT_DS_PREFIX + lang;
166+
String value = IOUtils.readAsString(fedoraAccess.getDataStream(pid, dsName), Charset.forName("UTF8"), true);
167+
vc.addDescription(lang, value);
168+
}
169+
vcs.add(vc);
170+
} catch (Exception vcex) {
171+
logger.log(Level.WARNING, "Could not get virtual collection for " + pid + ": " + vcex.toString());
172+
173+
}
174+
}
175+
}
176+
return vcs;
177+
} catch (Exception ex) {
178+
logger.log(Level.SEVERE, "Error getting virtual collections", ex);
179+
throw new Exception(ex);
180+
}
181+
}
115182

116183
public static List<VirtualCollection> getVirtualCollections(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception {
117184
try {

search/src/java/cz/incad/Kramerius/views/virtualcollection/VirtualCollectionViewObject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public List<VirtualCollection> getVirtualCollections() throws Exception {
7575
return VirtualCollectionsManager.getVirtualCollections(this.fedoraAccess, languageCodes());
7676
}
7777

78+
public List<VirtualCollection> getVirtualCollectionsFromFedora() throws Exception {
79+
return VirtualCollectionsManager.getVirtualCollectionsFromFedora(this.fedoraAccess, languageCodes());
80+
}
81+
7882
public List<VirtualCollection> getVirtualCollectionsLocale() throws Exception {
7983
Locale locale = this.localeProvider.get();
8084
ArrayList<String> l = new ArrayList<String>();

search/web/inc/admin/_virtual_collection_admin.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<th><view:msg>administrator.dialogs.virtualcollections.canLeave</view:msg></th>
5252
<th></th>
5353
</thead>
54-
<c:forEach var="col" items="${cols.virtualCollections}">
54+
<c:forEach var="col" items="${cols.virtualCollectionsFromFedora}">
5555
<tr id="vc_${col.pid}">
5656
<td>${col.pid}</td>
5757
<c:forEach items="${buttons.languageItems}" var="langitm">

0 commit comments

Comments
 (0)