001: /*
002: * SFXLinkTag.java
003: *
004: * Version: $Revision: 1189 $
005: *
006: * Date: $Date: 2005-04-20 09:23:44 -0500 (Wed, 20 Apr 2005) $
007: *
008: * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts
009: * Institute of Technology. All rights reserved.
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are
013: * met:
014: *
015: * - Redistributions of source code must retain the above copyright
016: * notice, this list of conditions and the following disclaimer.
017: *
018: * - Redistributions in binary form must reproduce the above copyright
019: * notice, this list of conditions and the following disclaimer in the
020: * documentation and/or other materials provided with the distribution.
021: *
022: * - Neither the name of the Hewlett-Packard Company nor the name of the
023: * Massachusetts Institute of Technology nor the names of their
024: * contributors may be used to endorse or promote products derived from
025: * this software without specific prior written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
030: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
032: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
033: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
034: * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
035: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
036: * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
037: * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
038: * DAMAGE.
039: */
040: package org.dspace.app.webui.jsptag;
041:
042: import java.io.IOException;
043: import java.net.URLEncoder;
044:
045: import javax.servlet.jsp.JspException;
046: import javax.servlet.jsp.tagext.TagSupport;
047:
048: import org.dspace.content.DCPersonName;
049: import org.dspace.content.DCValue;
050: import org.dspace.content.Item;
051: import org.dspace.core.ConfigurationManager;
052: import org.dspace.core.Constants;
053:
054: /**
055: * Renders an SFX query link. Takes one attribute - "item" which must be an Item
056: * object.
057: *
058: * @author Robert Tansley
059: * @version $Revision: 1189 $
060: */
061: public class SFXLinkTag extends TagSupport {
062: /** Item to display SFX link for */
063: private Item item;
064:
065: public SFXLinkTag() {
066: super ();
067: }
068:
069: public int doStartTag() throws JspException {
070: try {
071: String sfxServer = ConfigurationManager
072: .getProperty("sfx.server.url");
073:
074: if (sfxServer == null) {
075: // No SFX server - SFX linking switched off
076: return SKIP_BODY;
077: }
078:
079: String sfxQuery = "";
080:
081: DCValue[] titles = item.getDC("title", null, Item.ANY);
082:
083: if (titles.length > 0) {
084: sfxQuery = sfxQuery
085: + "&title="
086: + URLEncoder.encode(titles[0].value,
087: Constants.DEFAULT_ENCODING);
088: }
089:
090: DCValue[] authors = item.getDC("contributor", "author",
091: Item.ANY);
092:
093: if (authors.length > 0) {
094: DCPersonName dpn = new DCPersonName(authors[0].value);
095: sfxQuery = sfxQuery
096: + "&aulast="
097: + URLEncoder.encode(dpn.getLastName(),
098: Constants.DEFAULT_ENCODING);
099: sfxQuery = sfxQuery
100: + "&aufirst="
101: + URLEncoder.encode(dpn.getFirstNames(),
102: Constants.DEFAULT_ENCODING);
103: }
104:
105: DCValue[] isbn = item.getDC("identifier", "isbn", Item.ANY);
106:
107: if (isbn.length > 0) {
108: sfxQuery = sfxQuery
109: + "&isbn="
110: + URLEncoder.encode(isbn[0].value,
111: Constants.DEFAULT_ENCODING);
112: }
113:
114: DCValue[] issn = item.getDC("identifier", "issn", Item.ANY);
115:
116: if (issn.length > 0) {
117: sfxQuery = sfxQuery
118: + "&issn="
119: + URLEncoder.encode(issn[0].value,
120: Constants.DEFAULT_ENCODING);
121: }
122:
123: DCValue[] dates = item.getDC("date", "issued", Item.ANY);
124:
125: if (dates.length > 0) {
126: String fullDate = dates[0].value;
127:
128: // Remove the time if there is one - day is greatest granularity
129: // for SFX
130: if (fullDate.length() > 10) {
131: fullDate = fullDate.substring(0, 10);
132: }
133:
134: sfxQuery = sfxQuery
135: + "&date="
136: + URLEncoder.encode(fullDate,
137: Constants.DEFAULT_ENCODING);
138: }
139:
140: // Remove initial &, if any
141: if (sfxQuery.startsWith("&")) {
142: sfxQuery = sfxQuery.substring(1);
143: }
144:
145: pageContext.getOut().print(sfxServer + sfxQuery);
146: } catch (IOException ie) {
147: throw new JspException(ie);
148: }
149:
150: return SKIP_BODY;
151: }
152:
153: /**
154: * Get the item this tag should display SFX Link for
155: *
156: * @return the item
157: */
158: public Item getItem() {
159: return item;
160: }
161:
162: /**
163: * Set the item this tag should display SFX Link for
164: *
165: * @param itemIn
166: * the item
167: */
168: public void setItem(Item itemIn) {
169: item = itemIn;
170: }
171: }
|