View Javadoc
1   /*
2    * Copyright (c) 2002-2017 Gargoyle Software Inc.
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    * http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package com.gargoylesoftware.htmlunit.javascript.host.html;
16  
17  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.HTMLABBREVIATED;
18  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_PHRASE_COMMON_CLASS_NAME;
19  import static com.gargoylesoftware.htmlunit.BrowserVersionFeatures.JS_XML_SUPPORT_VIA_ACTIVEXOBJECT;
20  import static com.gargoylesoftware.htmlunit.javascript.configuration.SupportedBrowser.IE;
21  
22  import com.gargoylesoftware.htmlunit.html.DomNode;
23  import com.gargoylesoftware.htmlunit.html.HtmlAbbreviated;
24  import com.gargoylesoftware.htmlunit.html.HtmlAcronym;
25  import com.gargoylesoftware.htmlunit.html.HtmlBidirectionalOverride;
26  import com.gargoylesoftware.htmlunit.html.HtmlBig;
27  import com.gargoylesoftware.htmlunit.html.HtmlBlink;
28  import com.gargoylesoftware.htmlunit.html.HtmlBold;
29  import com.gargoylesoftware.htmlunit.html.HtmlCitation;
30  import com.gargoylesoftware.htmlunit.html.HtmlCode;
31  import com.gargoylesoftware.htmlunit.html.HtmlDefinition;
32  import com.gargoylesoftware.htmlunit.html.HtmlEmphasis;
33  import com.gargoylesoftware.htmlunit.html.HtmlItalic;
34  import com.gargoylesoftware.htmlunit.html.HtmlKeyboard;
35  import com.gargoylesoftware.htmlunit.html.HtmlNoBreak;
36  import com.gargoylesoftware.htmlunit.html.HtmlRp;
37  import com.gargoylesoftware.htmlunit.html.HtmlRt;
38  import com.gargoylesoftware.htmlunit.html.HtmlRuby;
39  import com.gargoylesoftware.htmlunit.html.HtmlS;
40  import com.gargoylesoftware.htmlunit.html.HtmlSample;
41  import com.gargoylesoftware.htmlunit.html.HtmlSmall;
42  import com.gargoylesoftware.htmlunit.html.HtmlStrike;
43  import com.gargoylesoftware.htmlunit.html.HtmlStrong;
44  import com.gargoylesoftware.htmlunit.html.HtmlSubscript;
45  import com.gargoylesoftware.htmlunit.html.HtmlSuperscript;
46  import com.gargoylesoftware.htmlunit.html.HtmlTeletype;
47  import com.gargoylesoftware.htmlunit.html.HtmlUnderlined;
48  import com.gargoylesoftware.htmlunit.html.HtmlVariable;
49  import com.gargoylesoftware.htmlunit.javascript.configuration.JsxClass;
50  import com.gargoylesoftware.htmlunit.javascript.host.ActiveXObject;
51  
52  /**
53   * The JavaScript object {@code HTMLPhraseElement}.
54   *
55   * @author Ahmed Ashour
56   * @author Daniel Gredler
57   * @author Ronald Brill
58   */
59  @JsxClass(domClass = HtmlAbbreviated.class, value = IE)
60  @JsxClass(domClass = HtmlAcronym.class, value = IE)
61  @JsxClass(domClass = HtmlBidirectionalOverride.class, value = IE)
62  @JsxClass(domClass = HtmlBig.class, value = IE)
63  @JsxClass(domClass = HtmlBlink.class, value = IE)
64  @JsxClass(domClass = HtmlBold.class, value = IE)
65  @JsxClass(domClass = HtmlCitation.class, value = IE)
66  @JsxClass(domClass = HtmlCode.class, value = IE)
67  @JsxClass(domClass = HtmlDefinition.class, value = IE)
68  @JsxClass(domClass = HtmlEmphasis.class, value = IE)
69  @JsxClass(domClass = HtmlItalic.class, value = IE)
70  @JsxClass(domClass = HtmlKeyboard.class, value = IE)
71  @JsxClass(domClass = HtmlNoBreak.class, value = IE)
72  @JsxClass(domClass = HtmlRt.class, value = IE)
73  @JsxClass(domClass = HtmlRp.class, value = IE)
74  @JsxClass(domClass = HtmlRuby.class, value = IE)
75  @JsxClass(domClass = HtmlS.class, value = IE)
76  @JsxClass(domClass = HtmlSample.class, value = IE)
77  @JsxClass(domClass = HtmlSmall.class, value = IE)
78  @JsxClass(domClass = HtmlStrike.class, value = IE)
79  @JsxClass(domClass = HtmlSubscript.class, value = IE)
80  @JsxClass(domClass = HtmlSuperscript.class, value = IE)
81  @JsxClass(domClass = HtmlStrong.class, value = IE)
82  @JsxClass(domClass = HtmlTeletype.class, value = IE)
83  @JsxClass(domClass = HtmlUnderlined.class, value = IE)
84  @JsxClass(domClass = HtmlVariable.class, value = IE)
85  public class HTMLPhraseElement extends HTMLElement {
86  
87      /**
88       * Sets the DOM node that corresponds to this JavaScript object.
89       * @param domNode the DOM node
90       */
91      @Override
92      public void setDomNode(final DomNode domNode) {
93          super.setDomNode(domNode);
94  
95          if (getBrowserVersion().hasFeature(JS_XML_SUPPORT_VIA_ACTIVEXOBJECT)) {
96              if ((domNode instanceof HtmlAbbreviated && getBrowserVersion().hasFeature(HTMLABBREVIATED))
97                  || domNode instanceof HtmlAcronym
98                  || domNode instanceof HtmlBidirectionalOverride
99                  || domNode instanceof HtmlBig
100                 || domNode instanceof HtmlBlink
101                 || domNode instanceof HtmlBold
102                 || domNode instanceof HtmlCitation
103                 || domNode instanceof HtmlCode
104                 || domNode instanceof HtmlDefinition
105                 || domNode instanceof HtmlEmphasis
106                 || domNode instanceof HtmlItalic
107                 || domNode instanceof HtmlKeyboard
108                 || domNode instanceof HtmlNoBreak
109                 || domNode instanceof HtmlS
110                 || domNode instanceof HtmlSample
111                 || domNode instanceof HtmlSmall
112                 || domNode instanceof HtmlStrong
113                 || domNode instanceof HtmlStrike
114                 || domNode instanceof HtmlSubscript
115                 || domNode instanceof HtmlSuperscript
116                 || domNode instanceof HtmlTeletype
117                 || domNode instanceof HtmlUnderlined
118                 || domNode instanceof HtmlVariable
119                 ) {
120                 ActiveXObject.addProperty(this, "cite", true, true);
121                 ActiveXObject.addProperty(this, "dateTime", true, true);
122             }
123         }
124     }
125 
126     /**
127      * Returns the value of the {@code cite} property.
128      * @return the value of the {@code cite} property
129      */
130     public String getCite() {
131         final String cite = getDomNodeOrDie().getAttribute("cite");
132         return cite;
133     }
134 
135     /**
136      * Returns the value of the {@code cite} property.
137      * @param cite the value
138      */
139     public void setCite(final String cite) {
140         getDomNodeOrDie().setAttribute("cite", cite);
141     }
142 
143     /**
144      * Returns the value of the {@code dateTime} property.
145      * @return the value of the {@code dateTime} property
146      */
147     public String getDateTime() {
148         final String dateTime = getDomNodeOrDie().getAttribute("datetime");
149         return dateTime;
150     }
151 
152     /**
153      * Returns the value of the {@code dateTime} property.
154      * @param dateTime the value
155      */
156     public void setDateTime(final String dateTime) {
157         getDomNodeOrDie().setAttribute("datetime", dateTime);
158     }
159 
160     /**
161      * Returns whether the end tag is forbidden or not.
162      * @see <a href="http://www.w3.org/TR/html4/index/elements.html">HTML 4 specs</a>
163      * @return whether the end tag is forbidden or not
164      */
165     @Override
166     protected boolean isEndTagForbidden() {
167         return false;
168     }
169 
170     /**
171      * {@inheritDoc}
172      */
173     @Override
174     public String getClassName() {
175         if (getWindow().getWebWindow() != null && getBrowserVersion().hasFeature(JS_PHRASE_COMMON_CLASS_NAME)) {
176             return "HTMLElement";
177         }
178         return super.getClassName();
179     }
180 }