All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.dto.LinkString Maven / Gradle / Ivy

There is a newer version: 9.0.1
Show newest version
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
// * with the License.  You may obtain a copy of the License at                                                              *
// *                                                                                                                         *
// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
// *                                                                                                                         *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
// * specific language governing permissions and limitations under the License.                                              *
// ***************************************************************************************************************************
package org.apache.juneau.dto;

import static org.apache.juneau.internal.StringUtils.*;

import java.text.*;

import org.apache.juneau.annotation.*;
import org.apache.juneau.html.*;
import org.apache.juneau.html.annotation.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.oapi.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.utils.*;

/**
 * Simple bean that implements a hyperlink for the HTML serializer.
 *
 * 

* The name and url properties correspond to the following parts of a hyperlink in an HTML document... *

* <a href='href'>name</a> *

* *

* When encountered by the {@link HtmlSerializer} class, this object gets converted to a hyperlink. * All other serializers simply convert it to a simple bean. */ @HtmlLink @Bean(fluentSetters=true) public class LinkString implements Comparable { private String name; private java.net.URI uri; /** No-arg constructor. */ public LinkString() {} /** * Constructor. * * @param name Corresponds to the text inside of the <A> element. * @param uri Corresponds to the value of the href attribute of the <A> element. * @param uriArgs Optional arguments for {@link MessageFormat} style arguments in the href. */ public LinkString(String name, String uri, Object...uriArgs) { name(name); uri(uri, uriArgs); } //----------------------------------------------------------------------------------------------------------------- // Bean properties //----------------------------------------------------------------------------------------------------------------- /** * Bean property getter: name. * *

* Corresponds to the text inside of the <A> element. * * @return The value of the name property on this bean, or null if it is not set. */ public String getName() { return name; } /** * Bean property setter: name. * * @param name The new value for the name property on this bean. * @return This object (for method chaining). */ public LinkString name(String name) { this.name = name; return this; } /** * Bean property getter: uri. * *

* Corresponds to the value of the href attribute of the <A> element. * * @return The value of the href property on this bean, or null if it is not set. */ public java.net.URI getUri() { return uri; } /** * Bean property setter: uri. * * @param uri The new value for the href property on this bean. * @return This object (for method chaining). */ public LinkString uri(String uri) { uri(uri, new Object[0]); return this; } /** * Bean property setter: uri. * *

* Same as {@link #uri(String)} except allows for {@link MessageFormat} style arguments. * * @param uri The new href. * @param args Optional {@link MessageFormat}-style arguments. * @return This object (for method chaining). */ public LinkString uri(String uri, Object...args) { for (int i = 0; i < args.length; i++) try { args[i] = OpenApiSerializer.DEFAULT.createSession().serialize(HttpPartType.PATH, null, args[i]); } catch (SchemaValidationException | SerializeException e) { throw new RuntimeException(e); } this.uri = java.net.URI.create(format(uri, args)); return this; } /** * Returns the name so that the {@link PojoQuery} class can search against it. */ @Override /* Object */ public String toString() { return name; } @Override /* Comparable */ public int compareTo(LinkString o) { return name.compareTo(o.name); } @Override /* Object */ public boolean equals(Object o) { if (! (o instanceof LinkString)) return false; return (compareTo((LinkString)o) == 0); } @Override /* Object */ public int hashCode() { return super.hashCode(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy