Clover coverage report - brownies library - 1.0-beta-1
Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00
file stats: LOC: 148   Methods: 7
NCLOC: 85   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
AbstractScriptLinkRenderer.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * Joey and its relative products are published under the terms
 3   
  * of the Apache Software License.
 4   
  */
 5   
 /*
 6   
  * Created on 2004/01/04
 7   
  */
 8   
 package org.asyrinx.brownie.tapestry.components.link;
 9   
 
 10   
 import org.apache.tapestry.ApplicationRuntimeException;
 11   
 import org.apache.tapestry.IMarkupWriter;
 12   
 import org.apache.tapestry.IRequestCycle;
 13   
 import org.apache.tapestry.IScript;
 14   
 import org.apache.tapestry.Tapestry;
 15   
 import org.apache.tapestry.components.ILinkComponent;
 16   
 import org.apache.tapestry.engine.ILink;
 17   
 import org.apache.tapestry.html.Body;
 18   
 import org.apache.tapestry.link.ILinkRenderer;
 19   
 import org.asyrinx.brownie.tapestry.script.ScriptUtils;
 20   
 
 21   
 /**
 22   
  * @author akima
 23   
  */
 24   
 public abstract class AbstractScriptLinkRenderer implements ILinkRenderer {
 25   
 
 26   
     /**
 27   
      *  
 28   
      */
 29  0
     public AbstractScriptLinkRenderer(String scriptName) {
 30  0
         super();
 31  0
         this.scriptName = scriptName;
 32   
     }
 33   
 
 34   
     private final String scriptName;
 35   
 
 36   
     private IScript script = null;
 37   
 
 38   
     /**
 39   
      * @return
 40   
      */
 41  0
     protected IScript loadScript(ILinkComponent linkComponent) {
 42  0
         if (script == null)
 43  0
             script = ScriptUtils.loadScript(linkComponent, getScriptName());
 44  0
         return script;
 45   
     }
 46   
 
 47   
     /**
 48   
      * @return
 49   
      */
 50  0
     protected String getScriptName() {
 51  0
         return scriptName;
 52   
     }
 53   
 
 54   
     /**
 55   
      * @see org.apache.tapestry.link.ILinkRenderer#renderLink(org.apache.tapestry.IMarkupWriter,
 56   
      *      org.apache.tapestry.IRequestCycle,
 57   
      *      org.apache.tapestry.components.ILinkComponent)
 58   
      */
 59  0
     public void renderLink(IMarkupWriter writer, IRequestCycle cycle,
 60   
             ILinkComponent linkComponent) {
 61   
         // check valid cycle( including body ) and valid linkComponent
 62  0
         checkBeforeRender(cycle, linkComponent);
 63  0
         cycle.setAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME,
 64   
                 linkComponent);
 65  0
         try {
 66  0
             final IScript loadedScript = loadScript(linkComponent);
 67  0
             final boolean hasBody = getHasBody();
 68  0
             final boolean disabled = linkComponent.isDisabled();
 69   
             // template method to add script
 70  0
             if (!cycle.isRewinding()) {
 71  0
                 final Body body = Body.get(cycle);
 72  0
                 if (!disabled) {
 73  0
                     addScript(cycle, loadedScript, body);
 74   
                 }
 75   
                 // template method to render begin tag
 76  0
                 renderBeginTag(writer, cycle, linkComponent);
 77   
             }
 78   
             //beforeBodyRender(writer, cycle, linkComponent);
 79  0
             final IMarkupWriter wrappedWriter = (!disabled) ? writer
 80   
                     .getNestedWriter() : writer;
 81  0
             if (hasBody) {
 82   
                 // template method to render tag bodies
 83  0
                 renderBody(wrappedWriter, cycle, linkComponent);
 84  0
                 linkComponent.renderBody(wrappedWriter, cycle);
 85   
             }
 86  0
             if (!cycle.isRewinding()) {
 87   
                 //afterBodyRender(writer, cycle, linkComponent);
 88  0
                 linkComponent.renderAdditionalAttributes(writer, cycle);
 89  0
                 if (hasBody) {
 90  0
                     wrappedWriter.close();
 91   
                     // Close the <element> tag
 92  0
                     writer.end();
 93   
                 } else
 94  0
                     writer.closeTag();
 95   
             }
 96   
 
 97   
         } finally {
 98  0
             cycle.removeAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME);
 99   
         }
 100   
     }
 101   
 
 102  0
     protected void checkBeforeRender(IRequestCycle cycle,
 103   
             ILinkComponent linkComponent) {
 104  0
         if (cycle.getAttribute(Tapestry.LINK_COMPONENT_ATTRIBUTE_NAME) != null)
 105  0
             throw new ApplicationRuntimeException(Tapestry
 106   
                     .getMessage("AbstractLinkComponent.no-nesting"),
 107   
                     linkComponent, null, null);
 108  0
         if (!cycle.isRewinding()) {
 109  0
             final Body body = Body.get(cycle);
 110  0
             if (body == null)
 111  0
                 throw new ApplicationRuntimeException(
 112   
                         "must-be-contained-by-body", this, null, null);
 113   
         }
 114   
     }
 115   
 
 116   
     /**
 117   
      * Converts the EngineServiceLink into a URI or URL. This implementation
 118   
      * simply invokes {@link ILink#getURL(String, boolean)}.
 119   
      *  
 120   
      */
 121  0
     protected final String constructURL(ILink link, String anchor) {
 122  0
         return link.getURL(anchor, true);
 123   
     }
 124   
 
 125  0
     protected boolean getHasBody() {
 126  0
         return true;
 127   
     }
 128   
 
 129   
     abstract protected void addScript(IRequestCycle cycle, IScript addingScript,
 130   
             Body body);
 131   
 
 132   
     /**
 133   
      * @param writer
 134   
      * @param cycle
 135   
      * @param linkComponent
 136   
      */
 137   
     abstract protected void renderBeginTag(IMarkupWriter writer,
 138   
             IRequestCycle cycle, ILinkComponent linkComponent);
 139   
 
 140   
     /**
 141   
      * @param writer
 142   
      * @param cycle
 143   
      * @param linkComponent
 144   
      */
 145   
     abstract protected void renderBody(IMarkupWriter writer,
 146   
             IRequestCycle cycle, ILinkComponent linkComponent);
 147   
 
 148   
 }