1 package org.apache.turbine.services.pull.tools; 2 3 18 19 import org.apache.commons.configuration.Configuration; 20 21 import org.apache.commons.logging.Log; 22 import org.apache.commons.logging.LogFactory; 23 24 import org.apache.turbine.Turbine; 25 import org.apache.turbine.services.pull.ApplicationTool; 26 import org.apache.turbine.util.RunData; 27 import org.apache.turbine.util.parser.ParameterParser; 28 import org.apache.turbine.util.uri.TemplateURI; 29 30 53 54 public class TemplateLink 55 implements ApplicationTool 56 { 57 58 public static final String TEMPLATE_LINK_PREFIX = "tool.link"; 59 60 61 public static final String TEMPLATE_LINK_RELATIVE_KEY = "want.relative"; 62 63 64 public static final boolean TEMPLATE_LINK_RELATIVE_DEFAULT = false; 65 66 67 68 boolean wantRelative = false; 69 70 71 private String template = null; 72 73 74 private TemplateURI templateURI = null; 75 76 77 private static Log log = LogFactory.getLog(TemplateLink.class); 78 79 84 public TemplateLink() 85 { 86 } 87 88 96 97 104 public void init(Object data) 105 { 106 110 templateURI = new TemplateURI((RunData) data); 111 112 Configuration conf = 113 Turbine.getConfiguration().subset(TEMPLATE_LINK_PREFIX); 114 115 if (conf != null) 116 { 117 wantRelative = conf.getBoolean(TEMPLATE_LINK_RELATIVE_KEY, 118 TEMPLATE_LINK_RELATIVE_DEFAULT); 119 } 120 121 } 122 123 126 public void refresh() 127 { 128 } 130 131 140 141 148 public TemplateLink setEncodeURLOff() 149 { 150 templateURI.clearResponse(); 151 return this; 152 } 153 154 160 public TemplateLink setPage(String template) 161 { 162 log.debug("setPage(" + template + ")"); 163 this.template = template; 164 templateURI.setTemplate(template); 165 return this; 166 } 167 168 174 public String getPage() 175 { 176 return template; 177 } 178 179 188 public TemplateLink setAction(String action) 189 { 190 log.debug("setAction(" + action + ")"); 191 templateURI.setAction(action); 192 return this; 193 } 194 195 205 public TemplateLink setActionEvent(String action, String event) 206 { 207 log.debug("setActionEvent(" + action + ", "+ event +")"); 208 templateURI.setActionEvent(action, event); 209 return this; 210 } 211 212 221 public TemplateLink setEvent(String action) 222 { 223 log.debug("setEvent(" + action + ")"); 224 templateURI.setEvent(action); 225 return this; 226 } 227 228 237 public TemplateLink setScreen(String screen) 238 { 239 log.debug("setScreen(" + screen + ")"); 240 templateURI.setScreen(screen); 241 return this; 242 } 243 244 250 public TemplateLink setReference(String reference) 251 { 252 templateURI.setReference(reference); 253 return this; 254 } 255 256 261 public String getReference() 262 { 263 return templateURI.getReference(); 264 } 265 266 273 274 275 282 public TemplateLink addPathInfo(ParameterParser pp) 283 { 284 templateURI.addPathInfo(pp); 285 return this; 286 } 287 288 295 public TemplateLink addPathInfo(String name, Object value) 296 { 297 templateURI.addPathInfo(name, value); 298 return this; 299 } 300 301 308 public TemplateLink addPathInfo(String name, String value) 309 { 310 templateURI.addPathInfo(name, value); 311 return this; 312 } 313 314 321 public TemplateLink addPathInfo(String name, double value) 322 { 323 templateURI.addPathInfo(name, value); 324 return this; 325 } 326 327 334 public TemplateLink addPathInfo(String name, int value) 335 { 336 templateURI.addPathInfo(name, value); 337 return this; 338 } 339 340 347 public TemplateLink addPathInfo(String name, long value) 348 { 349 templateURI.addPathInfo(name, value); 350 return this; 351 } 352 353 360 public TemplateLink addQueryData(String name, Object value) 361 { 362 templateURI.addQueryData(name, value); 363 return this; 364 } 365 366 373 public TemplateLink addQueryData(String name, String value) 374 { 375 templateURI.addQueryData(name, value); 376 return this; 377 } 378 379 386 public TemplateLink addQueryData(String name, double value) 387 { 388 templateURI.addQueryData(name, value); 389 return this; 390 } 391 392 399 public TemplateLink addQueryData(String name, int value) 400 { 401 templateURI.addQueryData(name, value); 402 return this; 403 } 404 405 412 public TemplateLink addQueryData(String name, long value) 413 { 414 templateURI.addQueryData(name, value); 415 return this; 416 } 417 418 425 public TemplateLink addQueryData(ParameterParser pp) 426 { 427 templateURI.addQueryData(pp); 428 return this; 429 } 430 431 436 public TemplateLink removePathInfo() 437 { 438 templateURI.removePathInfo(); 439 return this; 440 } 441 442 448 public TemplateLink removePathInfo(String name) 449 { 450 templateURI.removePathInfo(name); 451 return this; 452 } 453 454 459 public TemplateLink removeQueryData() 460 { 461 templateURI.removeQueryData(); 462 return this; 463 } 464 465 471 public TemplateLink removeQueryData(String name) 472 { 473 templateURI.removeQueryData(name); 474 return this; 475 } 476 477 502 public String getAbsoluteLink() 503 { 504 String output = templateURI.getAbsoluteLink(); 505 506 templateURI.removePathInfo(); 509 templateURI.removeQueryData(); 510 511 return output; 512 } 513 514 515 540 public String getRelativeLink() 541 { 542 String output = templateURI.getRelativeLink(); 543 544 templateURI.removePathInfo(); 547 templateURI.removeQueryData(); 548 549 return output; 550 } 551 552 559 public String getLink() 560 { 561 return wantRelative ? 562 getRelativeLink() : getAbsoluteLink(); 563 } 564 565 574 public String getURI() 575 { 576 return wantRelative ? 577 templateURI.getRelativeLink() : templateURI.getAbsoluteLink(); 578 } 579 580 589 public String getAbsoluteURI() 590 { 591 return templateURI.getAbsoluteLink(); 592 } 593 594 603 public String getRelativeURI() 604 { 605 return templateURI.getRelativeLink(); 606 } 607 608 614 public String toString() 615 { 616 return getLink(); 617 } 618 } 619 | Popular Tags |