1
2 /***
3 *Copyright (c) 2000-2002 OCLC Online Computer Library Center,
4 *Inc. and other contributors. All rights reserved. The contents of this file, as updated
5 *from time to time by the OCLC Office of Research, are subject to OCLC Research
6 *Public License Version 2.0 (the "License"); you may not use this file except in
7 *compliance with the License. You may obtain a current copy of the License at
8 *http://purl.oclc.org/oclc/research/ORPL/. Software distributed under the License is
9 *distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
10 *or implied. See the License for the specific language governing rights and limitations
11 *under the License. This software consists of voluntary contributions made by many
12 *individuals on behalf of OCLC Research. For more information on OCLC Research,
13 *please see http://www.oclc.org/oclc/research/.
14 *
15 *The Original Code is XML2oai_dc.java.
16 *The Initial Developer of the Original Code is Jeff Young.
17 *Portions created by ______________________ are
18 *Copyright (C) _____ _______________________. All Rights Reserved.
19 *Contributor(s):______________________________________.
20 */
21
22
23 package astrogrid.registry.oai;
24
25 import ORG.oclc.oai.server.crosswalk.*;
26
27 import java.util.Properties;
28 import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
29
30 /***
31 * Convert native "item" to oai_dc. In this case, the native "item"
32 * is assumed to already be formatted as an OAI <record> element,
33 * with the possible exception that multiple metadataFormats may
34 * be present in the <metadata> element. The "crosswalk", merely
35 * involves pulling out the one that is requested.
36 */
37 public class XML2ivo_vrCrosswalk extends Crosswalk {
38 private static String elementName = "Resource";
39 private static final String prefix_09 = "vr:";
40 private static final String prefix_10 = "vor:";
41
42
43
44
45 /***
46 * The constructor assigns the schemaLocation associated with this crosswalk. Since
47 * the crosswalk is trivial in this case, no properties are utilized.
48 *
49 * @param properties properties that are needed to configure the crosswalk.
50 */
51 public XML2ivo_vrCrosswalk(Properties properties) {
52 super("http://www.ivoa.net/xml/VOResource/v0.9 http://www.ivoa.net/xml/VOResource/VOResource-v0.9.xsd ");
53 }
54
55 /***
56 * Can this nativeItem be represented in DC format?
57 * @param nativeItem a record in native format
58 * @return true if DC format is possible, false otherwise.
59 */
60 public boolean isAvailableFor(Object nativeItem) {
61 String fullItem = (String)nativeItem;
62 if ((fullItem.indexOf(("<" + prefix_09 + elementName)) >= 0) ||
63 (fullItem.indexOf(("<" + prefix_10 + elementName)) >= 0))
64 return true;
65 return false;
66 }
67
68 /***
69 * Perform the actual crosswalk.
70 *
71 * @param nativeItem the native "item". In this case, it is
72 * already formatted as an OAI <record> element, with the
73 * possible exception that multiple metadataFormats are
74 * present in the <metadata> element.
75 * @return a String containing the XML to be stored within the <metadata> element.
76 * @exception CannotDisseminateFormatException nativeItem doesn't support this format.
77 */
78 public String createMetadata(Object nativeItem)
79 throws CannotDisseminateFormatException {
80 String fullItem = (String)nativeItem;
81 String elementEnd = prefix_09 + elementName + ">";
82 int startOffset = fullItem.indexOf(("<" + prefix_09 + elementName));
83 if(startOffset == -1) {
84 startOffset = fullItem.indexOf(("<" + prefix_10 + elementName));
85 elementEnd = prefix_10 + elementName + ">";
86 }
87 if (startOffset == -1) {
88 throw new CannotDisseminateFormatException(getSchemaLocation());
89 }
90 int endOffset = fullItem.indexOf(elementEnd) + elementEnd.length();
91 System.out.println("STARTOFFSET = " + startOffset + " ENDOFFSET=" + endOffset + "THE FULLITEM = " + fullItem);
92 return fullItem.substring(startOffset, endOffset);
93 }
94 }