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.*;
import org.apache.juneau.html.*;
import org.apache.juneau.urlencoding.*;
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(nameProperty = "name", hrefProperty = "href") public class LinkString implements Comparable { private String name, href; /** No-arg constructor. */ public LinkString() {} /** * Constructor. * * @param name Corresponds to the text inside of the <A> element. * @param href Corresponds to the value of the href attribute of the <A> element. * @param hrefArgs Optional arguments for {@link MessageFormat} style arguments in the href. */ public LinkString(String name, String href, Object...hrefArgs) { setName(name); setHref(href, hrefArgs); } //-------------------------------------------------------------------------------- // 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 setName(String name) { this.name = name; return this; } /** * Bean property getter: href. * *

* 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 String getHref() { return href; } /** * Bean property setter: href. * * @param href The new value for the href property on this bean. * @return This object (for method chaining). */ public LinkString setHref(String href) { setHref(href, new Object[0]); return this; } /** * Bean property setter: href. * *

* Same as {@link #setHref(String)} except allows for {@link MessageFormat} style arguments. * * @param href The new href. * @param args Optional {@link MessageFormat}-style arguments. * @return This object (for method chaining). */ public LinkString setHref(String href, Object...args) { for (int i = 0; i < args.length; i++) args[i] = UrlEncodingSerializer.DEFAULT.serialize(PartType.PATH, args[i]); this.href = format(href, 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