
org.apache.sling.api.resource.NonExistingResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.sling.api Show documentation
Show all versions of org.apache.sling.api Show documentation
The Apache Sling API defines an extension to the Servlet
API 2.4 to provide access to content and unified access
to request parameters hiding the differences between the
different methods of transferring parameters from client
to server. Note that the Apache Sling API bundle does not
include the Servlet API but instead requires the API to
be provided by the Servlet container in which the Apache
Sling framework is running or by another bundle.
/*
* 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.sling.api.resource;
import javax.annotation.Nonnull;
/**
* Simple helper class representing nonexisting resources.
*
* This is an utility class to create non existing resources.
* It is not meant to be used to check if a resource is a non existing
* resource. Use the {@link ResourceUtil#isNonExistingResource(Resource)}
* method instead (or check the resource type yourself). The reason
* for this is that this resource might be wrapped by other resource
* implementations like resource decorators etc.
*/
public final class NonExistingResource extends SyntheticResource {
/**
* Create a new non existing resource.
* @param resourceResolver The resource resolver.
* @param resourceURI The path of the resource.
*/
public NonExistingResource(final ResourceResolver resourceResolver,
final String resourceURI) {
super(resourceResolver, resourceURI, RESOURCE_TYPE_NON_EXISTING);
}
/**
* @see org.apache.sling.api.resource.SyntheticResource#getResourceType()
*/
public final @Nonnull String getResourceType() {
// overwrite to prevent overwriting of this method in extensions of
// this class because the specific resource type is the marker of a
// NonExistingResource
return RESOURCE_TYPE_NON_EXISTING;
}
public String toString() {
// overwrite to only list the class name and path, type is irrelevant
return getClass().getSimpleName() + ", path=" + getPath();
}
/**
*
* @return the parent resource (might be a {@link NonExistingResource} in case the parent does not exist either).
*/
public Resource getParent() {
Resource parent = super.getParent();
if (parent == null) {
return new NonExistingResource(getResourceResolver(), ResourceUtil.getParent(getPath()));
} else {
return parent;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy