org.thymeleaf.web.servlet.IServletWebApplication Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thymeleaf Show documentation
Show all versions of thymeleaf Show documentation
Modern server-side Java template engine for both web and standalone environments
/*
* =============================================================================
*
* Copyright (c) 2011-2021, 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.web.servlet;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import org.thymeleaf.util.Validate;
import org.thymeleaf.web.IWebApplication;
/**
*
* @author Daniel Fernández
*
* @since 3.1.0
*
*/
public interface IServletWebApplication extends IWebApplication {
public Enumeration getAttributeNames();
@Override
default boolean containsAttribute(final String name) {
Validate.notNull(name, "Name cannot be null");
// Attribute maps in the servlet specification do not allow null values (setting null = remove)
return getAttributeValue(name) != null;
}
@Override
default int getAttributeCount() {
int count = 0;
final Enumeration attributeNamesEnum = getAttributeNames();
while (attributeNamesEnum.hasMoreElements()) {
attributeNamesEnum.nextElement();
count++;
}
return count;
}
@Override
default Set getAllAttributeNames() {
final Set attributeNames = new LinkedHashSet(10);
final Enumeration attributeNamesEnum = getAttributeNames();
while (attributeNamesEnum.hasMoreElements()) {
attributeNames.add(attributeNamesEnum.nextElement());
}
return Collections.unmodifiableSet(attributeNames);
}
@Override
default Map getAttributeMap() {
final Map attributeMap = new LinkedHashMap(10);
final Enumeration attributeNamesEnum = getAttributeNames();
String attributeName;
while (attributeNamesEnum.hasMoreElements()) {
attributeName = attributeNamesEnum.nextElement();
attributeMap.put(attributeName, getAttributeValue(attributeName));
}
return Collections.unmodifiableMap(attributeMap);
}
@Override
default void removeAttribute(final String name) {
Validate.notNull(name, "Name cannot be null");
this.setAttributeValue(name, null);
}
public URL getResource(final String path) throws java.net.MalformedURLException;
@Override
default boolean resourceExists(final String path) {
Validate.notNull(path, "Path cannot be null");
try {
return (getResource(path) != null);
} catch (final MalformedURLException e) {
return false;
}
}
public Object getNativeServletContextObject();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy