001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.bean.html5;
018
019import static org.apache.juneau.commons.utils.StringUtils.*;
020
021import org.apache.juneau.marshall.*;
022
023/**
024 * DTO for an HTML <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#the-style-element">&lt;style&gt;</a>
025 * element.
026 *
027 * <p>
028 * The style element allows authors to embed CSS style information in their documents. It contains
029 * CSS rules that apply to the document. The style element is typically placed in the head section
030 * of the document, but can also be used inline. The CSS contained within the style element is
031 * processed by the browser and applied to the document.
032 *
033 * <h2 class='section'>Examples:</h2>
034 * <p class='bcode w800'>
035 *    <jk>import static</jk> org.apache.juneau.bean.html5.HtmlBuilder.*;
036 *
037 *    <jc>// Basic CSS styles</jc>
038 *    Style <jv>basic</jv> = <jsm>style</jsm>()
039 *       .text(<js>"body { font-family: Arial, sans-serif; }"</js>);
040 *
041 *    <jc>// CSS with media query</jc>
042 *    Style <jv>responsive</jv> = <jsm>style</jsm>()
043 *       .media(<js>"screen and (max-width: 600px)"</js>)
044 *       .text(<js>"body { font-size: 14px; }"</js>);
045 *
046 *    <jc>// Multiple CSS rules</jc>
047 *    Style <jv>multiple</jv> = <jsm>style</jsm>()
048 *       .text(
049 *          <js>"h1 { color: blue; }"</js>,
050 *          <js>"p { margin: 10px; }"</js>,
051 *          <js>".highlight { background-color: yellow; }"</js>
052 *       );
053 *
054 *    <jc>// CSS with type specification</jc>
055 *    Style <jv>typed</jv> = <jsm>style</jsm>()
056 *       .type(<js>"text/css"</js>)
057 *       .text(<js>".button { padding: 10px; background: #007bff; }"</js>);
058 *
059 *    <jc>// Print-specific styles</jc>
060 *    Style <jv>print</jv> = <jsm>style</jsm>()
061 *       .media(<js>"print"</js>)
062 *       .text(<js>"body { color: black; background: white; }"</js>);
063 * </p>
064 *
065 * <p>
066 * The following convenience methods are provided for constructing instances of this bean:
067 * <ul class='javatree'>
068 *    <li class='jc'>{@link HtmlBuilder}
069 *    <ul class='javatree'>
070 *       <li class='jm'>{@link HtmlBuilder#style() style()}
071 *       <li class='jm'>{@link HtmlBuilder#style(Object) style(Object)}
072 *    </ul>
073 * </ul>
074 *
075 * <h2 class='section'>See Also:</h2><ul>
076 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
077 * </ul>
078 */
079@Marshalled(typeName = "style")
080public class Style extends HtmlElementRawText<Style> {
081
082   /**
083    * Creates an empty {@link Style} element.
084    */
085   public Style() {}
086
087   /**
088    * Creates a {@link Style} element with the specified {@link Style#text(Object)} node.
089    *
090    * @param text The {@link Style#text(Object)} node. Can be <jk>null</jk> to leave the text unset.
091    */
092   public Style(Object text) {
093      text(text);
094   }
095
096   /**
097    * Creates a {@link Style} element with the specified inner text.
098    *
099    * @param text
100    *    The contents of the style element.
101    *    <br>Values will be concatenated with newlines.
102    */
103   public Style(String...text) {
104      text(joinnl(text));
105   }
106
107   /**
108    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-style-media">media</a> attribute.
109    *
110    * <p>
111    * Specifies the media types for which the stylesheet applies. This allows you to target
112    * specific devices or media types.
113    *
114    * <p>
115    * Common values:
116    * <ul>
117    *    <li><js>"all"</js> - All media types (default)</li>
118    *    <li><js>"screen"</js> - Computer screens</li>
119    *    <li><js>"print"</js> - Printers and print preview</li>
120    *    <li><js>"handheld"</js> - Handheld devices</li>
121    *    <li><js>"projection"</js> - Projectors</li>
122    *    <li><js>"tv"</js> - Television</li>
123    * </ul>
124    *
125    * @param value The media types for which the stylesheet applies. Can be <jk>null</jk> to unset the attribute.
126    * @return This object.
127    */
128   public Style media(String value) {
129      attr("media", value);
130      return this;
131   }
132
133   /**
134    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-style-type">type</a> attribute.
135    *
136    * <p>
137    * Type of embedded resource.
138    *
139    * @param value The new value for this attribute. Can be <jk>null</jk> to unset the attribute.
140    * @return This object.
141    */
142   public Style type(String value) {
143      attr("type", value);
144      return this;
145   }
146}