View Javadoc

1   /*
2    * Copyright 2004 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.nordija.tapestry.bayeux.downloads;
17  
18  import org.apache.tapestry.IMarkupWriter;
19  import org.apache.tapestry.IRequestCycle;
20  import org.apache.tapestry.engine.IEngineService;
21  import org.apache.tapestry.engine.ILink;
22  import org.apache.tapestry.link.AbstractLinkComponent;
23  
24  /**
25   * Renders a link to the stream service.
26   * <p/>
27   * The link will include an id for the resource to be streamed.
28   *
29   * @author Per Olesen www.nordija.com
30   * @author Jacob von Eyben www.nordija.com
31   * @version $Id: DownloadLink.java 119 2007-06-01 12:46:54Z jeyben $
32   * @see com.nordija.tapestry.bayeux.stream.StreamLink
33   * @see com.nordija.tapestry.bayeux.stream.StreamService
34   * @deprecated Will moste likly be removed in a later release. Use the {@link com.nordija.tapestry.bayeux.stream.StreamLink} instead.
35   */
36  public abstract class DownloadLink extends AbstractLinkComponent {
37  
38      public abstract String getDownloadResourceId();
39  
40      public abstract String getDownloadResourceSourceExtentionName();
41  
42      public abstract boolean isStateful();
43  
44      public abstract IEngineService getDownloadService();
45  
46      protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle) {
47          if (cycle.isRewinding()) {
48              return;
49          }
50  
51          ILink link = getDownloadService().getLink(isStateful(), new Object[]{getDownloadResourceId(), getDownloadResourceSourceExtentionName()});
52  
53          if (!isDisabled()) {
54              writer.begin("a");
55              writer.attribute("href", link.getURL());
56              renderInformalParameters(writer, cycle);
57          }
58          renderBody(writer, cycle);
59          if (!isDisabled()) {
60              writer.end();
61          }
62      }
63  
64  }