1 package org.apache.turbine.services.pull.tools; 2 3 18 19 import org.apache.commons.configuration.Configuration; 20 21 import org.apache.turbine.Turbine; 22 import org.apache.turbine.services.pull.ApplicationTool; 23 import org.apache.turbine.util.RunData; 24 import org.apache.turbine.util.uri.DataURI; 25 26 42 43 public class ContentTool 44 implements ApplicationTool 45 { 46 47 public static final String CONTENT_TOOL_PREFIX = "tool.content"; 48 49 55 public static final String CONTENT_TOOL_ENCODING_KEY = "want.encoding"; 56 57 58 public static final boolean CONTENT_TOOL_ENCODING_DEFAULT = false; 59 60 61 public static final String CONTENT_TOOL_RELATIVE_KEY = "want.relative"; 62 63 64 public static final boolean CONTENT_TOOL_RELATIVE_DEFAULT = false; 65 66 67 boolean wantEncoding = false; 68 69 70 boolean wantRelative = false; 71 72 73 private DataURI dataURI = null; 74 75 78 public ContentTool() 79 { 80 } 81 82 90 91 98 public void init(Object data) 99 { 100 dataURI = new DataURI((RunData) data); 104 105 Configuration conf = 106 Turbine.getConfiguration().subset(CONTENT_TOOL_PREFIX); 107 108 if (conf != null) 109 { 110 wantRelative = conf.getBoolean(CONTENT_TOOL_RELATIVE_KEY, 111 CONTENT_TOOL_RELATIVE_DEFAULT); 112 113 wantEncoding = conf.getBoolean(CONTENT_TOOL_ENCODING_KEY, 114 CONTENT_TOOL_ENCODING_DEFAULT); 115 } 116 117 if (!wantEncoding) 118 { 119 dataURI.clearResponse(); 120 } 121 } 122 123 126 public void refresh() 127 { 128 } 130 131 138 public String getURI(String path) 139 { 140 dataURI.setScriptName(path); 141 142 return wantRelative ? 143 dataURI.getRelativeLink() : dataURI.getAbsoluteLink(); 144 } 145 146 155 public String getAbsoluteURI(String path) 156 { 157 dataURI.setScriptName(path); 158 159 return dataURI.getAbsoluteLink(); 160 } 161 162 171 public String getRelativeURI(String path) 172 { 173 dataURI.setScriptName(path); 174 175 return dataURI.getRelativeLink(); 176 } 177 178 } 179 | Popular Tags |