KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > content > crosswalk > SimpleDCDisseminationCrosswalk


1 /*
2  * SimpleDCDisseminationCrosswalk.java
3  *
4  * Version: $Revision: 1.2 $
5  *
6  * Date: $Date: 2006/03/27 02:57:09 $
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
41 package org.dspace.content.crosswalk;
42
43 import java.io.OutputStream JavaDoc;
44 import java.io.IOException JavaDoc;
45 import java.util.ArrayList JavaDoc;
46 import java.util.List JavaDoc;
47
48 import java.sql.SQLException JavaDoc;
49
50 import org.dspace.core.Context;
51 import org.dspace.core.Constants;
52 import org.dspace.content.Item;
53 import org.dspace.content.DSpaceObject;
54 import org.dspace.content.DCValue;
55 import org.dspace.core.SelfNamedPlugin;
56 import org.dspace.authorize.AuthorizeException;
57
58 import org.jdom.*;
59 //import org.jdom.output.XMLOutputter;
60
//import org.jdom.output.Format;
61

62 /**
63  * Disseminator for Simple Dublin Core metadata in XML format.
64  * Logic stolen from OAIDCCrosswalk. This is mainly intended
65  * as a proof-of-concept, to use crosswalk plugins in the OAI-PMH
66  * server.
67  *
68  * @author Larry Stone
69  * @version $Revision: 1.2 $
70  */

71 public class SimpleDCDisseminationCrosswalk extends SelfNamedPlugin
72     implements DisseminationCrosswalk
73 {
74     // namespaces of interest.
75

76     // XXX FIXME: may also want http://www.openarchives.org/OAI/2.0/oai_dc/ for OAI
77

78     private static final Namespace DC_NS =
79         Namespace.getNamespace("dc", "http://purl.org/dc/elements/1.1/");
80
81     // simple DC schema for OAI
82
private static final String JavaDoc DC_XSD =
83                 "http://dublincore.org/schemas/xmls/simpledc20021212.xsd";
84                 //"http://www.openarchives.org/OAI/2.0/oai_dc.xsd";
85

86     private static final String JavaDoc schemaLocation =
87         DC_NS.getURI()+" "+DC_XSD;
88
89     private static final Namespace namespaces[] =
90         { DC_NS, XSI_NS };
91
92     private final static String JavaDoc aliases[] = { "SimpleDC", "DC" };
93
94     public static String JavaDoc[] getPluginNames()
95     {
96         return aliases;
97     }
98
99     public Element disseminateElement(DSpaceObject dso)
100         throws CrosswalkException,
101                IOException JavaDoc, SQLException JavaDoc, AuthorizeException
102     {
103         Element root = new Element("simpledc", DC_NS);
104         root.setAttribute("schemaLocation", schemaLocation, XSI_NS);
105         root.addContent(disseminateListInternal(dso, false));
106         return root;
107     }
108
109     /**
110      * Returns object's metadata as XML elements.
111      * Simple-minded copying of elements: convert contributor.author to
112      * "creator" but otherwise just grab element name without qualifier.
113      */

114     public List JavaDoc disseminateList(DSpaceObject dso)
115         throws CrosswalkException,
116                IOException JavaDoc, SQLException JavaDoc, AuthorizeException
117     {
118         return disseminateListInternal(dso, true);
119     }
120
121     public List JavaDoc disseminateListInternal(DSpaceObject dso, boolean addSchema)
122         throws CrosswalkException,
123                IOException JavaDoc, SQLException JavaDoc, AuthorizeException
124     {
125         if (dso.getType() != Constants.ITEM)
126             throw new CrosswalkObjectNotSupported("SimpleDCDisseminationCrosswalk can only crosswalk an Item.");
127
128         Item item = (Item)dso;
129         DCValue[] allDC = item.getDC(Item.ANY, Item.ANY, Item.ANY);
130
131         List JavaDoc dcl = new ArrayList JavaDoc(allDC.length);
132
133         for (int i = 0; i < allDC.length; i++)
134         {
135             // Do not include description.provenance
136
if (!(allDC[i].element.equals("description") &&
137                   (allDC[i].qualifier != null && allDC[i].qualifier.equals("provenance"))))
138             {
139                 String JavaDoc element;
140
141                 // contributor.author exposed as 'creator'
142
if (allDC[i].element.equals("contributor")
143                         && (allDC[i].qualifier != null)
144                         && allDC[i].qualifier.equals("author"))
145                     element = "creator";
146                 else
147                     element = allDC[i].element;
148                 Element field = new Element(element, DC_NS);
149                 field.addContent(allDC[i].value);
150                 if (addSchema)
151                     field.setAttribute("schemaLocation", schemaLocation, XSI_NS);
152                 dcl.add(field);
153             }
154         }
155         return dcl;
156     }
157
158     public Namespace[] getNamespaces()
159     {
160         return namespaces;
161     }
162
163     public String JavaDoc getSchemaLocation()
164     {
165         return schemaLocation;
166     }
167
168     public boolean canDisseminate(DSpaceObject dso)
169     {
170         return dso.getType() == Constants.ITEM;
171     }
172
173     public boolean preferList()
174     {
175         return true;
176     }
177 }
178
Popular Tags