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 java.net.*; 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-base-element"><base></a> 025 * element. 026 * 027 * <p> 028 * The base element specifies the base URL for all relative URLs in a document. It also specifies 029 * the default target for all links and forms in the document. Only one base element is allowed 030 * per document and it must be placed in the head section. 031 * 032 * <h5 class='section'>Examples:</h5> 033 * <p class='bcode w800'> 034 * <jc>// Set base URL for all relative links</jc> 035 * Base <jv>base1</jv> = <jsm>base</jsm>().href(<js>"https://example.com/docs/"</js>); 036 * 037 * <jc>// Set default target for all links</jc> 038 * Base <jv>base2</jv> = <jsm>base</jsm>().target(<js>"_blank"</js>); 039 * 040 * <jc>// Set both base URL and default target</jc> 041 * Base <jv>base3</jv> = <jsm>base</jsm>().href(<js>"https://example.com/"</js>).target(<js>"_self"</js>); 042 * </p> 043 * 044 * <p> 045 * The following convenience methods are provided for constructing instances of this bean: 046 * <ul class='javatree'> 047 * <li class='jc'>{@link HtmlBuilder} 048 * <ul class='javatree'> 049 * <li class='jm'>{@link HtmlBuilder#base() base()} 050 * </ul> 051 * </ul> 052 * </p> 053 * 054 * <h5 class='section'>See Also:</h5><ul> 055 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanHtml5">juneau-bean-html5</a> 056 * </ul> 057 */ 058@Marshalled(typeName = "base") 059public class Base extends HtmlElementVoid<Base> { 060 061 /** 062 * Creates an empty {@link Base} element. 063 */ 064 public Base() {} 065 066 /** 067 * Creates a {@link Base} element with the specified {@link Base#href(Object)} attribute. 068 * 069 * @param value The {@link Base#href(Object)} attribute. Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed). 070 */ 071 public Base(Object value) { 072 href(value); 073 } 074 075 /** 076 * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-base-href">href</a> attribute. 077 * 078 * <p> 079 * Document base URL. 080 * 081 * <p> 082 * The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 083 * Strings must be valid URIs. 084 * 085 * <p> 086 * URIs defined by {@link UriResolver} can be used for values. 087 * 088 * @param value 089 * The new value for this attribute. 090 * Typically a {@link URL} or {@link String}. 091 * Can be <jk>null</jk>, in which case the attribute is stored with a <jk>null</jk> value (not removed). 092 * @return This object. 093 */ 094 public Base href(Object value) { 095 attrUri("href", value); 096 return this; 097 } 098 099 /** 100 * <a class="doclink" href="https://www.w3.org/TR/html5/document-metadata.html#attr-base-target">target</a> 101 * attribute. 102 * 103 * <p> 104 * Specifies the default target for all links and forms in the document. 105 * 106 * <p> 107 * Common values: 108 * <ul> 109 * <li><js>"_blank"</js> - Open in a new window/tab</li> 110 * <li><js>"_self"</js> - Open in the same frame (default)</li> 111 * <li><js>"_parent"</js> - Open in the parent frame</li> 112 * <li><js>"_top"</js> - Open in the full body of the window</li> 113 * <li><js>"framename"</js> - Open in a named frame</li> 114 * </ul> 115 * 116 * @param value The default target for links and forms. Can be <jk>null</jk> to unset the attribute. 117 * @return This object. 118 */ 119 public Base target(String value) { 120 attr("target", value); 121 return this; 122 } 123 124}