1 40 package org.dspace.handle; 41 42 import java.sql.SQLException ; 43 import java.util.Collections ; 44 import java.util.Enumeration ; 45 import java.util.Iterator ; 46 import java.util.LinkedList ; 47 import java.util.List ; 48 49 import net.handle.hdllib.Encoder; 50 import net.handle.hdllib.HandleException; 51 import net.handle.hdllib.HandleStorage; 52 import net.handle.hdllib.HandleValue; 53 import net.handle.hdllib.ScanCallback; 54 import net.handle.hdllib.Util; 55 import net.handle.util.StreamTable; 56 57 import org.apache.log4j.Logger; 58 import org.dspace.core.ConfigurationManager; 59 import org.dspace.core.Context; 60 61 78 public class HandlePlugin implements HandleStorage 79 { 80 81 private static Logger log = Logger.getLogger(HandlePlugin.class); 82 83 86 public HandlePlugin() 87 { 88 } 89 90 94 97 public void init(StreamTable st) throws Exception 98 { 99 if (log.isInfoEnabled()) 101 { 102 log.info("Called init (not implemented)"); 103 } 104 } 105 106 109 public void setHaveNA(byte[] theHandle, boolean haveit) 110 throws HandleException 111 { 112 if (log.isInfoEnabled()) 114 { 115 log.info("Called setHaveNA (not implemented)"); 116 } 117 } 118 119 122 public void createHandle(byte[] theHandle, HandleValue[] values) 123 throws HandleException 124 { 125 if (log.isInfoEnabled()) 127 { 128 log.info("Called createHandle (not implemented)"); 129 } 130 } 131 132 135 public boolean deleteHandle(byte[] theHandle) throws HandleException 136 { 137 if (log.isInfoEnabled()) 139 { 140 log.info("Called deleteHandle (not implemented)"); 141 } 142 143 return false; 144 } 145 146 149 public void updateValue(byte[] theHandle, HandleValue[] values) 150 throws HandleException 151 { 152 if (log.isInfoEnabled()) 154 { 155 log.info("Called updateValue (not implemented)"); 156 } 157 } 158 159 162 public void deleteAllRecords() throws HandleException 163 { 164 if (log.isInfoEnabled()) 166 { 167 log.info("Called deleteAllRecords (not implemented)"); 168 } 169 } 170 171 174 public void checkpointDatabase() throws HandleException 175 { 176 if (log.isInfoEnabled()) 178 { 179 log.info("Called checkpointDatabase (not implemented)"); 180 } 181 } 182 183 186 public void shutdown() 187 { 188 if (log.isInfoEnabled()) 190 { 191 log.info("Called shutdown (not implemented)"); 192 } 193 } 194 195 198 public void scanHandles(ScanCallback callback) throws HandleException 199 { 200 if (log.isInfoEnabled()) 202 { 203 log.info("Called scanHandles (not implemented)"); 204 } 205 } 206 207 210 public void scanNAs(ScanCallback callback) throws HandleException 211 { 212 if (log.isInfoEnabled()) 214 { 215 log.info("Called scanNAs (not implemented)"); 216 } 217 } 218 219 223 238 public byte[][] getRawHandleValues(byte[] theHandle, int[] indexList, 239 byte[][] typeList) throws HandleException 240 { 241 if (log.isInfoEnabled()) 242 { 243 log.info("Called getRawHandleValues"); 244 } 245 246 Context context = null; 247 248 try 249 { 250 if (theHandle == null) 251 { 252 throw new HandleException(HandleException.INTERNAL_ERROR); 253 } 254 255 String handle = Util.decodeString(theHandle); 256 257 context = new Context(); 258 259 String url = HandleManager.resolveToURL(context, handle); 260 261 if (url == null) 262 { 263 throw new HandleException(HandleException.HANDLE_DOES_NOT_EXIST); 264 } 265 266 HandleValue value = new HandleValue(); 267 268 value.setIndex(100); 269 value.setType(Util.encodeString("URL")); 270 value.setData(Util.encodeString(url)); 271 value.setTTLType((byte) 0); 272 value.setTTL(100); 273 value.setTimestamp(100); 274 value.setReferences(null); 275 value.setAdminCanRead(true); 276 value.setAdminCanWrite(false); 277 value.setAnyoneCanRead(true); 278 value.setAnyoneCanWrite(false); 279 280 List values = new LinkedList (); 281 282 values.add(value); 283 284 byte[][] rawValues = new byte[values.size()][]; 285 286 for (int i = 0; i < values.size(); i++) 287 { 288 HandleValue hvalue = (HandleValue) values.get(i); 289 290 rawValues[i] = new byte[Encoder.calcStorageSize(hvalue)]; 291 Encoder.encodeHandleValue(rawValues[i], 0, hvalue); 292 } 293 294 return rawValues; 295 } 296 catch (HandleException he) 297 { 298 throw he; 299 } 300 catch (Exception e) 301 { 302 if (log.isDebugEnabled()) 303 { 304 log.debug("Exception in getRawHandleValues", e); 305 } 306 307 throw new HandleException(HandleException.INTERNAL_ERROR); 308 } 309 finally 310 { 311 if (context != null) 312 { 313 try 314 { 315 context.complete(); 316 } 317 catch (SQLException sqle) 318 { 319 } 320 } 321 } 322 } 323 324 333 public boolean haveNA(byte[] theHandle) throws HandleException 334 { 335 if (log.isInfoEnabled()) 336 { 337 log.info("Called haveNA"); 338 } 339 340 350 351 String expected = "0.NA/" 354 + ConfigurationManager.getProperty("handle.prefix"); 355 356 String received = Util.decodeString(theHandle); 358 359 return expected.equals(received); 361 } 362 363 374 public Enumeration getHandlesForNA(byte[] theNAHandle) 375 throws HandleException 376 { 377 String naHandle = Util.decodeString(theNAHandle); 378 379 if (log.isInfoEnabled()) 380 { 381 log.info("Called getHandlesForNA for NA " + naHandle); 382 } 383 384 Context context = null; 385 386 try 387 { 388 context = new Context(); 389 390 List handles = HandleManager.getHandlesForPrefix(context, naHandle); 391 List results = new LinkedList (); 392 393 for (Iterator iterator = handles.iterator(); iterator.hasNext();) 394 { 395 String handle = (String ) iterator.next(); 396 397 results.add(Util.encodeString(handle)); 399 } 400 401 return Collections.enumeration(results); 402 } 403 catch (SQLException sqle) 404 { 405 if (log.isDebugEnabled()) 406 { 407 log.debug("Exception in getHandlesForNA", sqle); 408 } 409 410 throw new HandleException(HandleException.INTERNAL_ERROR); 411 } 412 finally 413 { 414 if (context != null) 415 { 416 try 417 { 418 context.complete(); 419 } 420 catch (SQLException sqle) 421 { 422 } 423 } 424 } 425 } 426 } 427 | Popular Tags |