From: Antony C. <an...@sm...> - 2007-01-15 14:28:33
|
Hi Matthew, yes we are interested, how did you know?! Anyway we now have TinyURL running in CLAN and seems to be working just fine. Thanks, Antony On 15 Jan 2007, at 12:07, Matthew Buckett wrote: > Attached is a small patch I wrote a while ago that enables tinyurl.com > support for each resource from the top bar of Bodington. The patch is > against WebLearn but should apply with a little help to Bodington. Also > attached it a typo fix. > > Sending this to Bodington dev as other people may be interested in it > ;-) > > -- > Matthew Buckett > Index: > tomcatadd/webapps/bodington/templates/style_default/default/ > tinyurl.html > =================================================================== > --- > tomcatadd/webapps/bodington/templates/style_default/default/ > tinyurl.html (revision 0) > +++ > tomcatadd/webapps/bodington/templates/style_default/default/ > tinyurl.html (revision 1961) > @@ -0,0 +1,27 @@ > +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" > + "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> > + > +<html> > +<head> > + <building command=stylesheet> > + <title>Create TinyURL</title> > +</head> > + > +<body> > +<h2>Tiny URL</h2> > +<p> > +This is the shorterned URL for the current @Bodington@ resource. > +</p> > +<p> > +<building command=tinyurl name=dummy> > +</p> > +<h3>About</h3> > +<p> > +TinyURL allow you to generate shorter URLs for any resource in > @Bodington@ so > +that they become easier to email around. This service for this is > provided by > +<a target="_new" href="http://tinyurl.com/">tinyurl.com</a> which > allows you to > +easily generate short URLs for any page on the internet. > +</p> > + > +</body> > +</html> > > Property changes on: > tomcatadd/webapps/bodington/templates/style_default/default/ > tinyurl.html > ___________________________________________________________________ > Name: svn:eol-style > + native > Name: svn:keywords > + Author Date Id Revision > > Index: > tomcatadd/webapps/bodington/templates/style_default/default/top.html > =================================================================== > --- > tomcatadd/webapps/bodington/templates/style_default/default/top.html > (revision 1960) > +++ > tomcatadd/webapps/bodington/templates/style_default/default/top.html > (revision 1961) > @@ -93,6 +93,7 @@ > > <div id="Link"> > <span class="Text"> > + <a href="javascript:void > window.open('bs_template_tinyurl.html','day.getTime()', > 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,wi > dth=300,height=300');">TinyURL</a> > <if> > <test> > <call> > Index: src/org/bodington/servlet/facilities/Facility.java > =================================================================== > --- src/org/bodington/servlet/facilities/Facility.java (revision 1960) > +++ src/org/bodington/servlet/facilities/Facility.java (revision 1961) > @@ -99,6 +99,7 @@ > import org.bodington.util.DateFormatter; > import org.bodington.util.ResourceBundleHelper; > import org.bodington.util.TextUtils; > +import org.bodington.util.TinyUrl; > import org.bodington.util.html.HtmlFilterFactory; > import org.bodington.util.html.nodevisitors.BroadcastVisitor; > import org.bodington.util.html.nodevisitors.ReportingVisitor; > @@ -1477,6 +1478,12 @@ > uploadLimit( req, out ); > return; > } > + if (command.equalsIgnoreCase("tinyurl")) > + { > + if ( out != null ) > + tinyUrl( req, out ); > + return; > + } > // uhi:awc: added insert command to return url with username > appended to query - url supplied by insertname > if ( command.equalsIgnoreCase( "usernameloginurl" ) ) > { > @@ -1512,7 +1519,24 @@ > } > > > - /** > + private void tinyUrl(Request req, PrintWriter out) > + { > + TinyUrl tiny = new TinyUrl(); > + BodingtonURL url = new BodingtonURL(req); > + String resourceUrl = url.getResourceUrl(req.getResource()); > + log.debug("Getting tiny URL for "+ resourceUrl); > + String tinyUrl = tiny.shorten(resourceUrl); > + if (tinyUrl == null) > + { > + log.info("Problem getting tiny URL: "+ tiny.getError()); > + out.print("Problem creating URL"); > + } > + else > + out.print(tinyUrl); > + } > + > + > + /** > * Outputs the current upload limit. Actually is the request > * limit. > * @param req The Request. > Index: src/org/bodington/util/TinyUrl.java > =================================================================== > --- src/org/bodington/util/TinyUrl.java (revision 0) > +++ src/org/bodington/util/TinyUrl.java (revision 1961) > @@ -0,0 +1,136 @@ > +/* > ====================================================================== > +The Bodington System Software License, Version 1.0 > + > +Copyright (c) 2001 The University of Leeds. All rights reserved. > + > +Redistribution and use in source and binary forms, with or without > +modification, are permitted provided that the following conditions are > +met: > + > +1. Redistributions of source code must retain the above copyright > notice, > +this list of conditions and the following disclaimer. > + > +2. Redistributions in binary form must reproduce the above copyright > +notice, this list of conditions and the following disclaimer in the > +documentation and/or other materials provided with the distribution. > + > +3. The end-user documentation included with the redistribution, if > any, > +must include the following acknowledgement: "This product includes > +software developed by the University of Leeds > +(http://www.bodington.org/)." Alternately, this acknowledgement may > +appear in the software itself, if and wherever such third-party > +acknowledgements normally appear. > + > +4. The names "Bodington", "Nathan Bodington", "Bodington System", > +"Bodington Open Source Project", and "The University of Leeds" must > not be > +used to endorse or promote products derived from this software without > +prior written permission. For written permission, please contact > +d....@le.... > + > +5. The name "Bodington" may not appear in the name of products > derived > +from this software without prior written permission of the University > of > +Leeds. > + > +THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED > +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, TITLE, THE IMPLIED > WARRANTIES > +OF QUALITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN > NO > +EVENT SHALL THE UNIVERSITY OF LEEDS OR ITS CONTRIBUTORS BE LIABLE FOR > +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL > +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE > +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS > INTERRUPTION) > +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, > +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING > IN > +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE > +POSSIBILITY OF SUCH DAMAGE. > +========================================================= > + > +This software was originally created by the University of Leeds and > may contain voluntary > +contributions from others. For more information on the Bodington > Open Source Project, please > +see http://bodington.org/ > + > +====================================================================== > */ > + > +package org.bodington.util; > + > +import java.io.IOException; > +import java.util.regex.Pattern; > + > +import org.apache.commons.httpclient.HttpClient; > +import org.apache.commons.httpclient.HttpMethod; > +import org.apache.commons.httpclient.HttpStatus; > +import org.apache.commons.httpclient.NameValuePair; > +import org.apache.commons.httpclient.methods.GetMethod; > +import org.apache.commons.httpclient.methods.PostMethod; > + > +/** > + * Class to get a tiny URL from a longer URL. > + * @author buckett > + */ > +public class TinyUrl > +{ > + > + public static final String URL = > "http://tinyurl.com/api-create.php"; > + public static final String VERSION = "Java TinyURL 0.1"; > + > + private static final Pattern pattern = > Pattern.compile("http://tinyurl.com/\\w+"); > + > + private String error; > + > + /** > + * Attempts to shortern a URL > + * @param url The URL to shortern. > + * @return The tiny URL or null if it failed. > + */ > + public String shorten(String url) > + { > + String result = null; > + HttpClient client = new HttpClient(); > + PostMethod method = new PostMethod(URL); > + NameValuePair[] data = { > + new NameValuePair("url", url), > + new NameValuePair("source", VERSION) > + }; > + method.setRequestBody(data); > + try > + { > + client.executeMethod(method); > + if (method.getStatusCode() == HttpStatus.SC_OK) > + { > + String response = method.getResponseBodyAsString(); > + if ((response.indexOf("Error") == -1)) > + { > + if (pattern.matcher(response).matches()) > + { > + result = response; > + } > + else > + { > + error = "Response didn't match a valid tiny > url."; > + } > + } > + else > + { > + error = "Got error back."; > + } > + } > + else > + { > + error = "Bad HTTP code: "+ method.getStatusCode(); > + } > + } > + catch (IOException ioe) > + { > + error = "IO Problem connecting to "+ URL+ " "+ > ioe.getMessage(); > + } > + return result; > + } > + > + /** > + * @return Returns the last error we encountered. > + */ > + public String getError() > + { > + return error; > + } > + > +} > > Property changes on: src/org/bodington/util/TinyUrl.java > ___________________________________________________________________ > Name: svn:eol-style > + native > Name: svn:keywords > + Author Date Id Revision > > Index: tinyurl.html > =================================================================== > --- tinyurl.html (revision 1961) > +++ tinyurl.html (revision 3517) > @@ -18,7 +18,7 @@ > <h3>About</h3> > <p> > TinyURL allow you to generate shorter URLs for any resource in > @Bodington@ so > -that they become easier to email around. This service for this is > provided by > +that they become easier to email around. This service is provided by > <a target="_new" href="http://tinyurl.com/">tinyurl.com</a> which > allows you to > easily generate short URLs for any page on the internet. > </p> > <matthew.buckett.vcf>-------------------------------------------------- > ----------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV_________________________________ > ______________ > Bodington-developers mailing list > Bod...@li... > https://lists.sourceforge.net/lists/listinfo/bodington-developers |