|
53 | 53 | public class VirtualCollectionsManager {
|
54 | 54 |
|
55 | 55 | 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"; |
56 | 57 | static final String TEXT_DS_PREFIX = "TEXT_";
|
57 | 58 |
|
58 | 59 |
|
@@ -112,6 +113,72 @@ public static VirtualCollection doVC(String pid, FedoraAccess fedoraAccess, Arra
|
112 | 113 | return null;
|
113 | 114 | }
|
114 | 115 | }
|
| 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 | + } |
115 | 182 |
|
116 | 183 | public static List<VirtualCollection> getVirtualCollections(FedoraAccess fedoraAccess, ArrayList<String> languages) throws Exception {
|
117 | 184 | try {
|
|
0 commit comments