1 16 package org.apache.jetspeed.portal.portlets; 17 18 import org.apache.ecs.ConcreteElement; 20 import org.apache.ecs.StringElement; 21 22 import org.apache.jetspeed.portal.PortletException; 24 import org.apache.jetspeed.portal.PortletConfig; 25 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 26 import org.apache.jetspeed.services.logging.JetspeedLogger; 27 28 import org.apache.turbine.util.RunData; 30 import org.apache.turbine.util.ServerData; 31 import org.apache.turbine.services.servlet.TurbineServlet; 32 import org.apache.turbine.TurbineConstants; 33 import org.apache.turbine.util.DynamicURI; 34 35 import java.util.Hashtable ; 37 38 83 84 public class IFramePortlet extends AbstractInstancePortlet 85 { 86 89 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(IFramePortlet.class.getName()); 90 91 static final String DEFAULT_NOTSUPP_MSG = 92 "[Your user agent does not support inline frames or is currently" 93 + " configured not to display frames]"; 94 95 static final String NO_SOURCE_MSG = "Please customize source for this IFrame"; 96 97 static final String DEFAULT_SOURCE = "http://127.0.0.1"; 98 static final String DEFAULT_WIDTH = null; 99 static final String DEFAULT_HEIGHT = null; 100 static final String DEFAULT_SCROLLING = "auto"; 101 static final String DEFAULT_FRAMEBORDER = "1"; 102 103 static final String PARAM_SOURCE = "source"; 104 static final String PARAM_WIDTH = "width"; 105 static final String PARAM_HEIGHT = "height"; 106 static final String PARAM_SCROLLING = "scrolling"; 107 static final String PARAM_FRAMEBORDER = "frameborder"; 108 static final String PARAM_NAME = "name"; 109 static final String PARAM_STYLE = "style"; 110 static final String PARAM_MARGINWIDTH = "marginwidth"; 111 static final String PARAM_MARGINHEIGHT = "marginheight"; 112 static final String PARAM_REFRESH = "refresh"; 113 static final String PARAM_ALIGN = "align"; 114 static final String WEBAPPROOT = "${" + TurbineConstants.WEBAPP_ROOT + "}"; 115 116 private String iSource = DEFAULT_SOURCE; 117 private String iWidth = DEFAULT_WIDTH; 118 private String iHeight = DEFAULT_HEIGHT; 119 private String iScrolling = DEFAULT_SCROLLING; 120 private String iFrameBorder = DEFAULT_FRAMEBORDER; 121 private String iMarginWidth = null; 122 private String iMarginHeight = null; 123 private String iStyle = null; 124 private String iName = null; 125 private String iRefresh = null; 126 private String iAlign = null; 127 128 134 public void setSource(String source) 135 { 136 if (source != null) 137 { 138 Hashtable parms = new Hashtable (); 140 if (source.indexOf("${") >= 0) 141 { 142 parms.putAll(this.getPortletConfig().getInitParameters()); 144 145 try 147 { 148 ServerData sd = new ServerData(TurbineServlet.getServerName(), 149 Integer.parseInt(TurbineServlet.getServerPort()), 150 TurbineServlet.getServerScheme(), 151 TurbineServlet.getContextPath(), 152 TurbineServlet.getContextPath()); 153 DynamicURI uri = new DynamicURI(sd); 154 parms.put(TurbineConstants.WEBAPP_ROOT, uri.toString() + "/"); 155 } 156 catch (Exception e) 157 { 158 logger.error("Exception", e); 159 } 160 parms.put("portlet", this.getName()); 162 } 163 164 this.iSource = org.apache.jetspeed.util.StringUtils.replaceVars(source, parms); 165 } 166 167 } 168 169 175 public void setScrolling(String scrolling) 176 { 177 iScrolling = scrolling; 178 } 179 180 181 187 public void setWidth(String width) 188 { 189 iWidth = width; 190 } 191 192 193 199 public void setHeight(String height) 200 { 201 iHeight = height; 202 } 203 204 205 211 public void setFrameBorder(String frameBorder) 212 { 213 iFrameBorder = frameBorder; 214 } 215 216 221 public void setMarginWidth(String width) 222 { 223 224 iMarginWidth = width; 225 } 226 227 232 public void setMarginHeight(String height) 233 { 234 235 iMarginHeight = height; 236 } 237 238 243 public void setAlign(String value) 244 { 245 246 iAlign = value; 247 } 248 249 254 public void setRefresh(String value) 255 { 256 257 iRefresh = value; 258 } 259 260 261 272 public void setStyle(String value) 273 { 274 275 iStyle = value; 276 } 277 278 284 public void setFrameName(String value) 285 { 286 287 iName = value; 288 } 289 290 296 public ConcreteElement getContent(RunData runData) 297 { 298 299 if (org.apache.jetspeed.util.PortletSessionState.getPortletConfigChanged(this, runData)) 303 { 304 try { 305 this.init(); 306 } 307 catch (PortletException pe) 308 { 309 logger.error("Exception", pe); 310 } 311 } 312 313 StringBuffer text = new StringBuffer (); 314 315 if (getSource() == null || getSource().trim().length() == 0) 316 { 317 text.append(NO_SOURCE_MSG); 318 return (new StringElement(text.toString())); 319 } 320 321 text.append("<IFRAME "); 322 323 text.append("src = \"" + getSource() + "\" "); 324 if (getWidth() != null) 325 { 326 text.append("width = \"" + getWidth() + "\" "); 327 } 328 329 if (getHeight() != null) 330 { 331 text.append("height = \"" + getHeight() + "\" "); 332 } 333 334 if (getFrameName() != null) 335 { 336 text.append("name = \"" + getFrameName() + "\" "); 337 } 338 339 if (getStyle() != null) 340 { 341 text.append("style = \"" + getStyle() + "\" "); 342 } 343 344 if (getMarginWidth() != null) 345 { 346 text.append("marginwidth = \"" + getMarginWidth() + "\" "); 347 } 348 349 if (getMarginHeight() != null) 350 { 351 text.append("marginheight = \"" + getMarginHeight() + "\" "); 352 } 353 354 if (getAlign() != null) 355 { 356 text.append("align = \"" + getAlign() + "\" "); 357 } 358 359 text.append("scrolling = \"" + getScrolling() + "\" "); 360 text.append("frameborder = \"" + getFrameBorder() + "\" "); 361 text.append(">"); 362 363 text.append("</IFRAME>"); 364 return (new StringElement(text.toString())); 365 } 366 367 368 373 public String getSource() 374 { 375 return iSource; 376 } 377 378 379 384 public String getScrolling() 385 { 386 return iScrolling; 387 } 388 389 390 395 public String getWidth() 396 { 397 return iWidth; 398 } 399 400 401 406 public String getHeight() 407 { 408 return iHeight; 409 } 410 411 412 417 public String getFrameBorder() 418 { 419 String trueValues = "1,yes,true"; 420 if (iFrameBorder != null && trueValues.indexOf(iFrameBorder) >= 0) 421 { 422 return "1"; 423 } 424 return "0"; 425 } 426 427 428 435 public String getNotSupportedMsg() 436 { 437 return DEFAULT_NOTSUPP_MSG; 438 } 439 440 445 public String getAlign() 446 { 447 448 return iAlign; 449 } 450 451 456 public String getStyle() 457 { 458 459 return iStyle; 460 } 461 462 467 public String getFrameName() 468 { 469 470 return iName; 471 } 472 473 478 public String getRefresh() 479 { 480 481 return iRefresh; 482 } 483 484 489 public String getMarginHeight() 490 { 491 492 return iMarginHeight; 493 } 494 495 500 public String getMarginWidth() 501 { 502 503 return iMarginWidth; 504 } 505 506 511 public void init() throws PortletException 512 { 513 super.init(); 515 516 try 517 { 518 PortletConfig config = this.getPortletConfig(); 519 String param = null; 520 521 param = config.getInitParameter(PARAM_SOURCE); 522 if (param != null) 523 { 524 setSource(param); 525 } 526 527 param = config.getInitParameter(PARAM_WIDTH); 528 if (param != null) 529 { 530 setWidth(param); 531 } 532 533 param = config.getInitParameter(PARAM_HEIGHT); 534 if (param != null) 535 { 536 setHeight(param); 537 } 538 539 param = config.getInitParameter(PARAM_SCROLLING); 540 if (param != null) 541 { 542 setScrolling(param); 543 } 544 545 param = config.getInitParameter(PARAM_FRAMEBORDER); 546 if (param != null) 547 { 548 setFrameBorder(param); 549 } 550 551 param = config.getInitParameter(PARAM_STYLE); 552 if (param != null) 553 { 554 setStyle(param); 555 } 556 557 param = config.getInitParameter(PARAM_NAME); 558 if (param != null) 559 { 560 setFrameName(param); 561 } 562 563 param = config.getInitParameter(PARAM_REFRESH); 564 if (param != null) 565 { 566 setRefresh(param); 567 } 568 569 param = config.getInitParameter(PARAM_MARGINWIDTH); 570 if (param != null) 571 { 572 setMarginWidth(param); 573 } 574 575 param = config.getInitParameter(PARAM_MARGINHEIGHT); 576 if (param != null) 577 { 578 setMarginHeight(param); 579 } 580 581 param = config.getInitParameter(PARAM_ALIGN); 582 if (param != null) 583 { 584 setAlign(param); 585 } 586 587 } 588 catch (Exception e) 589 { 590 logger.error("Exception in init()", e); 591 throw new PortletException(e.getMessage()); 592 } 593 } 594 } 595 596 597 | Popular Tags |