001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.dto.html5;
014
015import static org.apache.juneau.internal.StringUtils.*;
016
017import java.net.*;
018import java.net.URI;
019
020import org.apache.juneau.*;
021import org.apache.juneau.annotation.*;
022
023/**
024 * DTO for an HTML {@doc ExtHTML5.scripting-1#the-script-element <script>}
025 * element.
026 *
027 * <ul class='seealso'>
028 *    <li class='link'>{@doc DtoHtml5}
029 * </ul>
030 */
031@Bean(typeName="script")
032public class Script extends HtmlElementRawText {
033
034   /**
035    * Creates an empty {@link Script} element.
036    */
037   public Script() {}
038
039   /**
040    * Creates a {@link Script} element with the specified {@link Script#type(String)} attribute and
041    * {@link Script#text(Object)} node.
042    *
043    * @param type The {@link Script#type(String)} attribute.
044    * @param text The child text node.
045    */
046   public Script(String type, String...text) {
047      type(type).text(joinnl(text));
048   }
049
050   /**
051    * {@doc ExtHTML5.scripting-1#attr-script-async async} attribute.
052    *
053    * <p>
054    * Execute script asynchronously.
055    *
056    * @param async
057    *    The new value for this attribute.
058    *    Typically a {@link Boolean} or {@link String}.
059    * @return This object (for method chaining).
060    */
061   public final Script async(Object async) {
062      attr("async", deminimize(async, "async"));
063      return this;
064   }
065
066   /**
067    * {@doc ExtHTML5.scripting-1#attr-script-charset charset} attribute.
068    *
069    * <p>
070    * Character encoding of the external script resource.
071    *
072    * @param charset The new value for this attribute.
073    * @return This object (for method chaining).
074    */
075   public final Script charset(String charset) {
076      attr("charset", charset);
077      return this;
078   }
079
080   /**
081    * {@doc ExtHTML5.scripting-1#attr-script-crossorigin crossorigin}
082    * attribute.
083    *
084    * <p>
085    * How the element handles cross-origin requests.
086    *
087    * @param crossorigin The new value for this attribute.
088    * @return This object (for method chaining).
089    */
090   public final Script crossorigin(String crossorigin) {
091      attr("crossorigin", crossorigin);
092      return this;
093   }
094
095   /**
096    * {@doc ExtHTML5.scripting-1#attr-script-defer defer} attribute.
097    *
098    * <p>
099    * Defer script execution.
100    *
101    * @param defer
102    *    The new value for this attribute.
103    *    Typically a {@link Boolean} or {@link String}.
104    * @return This object (for method chaining).
105    */
106   public final Script defer(Object defer) {
107      attr("defer", deminimize(defer, "defer"));
108      return this;
109   }
110
111   /**
112    * {@doc ExtHTML5.scripting-1#attr-script-src src} attribute.
113    *
114    * <p>
115    * Address of the resource.
116    *
117    * <p>
118    * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}.
119    * Strings must be valid URIs.
120    *
121    * <p>
122    * URIs defined by {@link UriResolver} can be used for values.
123    *
124    * @param src
125    *    The new value for this attribute.
126    *    Typically a {@link URL} or {@link String}.
127    * @return This object (for method chaining).
128    */
129   public final Script src(Object src) {
130      attrUri("src", src);
131      return this;
132   }
133
134   /**
135    * {@doc ExtHTML5.scripting-1#attr-script-type type} attribute.
136    *
137    * <p>
138    * Type of embedded resource.
139    *
140    * @param type The new value for this attribute.
141    * @return This object (for method chaining).
142    */
143   public final Script type(String type) {
144      attr("type", type);
145      return this;
146   }
147
148
149   //-----------------------------------------------------------------------------------------------------------------
150   // Overridden methods
151   //-----------------------------------------------------------------------------------------------------------------
152
153   @Override /* HtmlElement */
154   public final Script _class(String _class) {
155      super._class(_class);
156      return this;
157   }
158
159   @Override /* HtmlElement */
160   public final Script id(String id) {
161      super.id(id);
162      return this;
163   }
164
165   @Override /* HtmlElementText */
166   public Script text(Object text) {
167      super.text(text);
168      return this;
169   }
170}