KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > oai > METSCrosswalk


1 /*
2  * METSCrosswalk.java
3  *
4  * Version: $Revision: 1.1 $
5  *
6  * Date: $Date: 2005/10/12 02:27:12 $
7  *
8  * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
9  * Institute of Technology. All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are
13  * met:
14  *
15  * - Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  *
18  * - Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution.
21  *
22  * - Neither the name of the Hewlett-Packard Company nor the name of the
23  * Massachusetts Institute of Technology nor the names of their
24  * contributors may be used to endorse or promote products derived from
25  * this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38  * DAMAGE.
39  */

40 package org.dspace.app.oai;
41
42 import java.io.ByteArrayOutputStream JavaDoc;
43 import java.util.Properties JavaDoc;
44
45 import org.dspace.app.mets.METSExport;
46 import org.dspace.search.HarvestedItemInfo;
47
48 import ORG.oclc.oai.server.crosswalk.Crosswalk;
49 import ORG.oclc.oai.server.verb.CannotDisseminateFormatException;
50
51 /**
52  * OAICat crosswalk to allow METS to be harvested.
53  *
54  * No security or privacy measures in place.
55  *
56  * @author Li XiaoYu (Rita)
57  * @author Robert Tansley
58  */

59 public class METSCrosswalk extends Crosswalk
60 {
61     public METSCrosswalk(Properties JavaDoc properties)
62     {
63         super(
64                 "http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd");
65     }
66
67     public boolean isAvailableFor(Object JavaDoc nativeItem)
68     {
69         // We have METS for everything
70
return true;
71     }
72
73     public String JavaDoc createMetadata(Object JavaDoc nativeItem)
74             throws CannotDisseminateFormatException
75     {
76         HarvestedItemInfo hii = (HarvestedItemInfo) nativeItem;
77
78         try
79         {
80             ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
81
82             METSExport.writeMETS(hii.context, hii.item, baos, true);
83
84             // FIXME: Nasty hack to remove <?xml...?> header that METS toolkit
85
// puts there. Hopefully the METS toolkit itself can be updated
86
// to fix this
87
String JavaDoc fullXML = baos.toString("UTF-8");
88             String JavaDoc head = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"?>\n";
89             int pos = fullXML.indexOf(head);
90             if (pos != -1)
91             {
92                 fullXML = fullXML.substring(pos + head.length());
93             }
94             
95             return fullXML;
96         }
97         catch (Exception JavaDoc e)
98         {
99             e.printStackTrace();
100             return null;
101         }
102
103     }
104 }
105
Popular Tags