1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.io.IOException ; 41 import java.net.MalformedURLException ; 42 import java.net.URL ; 43 import java.util.Map ; 44 45 import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; 46 import com.gargoylesoftware.htmlunit.Page; 47 import com.gargoylesoftware.htmlunit.WebClient; 48 import com.gargoylesoftware.htmlunit.WebRequestSettings; 49 import com.gargoylesoftware.htmlunit.WebWindow; 50 51 61 public abstract class BaseFrame extends StyledElement { 62 63 66 public final class FrameWindow implements WebWindow { 67 private Page enclosedPage_; 68 private Object scriptObject_; 69 70 73 private FrameWindow() { 74 } 76 77 82 public String getName() { 83 return getNameAttribute(); 84 } 85 86 91 public void setName(final String name) { 92 setNameAttribute(name); 93 } 94 95 100 public Page getEnclosedPage() { 101 return enclosedPage_; 102 } 103 104 109 public void setEnclosedPage( final Page page ) { 110 enclosedPage_ = page; 111 } 112 113 118 public WebWindow getParentWindow() { 119 return getPage().getEnclosingWindow(); 120 } 121 122 127 public WebWindow getTopWindow() { 128 return getParentWindow().getTopWindow(); 129 } 130 131 136 public WebClient getWebClient() { 137 return getPage().getWebClient(); 138 } 139 140 145 public Object getScriptObject() { 146 return scriptObject_; 147 } 148 149 155 public void setScriptObject( final Object scriptObject ) { 156 scriptObject_ = scriptObject; 157 } 158 159 165 public HtmlPage getEnclosingPage() { 166 return getPage(); 167 } 168 } 169 170 private final WebWindow enclosedWindow_ = new FrameWindow(); 171 172 178 protected BaseFrame( final HtmlPage page, final Map attributes) { 179 180 super(page, attributes); 181 182 final WebClient webClient = page.getWebClient(); 183 webClient.registerWebWindow(enclosedWindow_); 184 } 185 186 187 191 void loadInnerPage() { 192 String source = getSrcAttribute(); 193 if( source.length() == 0 ) { 194 source = "about:blank"; 196 } 197 198 loadInnerPageIfPossible(source); 199 } 200 201 private void loadInnerPageIfPossible(final String srcAttribute) { 202 203 if( srcAttribute.length() != 0 ) { 204 URL url = null; 205 try { 206 url = getPage().getFullyQualifiedUrl(srcAttribute); 207 } 208 catch( final MalformedURLException e ) { 209 getLog().error("Bad url in src attribute of " + getTagName() + ": url=["+srcAttribute+"]", e); 210 } 211 try { 212 getPage().getWebClient().getPage(enclosedWindow_, new WebRequestSettings(url)); 213 } 214 catch (final FailingHttpStatusCodeException e){ 215 } 217 catch( final IOException e ) { 218 getLog().error("IOException when getting content for " + getTagName() 219 + ": url=["+url.toExternalForm()+"]", e); 220 } 221 } 222 } 223 224 227 public abstract String getTagName(); 228 229 237 public final String getLongDescAttribute() { 238 return getAttributeValue("longdesc"); 239 } 240 241 242 250 public final String getNameAttribute() { 251 return getAttributeValue("name"); 252 } 253 254 255 260 public final void setNameAttribute(final String name) { 261 setAttributeValue("name", name); 262 } 263 264 265 273 public final String getSrcAttribute() { 274 return getAttributeValue("src"); 275 } 276 277 278 286 public final String getFrameBorderAttribute() { 287 return getAttributeValue("frameborder"); 288 } 289 290 291 299 public final String getMarginWidthAttribute() { 300 return getAttributeValue("marginwidth"); 301 } 302 303 304 312 public final String getMarginHeightAttribute() { 313 return getAttributeValue("marginheight"); 314 } 315 316 317 325 public final String getNoResizeAttribute() { 326 return getAttributeValue("noresize"); 327 } 328 329 330 338 public final String getScrollingAttribute() { 339 return getAttributeValue("scrolling"); 340 } 341 342 343 351 public final String getOnLoadAttribute() { 352 return getAttributeValue("onload"); 353 } 354 355 356 362 public Page getEnclosedPage() { 363 return getEnclosedWindow().getEnclosedPage(); 364 } 365 366 367 371 public WebWindow getEnclosedWindow() { 372 return enclosedWindow_; 373 } 374 375 376 380 public final void setSrcAttribute( final String attribute ) { 381 setAttributeValue("src", attribute); 382 loadInnerPageIfPossible(attribute); 383 } 384 } 385 | Popular Tags |