Return-Path: Delivered-To: apmail-cocoon-dev-archive@www.apache.org Received: (qmail 85303 invoked from network); 10 Oct 2003 10:06:44 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 10 Oct 2003 10:06:44 -0000 Received: (qmail 13940 invoked by uid 500); 10 Oct 2003 10:06:13 -0000 Delivered-To: apmail-cocoon-dev-archive@cocoon.apache.org Received: (qmail 13893 invoked by uid 500); 10 Oct 2003 10:06:11 -0000 Mailing-List: contact dev-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: dev@cocoon.apache.org Delivered-To: mailing list dev@cocoon.apache.org Received: (qmail 13880 invoked from network); 10 Oct 2003 10:06:11 -0000 Received: from unknown (HELO ns.alma.nu) (195.84.38.252) by daedalus.apache.org with SMTP; 10 Oct 2003 10:06:11 -0000 Received: from pc40-128.raa.se ([193.10.40.128]) by ns.alma.nu (JAMES SMTP Server 2.1) with SMTP ID 917 for ; Fri, 10 Oct 2003 12:06:23 +0200 (CEST) Message-ID: <3F86849A.90707@curalia.se> Date: Fri, 10 Oct 2003 12:06:18 +0200 From: =?ISO-8859-1?Q?Martin_Kal=E9n?= Organization: Curalia AB User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3b) Gecko/20030210 X-Accept-Language: sv, en, en-us MIME-Version: 1.0 To: dev@cocoon.apache.org Subject: [newbie] UrlExistsSelector Content-Type: multipart/mixed; boundary="------------070309090500010106040709" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------070309090500010106040709 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Greetings developers, as a newbie to the wonderful world of Cocoon sitemaps I was struggling with the problem of using a selector to determine if an external HTTP URL was available. * Problem description: A pipeline matcher with the following steps is triggered: 1. XSP generation 2. cinclude transformation 3. XSLT transformation 4. HTML serialization The cinclude in step 2 triggers another cocoon pipeline. XSP snippet: Pipeline #2: 1. (what I wanted) map:select and generation based on status of external HTTP URL 2. XSLT transformation 3. XML serialization * My soloution: I was first trying the map:select with the org.apache.cocoon.selection.ResourceExistsSelector until I found out that this was only for content within the current servlet context. I then wrote the attached (trivial) UrlExistsSelector and used this one for step 1 in pipeline #2. This works, but might have som implications in security/performance (no timeout handling) etc. etc. that I just don't see because I'm new to Cocoon. Any comments? Other soloutions? TIA, Martin -- Martin Kal�n Curalia AB Web: http://www.curalia.se Orrspelsv�gen 2B Mail: info@curalia.se SE-182 79 Stocksund Tel: +46-8-410 064 40 --------------070309090500010106040709 Content-Type: text/html; name="UrlExistsSelector.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="UrlExistsSelector.java" import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.selection.Selector; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Map; /** * Selects the first of a set of URLs that can be connected to. *

* Like {@link org.apache.cocoon.selection.ResourceExistsSelector}, * but works with java.net.URL instead of using the servlet * containter's context resolving. * * @author Martin Kalén * @version CVS $Id: UrlExistsSelector.java,v 1.1 2003/10/10 09:08:47 martin Exp $ */ public class UrlExistsSelector extends AbstractLogEnabled implements ThreadSafe, Selector { public boolean select(String expression, Map objectModel, Parameters parameters) { try { URL url = new URL(expression); URLConnection connection = url.openConnection(); connection.connect(); return true; } catch (MalformedURLException e) { StringBuffer message = new StringBuffer(); message.append("Selector expression '"); message.append(expression); message.append("' is not a valid URL"); getLogger().warn(message.toString()); return false; } catch (Exception e) { return false; } } } --------------070309090500010106040709--