// retrieve the info available by the Identity verb of oai repository, e.g. protocol version // and date granularity @SuppressWarnings("unchecked") public static HashMap<String, String> getIdentifyResponseInfo(String baseURL) { Identify ident = null; OAIPMHtype xmlType = null; HashMap<String, String> res = new HashMap<String, String>(); try { ident = new Identify(baseURL); String xmlRec = ident.toString(); if (xmlRec.startsWith("<?")) { int offset = xmlRec.indexOf("?>"); xmlRec = xmlRec.substring(offset + 2); } InputStream is = new ByteArrayInputStream(xmlRec.getBytes("UTF-8")); JAXBElement<OAIPMHtype> oai = (JAXBElement<OAIPMHtype>) u.unmarshal(is); xmlType = oai.getValue(); if (xmlType.getIdentify().getBaseURL() != null) { res.put("Repository BaseURL", xmlType.getIdentify().getBaseURL()); } if (xmlType.getIdentify().getEarliestDatestamp() != null) { res.put("Earliest DateStamp", xmlType.getIdentify().getEarliestDatestamp()); } if (xmlType.getIdentify().getProtocolVersion() != null) { res.put("Protocol Version", xmlType.getIdentify().getProtocolVersion()); } if (xmlType.getIdentify().getRepositoryName() != null) { res.put("Repository Name", xmlType.getIdentify().getRepositoryName()); } if ((xmlType.getIdentify().getAdminEmail() != null) && (xmlType.getIdentify().getAdminEmail().size() > 0)) { res.put("Admin Email", xmlType.getIdentify().getAdminEmail().get(0)); } if (xmlType.getIdentify().getDeletedRecord() != null) { res.put("Deleted Record", xmlType.getIdentify().getDeletedRecord().value()); } if (xmlType.getIdentify().getGranularity() != null) { res.put("Granularity", xmlType.getIdentify().getGranularity().value()); } } catch (IOException e) { // e.printStackTrace(); } catch (ParserConfigurationException e) { // e.printStackTrace(); } catch (SAXException e) { // e.printStackTrace(); } catch (TransformerException e) { // e.printStackTrace(); } catch (JAXBException e) { // e.printStackTrace(); } ident = null; xmlType = null; return res; }
// call this method first for repository validity before do anything else... public static boolean isValid(String baseURL) { boolean res = false; Identify ident = null; // validate baseURL try { ident = new Identify(baseURL); res = true; } catch (IOException e) { // e.printStackTrace(); res = false; } catch (ParserConfigurationException e) { // e.printStackTrace(); res = false; } catch (SAXException e) { // e.printStackTrace(); res = false; } catch (TransformerException e) { // e.printStackTrace(); res = false; } // validate response (version plus xml response structure) if (ident != null) { try { NodeList errors = ident.getErrors(); if ((errors != null) && (errors.getLength() > 0)) { res = false; } else { ident.getProtocolVersion(); res = true; } } catch (TransformerException e) { // e.printStackTrace(); res = false; } catch (NoSuchFieldException e) { // e.printStackTrace(); res = false; } } ident = null; // clean up the mess ;) return res; }