|
|||||||||||||||||||
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 | |||||||||||||||
BaseTagWriter.java | 100% | 100% | 100% | 100% |
|
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 | 138 |
public void render(IMarkupWriter writer, IRequestCycle cycle) |
39 |
{ |
|
40 | 138 |
IPage page = cycle.getPage(); |
41 |
|
|
42 | 138 |
StringBuffer sb = new StringBuffer();
|
43 | 138 |
sb.append("/");
|
44 |
|
|
45 | 138 |
if (page.getNamespace().getId() == null) |
46 |
{ |
|
47 | 113 |
String name = page.getPageName(); |
48 | 113 |
int slashx = name.lastIndexOf('/');
|
49 |
|
|
50 |
// Include the directory and trailing slash.
|
|
51 | 113 |
if (slashx > 0)
|
52 | 1 |
sb.append(name.substring(0, slashx + 1)); |
53 |
} |
|
54 |
|
|
55 | 138 |
String url = cycle.getAbsoluteURL(sb.toString()); |
56 |
|
|
57 | 138 |
writer.beginEmpty("base");
|
58 | 138 |
writer.attribute("href", url);
|
59 |
|
|
60 | 138 |
writer.println(); |
61 |
} |
|
62 |
|
|
63 |
} |
|