| <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang=""><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>ContentTool.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Apache Turbine</a> > <a href="index.source.html" class="el_package">org.apache.turbine.services.pull.tools</a> > <span class="el_source">ContentTool.java</span></div><h1>ContentTool.java</h1><pre class="source lang-java linenums">package org.apache.turbine.services.pull.tools; |
| |
| |
| /* |
| * Licensed to the Apache Software Foundation (ASF) under one |
| * or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information |
| * regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the |
| * "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, |
| * software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| * KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| |
| |
| import org.apache.commons.configuration2.Configuration; |
| import org.apache.turbine.Turbine; |
| import org.apache.turbine.pipeline.PipelineData; |
| import org.apache.turbine.services.pull.ApplicationTool; |
| import org.apache.turbine.util.RunData; |
| import org.apache.turbine.util.uri.DataURI; |
| |
| /** |
| * Terribly simple tool to translate URIs into Turbine Links. |
| * Equivalent to URIUtils.getAbsoluteLink() in a pull tool. |
| * |
| * <p> |
| * If you're missing any routines from the 'old' $content tool concerning |
| * path_info or query data, you did use the wrong tool then. You should've used |
| * the TemplateLink tool which should be available as "$link" in your context. |
| * <p> |
| * |
| * This is an application pull tool for the template system. You should <b>not</b> |
| * use it in a normal application! |
| * |
| * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> |
| * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> |
| * @version $Id$ |
| */ |
| |
| public class ContentTool |
| implements ApplicationTool |
| { |
| /** Prefix for Parameters for this tool */ |
| public static final String CONTENT_TOOL_PREFIX = "tool.content"; |
| |
| /** |
| * Should this tool add Container Encoding to the URIs returned? |
| * True might cause trouble e.g. if you run with Apache HTTP Daemon / Tomcat Combo. |
| * |
| * Default is false (like Turbine 2.2) |
| */ |
| public static final String CONTENT_TOOL_ENCODING_KEY = "want.encoding"; |
| |
| /** Default Value for CONTENT_TOOL_ENCODING_KEY */ |
| public static final boolean CONTENT_TOOL_ENCODING_DEFAULT = false; |
| |
| /** Should this tool return relative URIs or absolute? Default: Absolute. */ |
| public static final String CONTENT_TOOL_RELATIVE_KEY = "want.relative"; |
| |
| /** Default Value for CONTENT_TOOL_RELATIVE_KEY */ |
| public static final boolean CONTENT_TOOL_RELATIVE_DEFAULT = false; |
| |
| /** Do we want the container to encode the response? */ |
| <span class="nc" id="L74"> boolean wantEncoding = false;</span> |
| |
| /** Do we want a relative link? */ |
| <span class="nc" id="L77"> boolean wantRelative = false;</span> |
| |
| /** Caches a DataURI object which provides the translation routines */ |
| <span class="nc" id="L80"> private DataURI dataURI = null;</span> |
| |
| /** |
| * C'tor |
| */ |
| public ContentTool() |
| <span class="nc" id="L86"> {</span> |
| // empty |
| <span class="nc" id="L88"> }</span> |
| |
| /* |
| * ======================================================================== |
| * |
| * Application Tool Interface |
| * |
| * ======================================================================== |
| * |
| */ |
| |
| /** |
| * This will initialize a ContentTool object that was |
| * constructed with the default constructor (ApplicationTool |
| * method). |
| * |
| * @param data assumed to be a PipelineData object |
| */ |
| @Override |
| public void init(Object data) |
| { |
| // we just blithely cast to RunData as if another object |
| // or null is passed in we'll throw an appropriate runtime |
| // exception. |
| <span class="nc bnc" id="L112" title="All 2 branches missed."> if (data instanceof PipelineData)</span> |
| { |
| <span class="nc" id="L114"> PipelineData pipelineData = (PipelineData) data;</span> |
| <span class="nc" id="L115"> RunData runData = (RunData)pipelineData;</span> |
| <span class="nc" id="L116"> dataURI = new DataURI(runData);</span> |
| <span class="nc" id="L117"> }</span> |
| else |
| { |
| <span class="nc" id="L120"> dataURI = new DataURI((RunData) data);</span> |
| |
| } |
| |
| Configuration conf = |
| <span class="nc" id="L125"> Turbine.getConfiguration().subset(CONTENT_TOOL_PREFIX);</span> |
| |
| <span class="nc bnc" id="L127" title="All 2 branches missed."> if (conf != null)</span> |
| { |
| <span class="nc" id="L129"> wantRelative = conf.getBoolean(CONTENT_TOOL_RELATIVE_KEY,</span> |
| CONTENT_TOOL_RELATIVE_DEFAULT); |
| |
| <span class="nc" id="L132"> wantEncoding = conf.getBoolean(CONTENT_TOOL_ENCODING_KEY,</span> |
| CONTENT_TOOL_ENCODING_DEFAULT); |
| } |
| |
| <span class="nc bnc" id="L136" title="All 2 branches missed."> if (!wantEncoding)</span> |
| { |
| <span class="nc" id="L138"> dataURI.clearResponse();</span> |
| } |
| <span class="nc" id="L140"> }</span> |
| |
| /** |
| * Refresh method - does nothing |
| */ |
| @Override |
| public void refresh() |
| { |
| // empty |
| <span class="nc" id="L149"> }</span> |
| |
| /** |
| * Returns the Turbine URI of a given Path |
| * |
| * @param path The path to translate |
| * |
| * @return Turbine translated absolute path |
| */ |
| public String getURI(String path) |
| { |
| <span class="nc" id="L160"> dataURI.setScriptName(path);</span> |
| |
| <span class="nc bnc" id="L162" title="All 2 branches missed."> return wantRelative ?</span> |
| <span class="nc" id="L163"> dataURI.getRelativeLink() : dataURI.getAbsoluteLink();</span> |
| } |
| |
| /** |
| * Returns the Turbine URI of a given Path. The |
| * result is always an absolute path starting with |
| * the server scheme (http/https). |
| * |
| * @param path The path to translate |
| * |
| * @return Turbine translated absolute path |
| */ |
| public String getAbsoluteURI(String path) |
| { |
| <span class="nc" id="L177"> dataURI.setScriptName(path);</span> |
| |
| <span class="nc" id="L179"> return dataURI.getAbsoluteLink();</span> |
| } |
| |
| /** |
| * Returns the Turbine URI of a given Path. The |
| * result is always relative to the context of |
| * the application. |
| * |
| * @param path The path to translate |
| * |
| * @return Turbine translated absolute path |
| */ |
| public String getRelativeURI(String path) |
| { |
| <span class="nc" id="L193"> dataURI.setScriptName(path);</span> |
| |
| <span class="nc" id="L195"> return dataURI.getRelativeLink();</span> |
| } |
| |
| } |
| </pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.12.202403310830</span></div></body></html> |