Clover coverage report - Code Coverage for tapestry release 4.0.2
Coverage timestamp: Thu Apr 13 2006 10:52:06 EDT
file stats: LOC: 63   Methods: 1
NCLOC: 24   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BaseTagWriter.java 100% 100% 100% 100%
coverage
 1    // Copyright 2005 The Apache Software Foundation
 2    //
 3    // Licensed under the Apache License, Version 2.0 (the "License");
 4    // you may not use this file except in compliance with the License.
 5    // You may obtain a copy of the License at
 6    //
 7    // http://www.apache.org/licenses/LICENSE-2.0
 8    //
 9    // Unless required by applicable law or agreed to in writing, software
 10    // distributed under the License is distributed on an "AS IS" BASIS,
 11    // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12    // See the License for the specific language governing permissions and
 13    // limitations under the License.
 14   
 15    package org.apache.tapestry.services.impl;
 16   
 17    import org.apache.tapestry.IMarkupWriter;
 18    import org.apache.tapestry.IPage;
 19    import org.apache.tapestry.IRender;
 20    import org.apache.tapestry.IRequestCycle;
 21   
 22    /**
 23    * Contains code needed to render the <base> tag for pages. The <base> tag ensures that
 24    * the base URL for the rendered page matches the location of the page template in the servlet
 25    * context, so that relative URLs to static assets (images, stylesheets, etc.) will be processed
 26    * correctly. This is important starting with release 4.0, where HTML templates are no longer
 27    * restricted to the servlet root.
 28    * <p>
 29    * Note that pages outside of the application namespace (provided by the framework itself, or in a
 30    * library) are "virtually located" in the application root.
 31    *
 32    * @author Howard M. Lewis Ship
 33    * @since 4.0
 34    */
 35    public class BaseTagWriter implements IRender
 36    {
 37   
 38  109 public void render(IMarkupWriter writer, IRequestCycle cycle)
 39    {
 40  109 IPage page = cycle.getPage();
 41   
 42  109 StringBuffer sb = new StringBuffer();
 43  109 sb.append("/");
 44   
 45  109 if (page.getNamespace().getId() == null)
 46    {
 47  89 String name = page.getPageName();
 48  89 int slashx = name.lastIndexOf('/');
 49   
 50    // Include the directory and trailing slash.
 51  89 if (slashx > 0)
 52  1 sb.append(name.substring(0, slashx + 1));
 53    }
 54   
 55  109 String url = cycle.getAbsoluteURL(sb.toString());
 56   
 57  109 writer.beginEmpty("base");
 58  109 writer.attribute("href", url);
 59   
 60  109 writer.println();
 61    }
 62   
 63    }