1 16 17 package org.apache.jetspeed.util.template; 18 19 import java.lang.reflect.Method ; 20 import org.apache.turbine.util.RunData; 21 import org.apache.turbine.util.DynamicURI; 22 import org.apache.turbine.services.pull.ApplicationTool; 23 import org.apache.jetspeed.services.resources.JetspeedResources; 24 25 33 public class ContentTemplateLink 34 extends DynamicURI 35 implements ApplicationTool 36 { 37 38 39 private String contextPath; 40 41 42 private String pathToContent; 43 44 46 private boolean useExternalForm = false; 47 48 49 public ContentTemplateLink () 50 { 51 } 52 53 54 public ContentTemplateLink (RunData data) 55 { 56 super(data); 57 initForceSecure(); 58 initContextPath(data); 59 } 60 61 68 public void init(Object data) 69 { 70 super.init((RunData)data); 71 initForceSecure(); 72 initContextPath(data); 73 } 74 75 79 protected void initContextPath(Object data) 80 { 81 try 82 { 83 Class runDataClass = RunData.class; 84 Method meth = runDataClass.getDeclaredMethod("getContextPath", null); 85 contextPath = (String )meth.invoke(data, null); 86 } 87 catch (Exception e) 88 { 89 94 contextPath = ""; 95 } 96 } 97 98 101 protected void initForceSecure() 102 { 103 if (JetspeedResources.getBoolean("force.ssl", false)) 105 { 106 setSecure(); 107 } 108 } 109 110 113 public void refresh() 114 { 115 } 117 118 123 public ContentTemplateLink getExternal() { 124 this.useExternalForm = true; 125 return this; 126 } 127 128 133 public ContentTemplateLink getAbsolute() { 134 this.useExternalForm = false; 135 return this; 136 } 137 138 145 public ContentTemplateLink setURI(String pathToContent) 146 { 147 this.pathToContent = pathToContent; 148 return this; 149 } 150 151 157 public String toString() 158 { 159 160 StringBuffer sb = new StringBuffer (); 161 162 if (useExternalForm) 164 { 165 String scheme = getServerScheme(); 166 sb.append ( getServerScheme() ); sb.append ("://"); 168 sb.append (getServerName()); int port = getServerPort(); 170 if( ( "http".equals( scheme ) && port != 80 ) || 171 ( "https".equals( scheme ) && port != 443 ) ) { sb.append (":"); 173 sb.append ( port ); } 175 } 176 sb.append (contextPath); sb.append ("/"); 179 if (pathToContent!=null) sb.append (pathToContent); 180 181 removePathInfo(); 184 removeQueryData(); 185 this.pathToContent=null; 186 187 return (sb.toString()); 188 } 189 190 } 191 | Popular Tags |