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 * <h5 class='section'>Examples:</h5>
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 * </p>
075 *
076 * <h5 class='section'>See Also:</h5><ul>
077 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a>
078 * </ul>
079 */
080@Marshalled(typeName = "style")
081public class Style extends HtmlElementRawText<Style> {
082
083   /**
084    * Creates an empty {@link Style} element.
085    */
086   public Style() {}
087
088   /**
089    * Creates a {@link Style} element with the specified {@link Style#text(Object)} node.
090    *
091    * @param text The {@link Style#text(Object)} node. Can be <jk>null</jk> to leave the text unset.
092    */
093   public Style(Object text) {
094      text(text);
095   }
096
097   /**
098    * Creates a {@link Style} element with the specified inner text.
099    *
100    * @param text
101    *    The contents of the style element.
102    *    <br>Values will be concatenated with newlines.
103    */
104   public Style(String...text) {
105      text(joinnl(text));
106   }
107
108   /**
109    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-style-media">media</a> attribute.
110    *
111    * <p>
112    * Specifies the media types for which the stylesheet applies. This allows you to target
113    * specific devices or media types.
114    *
115    * <p>
116    * Common values:
117    * <ul>
118    *    <li><js>"all"</js> - All media types (default)</li>
119    *    <li><js>"screen"</js> - Computer screens</li>
120    *    <li><js>"print"</js> - Printers and print preview</li>
121    *    <li><js>"handheld"</js> - Handheld devices</li>
122    *    <li><js>"projection"</js> - Projectors</li>
123    *    <li><js>"tv"</js> - Television</li>
124    * </ul>
125    *
126    * @param value The media types for which the stylesheet applies. Can be <jk>null</jk> to unset the attribute.
127    * @return This object.
128    */
129   public Style media(String value) {
130      attr("media", value);
131      return this;
132   }
133
134   /**
135    * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-style-type">type</a> attribute.
136    *
137    * <p>
138    * Type of embedded resource.
139    *
140    * @param value The new value for this attribute. Can be <jk>null</jk> to unset the attribute.
141    * @return This object.
142    */
143   public Style type(String value) {
144      attr("type", value);
145      return this;
146   }
147}