1 /* 2 * Copyright 2008 FatWire Corporation. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package tools.gsf.facade.uri; 18 19 import COM.FutureTense.Interfaces.ICS; 20 import com.fatwire.assetapi.data.AssetId; 21 import tools.gsf.facade.runtag.render.GetTemplateUrl; 22 23 /** 24 * @author Dolf Dijkstra 25 * @since Mar 13, 2011 26 */ 27 public class TemplateUriBuilder { 28 29 private final GetTemplateUrl tag = new GetTemplateUrl(); 30 31 private String site; 32 33 /** 34 * Constructor with c and cid, with a wrapper . 35 * 36 * @param c current asset 37 * @param cid content id 38 * @param tname template name 39 * @param wrapper string value for wrapper 40 */ 41 public TemplateUriBuilder(final String c, final String cid, final String tname, final String wrapper) { 42 tag.setC(c); 43 tag.setCid(cid); 44 tag.setTname(tname); 45 tag.setWrapperpage(wrapper); 46 } 47 48 /** 49 * Constructor with c and cid, without a wrapper. 50 * 51 * @param c current asset 52 * @param cid content id 53 * @param tname template name 54 */ 55 public TemplateUriBuilder(final String c, final String cid, final String tname) { 56 tag.setC(c); 57 tag.setCid(cid); 58 tag.setTname(tname); 59 60 } 61 62 /** 63 * Constructor with AssetId and wrapper. 64 * 65 * @param id asset id 66 * @param tname template name 67 * @param wrapper string value for wrapper 68 */ 69 public TemplateUriBuilder(final AssetId id, final String tname, final String wrapper) { 70 this(id.getType(), Long.toString(id.getId()), tname, wrapper); 71 } 72 73 /** 74 * Constructor with AssetId, without a wrapper. 75 * 76 * @param id asset id 77 * @param tname template name 78 */ 79 public TemplateUriBuilder(final AssetId id, final String tname) { 80 this(id.getType(), Long.toString(id.getId()), tname); 81 } 82 83 /** 84 * Returns the uri to the asset rendered with the specified template and 85 * wrapper (if provided). 86 * 87 * @param ics Content Server context object 88 * @return the Content Server url. 89 * @see "tools.gsf.facade.runtag.AbstractTagRunner#execute(COM.FutureTense.Interfaces.ICS)" 90 */ 91 public String toURI(final ICS ics) { 92 tag.setContext(""); 93 if (site == null) { 94 tag.setSite(ics.GetVar("site")); 95 } 96 tag.setSlotname("irrelevant__"); 97 if (ics.GetVar("eid") != null) { 98 tag.setTid(ics.GetVar("eid")); 99 tag.setTtype("CSElement"); 100 } else { 101 tag.setTid(ics.GetVar("tid")); 102 tag.setTtype("Template"); 103 104 } 105 tag.setOutstr("uri__"); 106 tag.execute(ics); 107 final String uri = ics.GetVar("uri__"); 108 ics.RemoveVar("uri__"); 109 return uri; 110 } 111 112 /** 113 * @param name argument name 114 * @param value argument value 115 * @return this template uri builder 116 * @see "tools.gsf.facade.runtag.render.TagRunnerWithArguments#setArgument(java.lang.String, java.lang.String)" 117 */ 118 public TemplateUriBuilder argument(final String name, final String value) { 119 tag.setArgument(name, value); 120 return this; 121 } 122 123 /** 124 * @param s string value for assembler 125 * @return this template uri builder 126 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setAssembler(java.lang.String)" 127 */ 128 public TemplateUriBuilder assembler(final String s) { 129 tag.setAssembler(s); 130 return this; 131 } 132 133 /** 134 * @param s string value for authority 135 * @return this template uri builder 136 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setAuthority(java.lang.String)" 137 */ 138 public TemplateUriBuilder authority(final String s) { 139 tag.setAuthority(s); 140 return this; 141 } 142 143 /** 144 * @param s string value for container 145 * @return this template uri builder 146 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setContainer(java.lang.String)" 147 */ 148 public TemplateUriBuilder container(final String s) { 149 tag.setContainer(s); 150 return this; 151 } 152 153 /** 154 * @param s flag for dynamic 155 * @return this template uri builder 156 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setDynamic(java.lang.String)" 157 */ 158 public TemplateUriBuilder dynamic(final boolean s) { 159 tag.setDynamic(s); 160 return this; 161 } 162 163 /** 164 * @param s string value for fragment 165 * @return this template uri builder 166 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setFragment(java.lang.String)" 167 */ 168 public TemplateUriBuilder fragment(final String s) { 169 tag.setFragment(s); 170 return this; 171 } 172 173 /** 174 * @param s string value for packed arguments 175 * @return this template uri builder 176 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setPackedargs(java.lang.String)" 177 */ 178 public TemplateUriBuilder packedargs(final String s) { 179 tag.setPackedargs(s); 180 return this; 181 } 182 183 /** 184 * @param s flag for satellite 185 * @return this template uri builder 186 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setSatellite(java.lang.String)" 187 */ 188 public TemplateUriBuilder satellite(final boolean s) { 189 tag.setSatellite(s); 190 return this; 191 } 192 193 /** 194 * @param s string value for scheme 195 * @return this template uri builder 196 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setScheme(java.lang.String)" 197 */ 198 public TemplateUriBuilder scheme(final String s) { 199 tag.setScheme(s); 200 return this; 201 } 202 203 /** 204 * @param s string value for site 205 * @return this template uri builder 206 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setSite(java.lang.String)" 207 */ 208 public TemplateUriBuilder site(final String s) { 209 site = s; 210 tag.setSite(s); 211 return this; 212 } 213 214 /** 215 * @param s string value for wrapper page 216 * @return this template uri builder 217 * @see "tools.gsf.facade.runtag.render.GetTemplateUrl#setWrapperpage(java.lang.String)" 218 */ 219 public TemplateUriBuilder wrapper(final String s) { 220 tag.setWrapperpage(s); 221 return this; 222 } 223 224 }