KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dspace > app > webui > jsptag > SFXLinkTag


1 /*
2  * SFXLinkTag.java
3  *
4  * Version: $Revision: 1.5 $
5  *
6  * Date: $Date: 2005/04/20 14:23:02 $
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.webui.jsptag;
41
42 import java.io.IOException JavaDoc;
43 import java.net.URLEncoder JavaDoc;
44
45 import javax.servlet.jsp.JspException JavaDoc;
46 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
47
48 import org.dspace.content.DCPersonName;
49 import org.dspace.content.DCValue;
50 import org.dspace.content.Item;
51 import org.dspace.core.ConfigurationManager;
52 import org.dspace.core.Constants;
53
54 /**
55  * Renders an SFX query link. Takes one attribute - "item" which must be an Item
56  * object.
57  *
58  * @author Robert Tansley
59  * @version $Revision: 1.5 $
60  */

61 public class SFXLinkTag extends TagSupport JavaDoc
62 {
63     /** Item to display SFX link for */
64     private Item item;
65
66     public SFXLinkTag()
67     {
68         super();
69     }
70
71     public int doStartTag() throws JspException JavaDoc
72     {
73         try
74         {
75             String JavaDoc sfxServer = ConfigurationManager
76                     .getProperty("sfx.server.url");
77
78             if (sfxServer == null)
79             {
80                 // No SFX server - SFX linking switched off
81
return SKIP_BODY;
82             }
83
84             String JavaDoc sfxQuery = "";
85
86             DCValue[] titles = item.getDC("title", null, Item.ANY);
87
88             if (titles.length > 0)
89             {
90                 sfxQuery = sfxQuery
91                         + "&title="
92                         + URLEncoder.encode(titles[0].value,
93                                 Constants.DEFAULT_ENCODING);
94             }
95
96             DCValue[] authors = item.getDC("contributor", "author", Item.ANY);
97
98             if (authors.length > 0)
99             {
100                 DCPersonName dpn = new DCPersonName(authors[0].value);
101                 sfxQuery = sfxQuery
102                         + "&aulast="
103                         + URLEncoder.encode(dpn.getLastName(),
104                                 Constants.DEFAULT_ENCODING);
105                 sfxQuery = sfxQuery
106                         + "&aufirst="
107                         + URLEncoder.encode(dpn.getFirstNames(),
108                                 Constants.DEFAULT_ENCODING);
109             }
110
111             DCValue[] isbn = item.getDC("identifier", "isbn", Item.ANY);
112
113             if (isbn.length > 0)
114             {
115                 sfxQuery = sfxQuery
116                         + "&isbn="
117                         + URLEncoder.encode(isbn[0].value,
118                                 Constants.DEFAULT_ENCODING);
119             }
120
121             DCValue[] issn = item.getDC("identifier", "issn", Item.ANY);
122
123             if (issn.length > 0)
124             {
125                 sfxQuery = sfxQuery
126                         + "&issn="
127                         + URLEncoder.encode(issn[0].value,
128                                 Constants.DEFAULT_ENCODING);
129             }
130
131             DCValue[] dates = item.getDC("date", "issued", Item.ANY);
132
133             if (dates.length > 0)
134             {
135                 String JavaDoc fullDate = dates[0].value;
136
137                 // Remove the time if there is one - day is greatest granularity
138
// for SFX
139
if (fullDate.length() > 10)
140                 {
141                     fullDate = fullDate.substring(0, 10);
142                 }
143
144                 sfxQuery = sfxQuery
145                         + "&date="
146                         + URLEncoder.encode(fullDate,
147                                 Constants.DEFAULT_ENCODING);
148             }
149
150             // Remove initial &, if any
151
if (sfxQuery.startsWith("&"))
152             {
153                 sfxQuery = sfxQuery.substring(1);
154             }
155
156             pageContext.getOut().print(sfxServer + sfxQuery);
157         }
158         catch (IOException JavaDoc ie)
159         {
160             throw new JspException JavaDoc(ie);
161         }
162
163         return SKIP_BODY;
164     }
165
166     /**
167      * Get the item this tag should display SFX Link for
168      *
169      * @return the item
170      */

171     public Item getItem()
172     {
173         return item;
174     }
175
176     /**
177      * Set the item this tag should display SFX Link for
178      *
179      * @param itemIn
180      * the item
181      */

182     public void setItem(Item itemIn)
183     {
184         item = itemIn;
185     }
186 }
187
Popular Tags