1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.css;
16
17 import java.net.MalformedURLException;
18 import java.net.URL;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.htmlunit.html.DomNode;
23 import org.htmlunit.html.HtmlLink;
24 import org.htmlunit.html.HtmlPage;
25 import org.htmlunit.html.HtmlStyle;
26 import org.htmlunit.javascript.HtmlUnitScriptable;
27 import org.htmlunit.javascript.configuration.JsxClass;
28 import org.htmlunit.javascript.configuration.JsxConstructor;
29 import org.htmlunit.javascript.configuration.JsxGetter;
30 import org.htmlunit.javascript.host.html.HTMLElement;
31
32
33
34
35
36
37
38 @JsxClass
39 public class StyleSheet extends HtmlUnitScriptable {
40
41 private static final Log LOG = LogFactory.getLog(StyleSheet.class);
42
43
44 private final HTMLElement ownerNode_;
45
46
47
48
49 public StyleSheet() {
50 super();
51 ownerNode_ = null;
52 }
53
54
55
56
57 @JsxConstructor
58 public void jsConstructor() {
59
60 }
61
62
63
64
65
66 public StyleSheet(final HTMLElement ownerNode) {
67 super();
68 ownerNode_ = ownerNode;
69 }
70
71
72
73
74
75 @JsxGetter
76 public HTMLElement getOwnerNode() {
77 return ownerNode_;
78 }
79
80
81
82
83
84 @JsxGetter
85 public String getHref() {
86 if (ownerNode_ != null) {
87 final DomNode node = ownerNode_.getDomNodeOrDie();
88 if (node instanceof HtmlStyle) {
89 return null;
90 }
91 if (node instanceof HtmlLink) {
92
93 final HtmlLink link = (HtmlLink) node;
94 final String href = link.getHrefAttribute();
95
96 try {
97 final HtmlPage page = (HtmlPage) link.getPage();
98 final URL url = page.getFullyQualifiedUrl(href);
99 return url.toExternalForm();
100 }
101 catch (final MalformedURLException e) {
102
103 LOG.warn(e.getMessage(), e);
104 }
105 }
106 }
107
108 return getUri();
109 }
110
111
112
113
114
115
116 public String getUri() {
117 return null;
118 }
119 }