org.thymeleaf.standard.expression.FragmentSignature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.everit.osgi.bundles.org.thymeleaf.thymeleaf Show documentation
Show all versions of org.everit.osgi.bundles.org.thymeleaf.thymeleaf Show documentation
XML/XHTML/HTML5 template engine for Java
The newest version!
/*
* =============================================================================
*
* Copyright (c) 2011-2013, The THYMELEAF team (http://www.thymeleaf.org)
*
* Licensed 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.thymeleaf.standard.expression;
import java.io.Serializable;
import java.util.List;
import org.thymeleaf.util.StringUtils;
import org.thymeleaf.util.Validate;
/**
*
* Represents a fragment signature, including both a name and an (optional) sequence of parameter names to be
* applied. Typically the result of parsing a th:fragment attribute.
*
*
* @author Daniel Fernández
*
* @since 2.1.0
*
*/
public final class FragmentSignature implements Serializable {
private static final long serialVersionUID = 6847640942405961705L;
private static final char FRAGMENT_SIGNATURE_PARAMETERS_START = '(';
private static final char FRAGMENT_SIGNATURE_PARAMETERS_END = ')';
private final String fragmentName;
private final List parameterNames;
public FragmentSignature(final String fragmentName, final List parameterNames) {
super();
Validate.notEmpty(fragmentName, "Fragment name cannot be null or empty");
this.fragmentName = fragmentName;
this.parameterNames = parameterNames;
}
public String getFragmentName() {
return this.fragmentName;
}
public boolean hasParameters() {
return this.parameterNames != null && this.parameterNames.size() > 0;
}
public List getParameterNames() {
return this.parameterNames;
}
public String getStringRepresentation() {
if (this.parameterNames == null || this.parameterNames.size() == 0) {
return this.fragmentName;
}
return this.fragmentName + " " +
FRAGMENT_SIGNATURE_PARAMETERS_START +
StringUtils.join(this.parameterNames, ',') +
FRAGMENT_SIGNATURE_PARAMETERS_END;
}
@Override
public String toString() {
return getStringRepresentation();
}
}