001: /*
002: * FrontPageSearch.java
003: *
004: * Version: $Revision: 1.1 $
005: *
006: * Date: $Date: 2006/08/08 20:58:15 $
007: *
008: * Copyright (c) 2002, 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.xmlui.aspect.artifactbrowser;
041:
042: import java.io.IOException;
043: import java.io.Serializable;
044: import java.sql.SQLException;
045:
046: import org.apache.cocoon.caching.CacheableProcessingComponent;
047: import org.apache.excalibur.source.SourceValidity;
048: import org.apache.excalibur.source.impl.validity.NOPValidity;
049: import org.dspace.app.xmlui.cocoon.AbstractDSpaceTransformer;
050: import org.dspace.app.xmlui.utils.UIException;
051: import org.dspace.app.xmlui.wing.Message;
052: import org.dspace.app.xmlui.wing.WingException;
053: import org.dspace.app.xmlui.wing.element.Body;
054: import org.dspace.app.xmlui.wing.element.Division;
055: import org.dspace.app.xmlui.wing.element.PageMeta;
056: import org.dspace.app.xmlui.wing.element.Para;
057: import org.dspace.authorize.AuthorizeException;
058: import org.dspace.core.ConfigurationManager;
059: import org.xml.sax.SAXException;
060:
061: /**
062: * This simple component will add a Search Box. It is intended for use on the front page.
063: *
064: * @author Scott Phillips
065: */
066: public class FrontPageSearch extends AbstractDSpaceTransformer
067: implements CacheableProcessingComponent {
068: /** Language Strings */
069:
070: public static final Message T_dspace_home = message("xmlui.general.dspace_home");
071:
072: private static final Message T_head = message("xmlui.ArtifactBrowser.FrontPageSearch.head");
073:
074: private static final Message T_para1 = message("xmlui.ArtifactBrowser.FrontPageSearch.para1");
075:
076: private static final Message T_go = message("xmlui.general.go");
077:
078: /**
079: * Generate the unique caching key.
080: * This key must be unique inside the space of this component.
081: */
082: public Serializable getKey() {
083: return "1";
084: }
085:
086: /**
087: * Generate the cache validity object.
088: */
089: public SourceValidity getValidity() {
090: return NOPValidity.SHARED_INSTANCE;
091: }
092:
093: /**
094: * Add a page title and trail links.
095: */
096: public void addPageMeta(PageMeta pageMeta) throws SAXException,
097: WingException, UIException, SQLException, IOException,
098: AuthorizeException {
099: pageMeta.addMetadata("title").addContent(T_dspace_home);
100: pageMeta.addTrailLink(contextPath, T_dspace_home);
101:
102: // Add RSS links if available
103: String formats = ConfigurationManager
104: .getProperty("webui.feed.formats");
105: if (formats != null) {
106: for (String format : formats.split(",")) {
107: // Remove the protocol number, i.e. just list 'rss' or' atom'
108: String[] parts = format.split("_");
109: if (parts.length < 1)
110: continue;
111:
112: String feedFormat = parts[0].trim() + "+xml";
113:
114: String feedURL = contextPath + "/feed/" + format.trim()
115: + "/site";
116: pageMeta.addMetadata("feed", feedFormat).addContent(
117: feedURL);
118: }
119: }
120: }
121:
122: public void addBody(Body body) throws SAXException, WingException,
123: UIException, SQLException, IOException, AuthorizeException {
124: Division search = body.addInteractiveDivision(
125: "front-page-search", contextPath + "/search",
126: Division.METHOD_POST, "primary");
127:
128: search.setHead(T_head);
129:
130: search.addPara(T_para1);
131:
132: Para fields = search.addPara();
133: fields.addText("query");
134: fields.addButton("submit").setValue(T_go);
135: }
136: }
|