Update of /cvsroot/wicket-stuff/wicket-flickr/src/main/java/wicket/examples/flickr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1735/src/main/java/wicket/examples/flickr Added Files: FlickrApplication.java Index.html FlickrDao.java HelpInfo.java FlickrSession.java Index.java Start.java Log Message: initial checking --- NEW FILE: Index.java --- package wicket.examples.flickr; import wicket.markup.html.WebPage; import wicket.markup.html.link.BookmarkablePageLink; public class Index extends WebPage { /** Used for serialization. */ private static final long serialVersionUID = 1L; public Index() { // show a warning that the flickr api key wasn't set in the web.xml file. add(new HelpInfo("noKey")); add(new BookmarkablePageLink("standard", wicket.examples.flickr.standard.Index.class)); add(new BookmarkablePageLink("ajax", wicket.examples.flickr.ajax.Index.class)); } } --- NEW FILE: Index.html --- <html> <head> <link rel="stylesheet" href="flickr.css" type="text/css" /> <title>Wicket Flickr Demo</title> </head> <body> <form> <h1>Wicket Flickr Demo</h1> <p> This application demonstrates a use of a new <a href="http://wicket.sf.net">Wicket</a> feature: partial page rendering for Ajax type applications. It uses the Ruby on Rails video demo application which caused quite a stirr in the Web Application community. </p> <p> Although this is a fully functional demo, it depends on currently experimental features of Wicket and the techniques used may not be considered a best practise. </p> <span wicket:id="noKey"> <h3>Before you start</h3> <p> Please provide the application with your own Flickr API Key, otherwise the service won't accept your requests. You can set this key in the <i>web.xml</i> deployment descriptor, using the '<tt>flickr_api</tt>' init parameter to the Wicket servlet. </p> <p> The application will not contact Flickr, but instead use pre-defined search results. The following search keys are available: <ul> <li>flower</li> <li>color</li> </ul> </p> </span> <h3>Select the path</h3> <ul> <li><a href="#" wicket:id="standard">Demo without Ajax</a></li> <li><a href="#" wicket:id="ajax">Demo using Ajax</a></li> </ul> <h3>Thanks and legal stuff</h3> <p> This demo uses the <a href="http://www.sf.net/projects/flickrj">FlickrJ</a> library for communication with the <a href="http://www.flickr.com">Flickr</a> service. This demo is not affiliated with <a href="http://www.flickr.com">Flickr</a>. Flickr is a trademark of Yahoo! Inc. </p> </form> </body> </html> --- NEW FILE: HelpInfo.java --- package wicket.examples.flickr; import wicket.markup.html.WebMarkupContainer; import wicket.util.string.Strings; /** * Markup container that is only visible when no flickr key was provided * in the servlet init parameters. * * @author Martijn Dashorst */ public class HelpInfo extends WebMarkupContainer { /** for serialization. */ private static final long serialVersionUID = 1L; public HelpInfo(String id) { super(id); } @Override public boolean isVisible() { return Strings.isEmpty(FlickrDao.FLICKR_KEY); } } --- NEW FILE: FlickrSession.java --- package wicket.examples.flickr; import wicket.protocol.http.WebApplication; import wicket.protocol.http.WebSession; public class FlickrSession extends WebSession { /** used for serialization. */ private static final long serialVersionUID = 3946644471811858975L; /** The user supplied Flickr api key. */ private String flickrApiKey; /** Constructor. */ protected FlickrSession(WebApplication application) { super(application); } /** * @return Returns the flickrApiKey. */ public String getFlickrApiKey() { return flickrApiKey; } /** * @param flickrApiKey The flickrApiKey to set. */ public void setFlickrApiKey(String flickrApiKey) { this.flickrApiKey = flickrApiKey; } } --- NEW FILE: FlickrApplication.java --- package wicket.examples.flickr; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import wicket.protocol.http.WebApplication; /** * Runs the QuickStartApplication when invoked from command line. */ public class FlickrApplication extends WebApplication { /** Logging */ private static final Log log = LogFactory.getLog(FlickrApplication.class); /** * Constructor */ public FlickrApplication() { configure("development"); } @Override protected void init() { FlickrDao.FLICKR_KEY = getWicketServlet().getInitParameter("flickr_key"); } @Override public Class getHomePage() { return Index.class; } } --- NEW FILE: Start.java --- /* * $Id: Start.java,v 1.1 2006/01/29 21:52:58 dashorst Exp $ * $Revision: 1.1 $ * $Date: 2006/01/29 21:52:58 $ * * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package wicket.examples.flickr; import java.net.URL; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.mortbay.jetty.Server; /** * Seperate startup class for people that want to run the examples directly. */ public class Start { /** * Used for logging. */ private static Log log = LogFactory.getLog(Start.class); /** * Construct. */ Start() { super(); } /** * Main function, starts the jetty server. * * @param args */ public static void main(String[] args) { Server jettyServer = null; try { URL jettyConfig = new URL("file:src/main/resources/jetty-config.xml"); if (jettyConfig == null) { log.fatal("Unable to locate jetty-test-config.xml on the classpath"); } jettyServer = new Server(jettyConfig); jettyServer.start(); } catch (Exception e) { log.fatal("Could not start the Jetty server: " + e); if (jettyServer != null) { try { jettyServer.stop(); } catch (InterruptedException e1) { log.fatal("Unable to stop the jetty server: " + e1); } } } } } --- NEW FILE: FlickrDao.java --- package wicket.examples.flickr; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Vector; import com.aetrion.flickr.Flickr; import com.aetrion.flickr.photos.Photo; import com.aetrion.flickr.photos.PhotoList; import com.aetrion.flickr.photos.PhotosInterface; import com.aetrion.flickr.photos.SearchParameters; /** * Wrapper around the Flickr Api. */ public class FlickrDao { /** My API key, is set using a web.xml init-parameter. */ public static String FLICKR_KEY; /** * Constant URL's for working without FLICKR_KEY. */ private static String[] FLOWERS = { "http://static.flickr.com/14/92739343_d4dccf9f63_s.jpg", "http://static.flickr.com/23/92738399_5d7326174b_s.jpg", "http://static.flickr.com/32/92732056_2e4a2aa606_s.jpg", "http://static.flickr.com/39/92731528_773bf59758_s.jpg", "http://static.flickr.com/26/92731189_38770b3e99_s.jpg", "http://static.flickr.com/11/92729727_bdf2534605_s.jpg", "http://static.flickr.com/40/92727009_6da0730cd2_s.jpg", "http://static.flickr.com/23/92725895_97001944b1_s.jpg", "http://static.flickr.com/11/92724122_13b3309c03_s.jpg", "http://static.flickr.com/38/92724125_d8da613ff1_s.jpg", "http://static.flickr.com/19/92724124_97b0224d27_s.jpg", "http://static.flickr.com/22/92724119_d9b514b37d_s.jpg", "http://static.flickr.com/40/92723090_ccd03ab825_s.jpg", "http://static.flickr.com/32/92722625_62e3006f54_s.jpg", "http://static.flickr.com/42/92719038_e7ead83db8_s.jpg", "http://static.flickr.com/38/92718029_c747e0c27d_s.jpg", "http://static.flickr.com/27/92717023_1d067e8447_s.jpg", "http://static.flickr.com/33/92715696_f741fb7f81_s.jpg", "http://static.flickr.com/14/92715694_94268c081c_s.jpg", "http://static.flickr.com/34/92713820_344b8c5fce_s.jpg", "http://static.flickr.com/28/92706830_2c69f32291_s.jpg", "http://static.flickr.com/31/92706702_d108030343_s.jpg", "http://static.flickr.com/41/92705998_a28a549a6e_s.jpg", "http://static.flickr.com/16/92702814_4100c2ea83_s.jpg", }; /** * Constant URL's for working without FLICKR_KEY. */ private static String[] COLORS = { "http://static.flickr.com/21/92736979_cea216909c_s.jpg", "http://static.flickr.com/27/92736980_7bfc650a43_s.jpg", "http://static.flickr.com/38/92736981_343e1bb5ce_s.jpg", "http://static.flickr.com/39/92731528_773bf59758_s.jpg", "http://static.flickr.com/11/92729727_bdf2534605_s.jpg", "http://static.flickr.com/34/92727348_d1b9dad364_s.jpg", "http://static.flickr.com/31/92726872_f7fe63c0e0_s.jpg", "http://static.flickr.com/11/92723613_a32e6257fc_s.jpg", "http://static.flickr.com/30/92723617_509d11680a_s.jpg", "http://static.flickr.com/12/92723618_3ecd777ae6_s.jpg", "http://static.flickr.com/36/92722165_3e111b5a90_s.jpg", "http://static.flickr.com/43/92722160_65446d5c7c_s.jpg", "http://static.flickr.com/43/92722171_87605f6278_s.jpg", "http://static.flickr.com/33/92722163_6a41b16ee9_s.jpg", "http://static.flickr.com/37/92722169_b04de816cf_s.jpg", "http://static.flickr.com/22/92722167_be781ae2d4_s.jpg", "http://static.flickr.com/11/92722015_4a52eae106_s.jpg", "http://static.flickr.com/43/92722014_79e0637cb8_s.jpg", "http://static.flickr.com/27/92720508_892fc053a8_s.jpg", "http://static.flickr.com/35/92717738_d2e3efad75_s.jpg", "http://static.flickr.com/37/92717389_3bb8e479dc_s.jpg", "http://static.flickr.com/24/92717361_c29577e8fd_s.jpg", "http://static.flickr.com/15/92717304_b52bf7cab2_s.jpg", "http://static.flickr.com/43/92717275_5327959a4c_s.jpg", }; /** * Gets static url's to 75x75px thumbnails of images which are tagged with * the supplied tags. * * @param tags * the tags used for searching the Flickr site * @return the list of static url's to the found images */ public List<String> getSmallSquareImages(String[] tags) { if (FLICKR_KEY == null) { return getImagesOffline(tags); } return getImagesOnline(tags); } /** * Performs a dummy flickr lookup with stored image URL's. * @param tags * @return */ private List<String> getImagesOffline(String[] tags) { if (tags.length > 0) { if ("flower".equalsIgnoreCase(tags[0])) { return Arrays.asList(FLOWERS); } else if ("color".equalsIgnoreCase(tags[0])) { return Arrays.asList(COLORS); } } return Arrays.asList(new String[] {}); } /** * Performs a one and only flickr lookup with the provided flickr key. * @param tags * @return */ private List<String> getImagesOnline(String[] tags) { List<String> images = new Vector<String>(); Flickr flickr = new Flickr(FLICKR_KEY); PhotosInterface photosInterface = flickr.getPhotosInterface(); try { SearchParameters pars = new SearchParameters(); pars.setTags(tags); PhotoList list = photosInterface.search(pars, 24, 1); for (Iterator iter = list.iterator(); iter.hasNext();) { Photo element = (Photo) iter.next(); String url = "http://static.flickr.com/" + element.getServer() + "/" + element.getId() + "_" + element.getSecret() + "_s.jpg"; images.add(url); } } catch (Exception e) { e.printStackTrace(); } return images; } } |