@Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class) { return (AdapterType) valueMap; } return super.adaptTo(type); }
/** * Unwrap the resource and return the wrapped implementation. * @param rsrc The resource to unwrap * @return The unwrapped resource * @since 2.5 (Sling API Bundle 2.7.0) */ public static @NotNull Resource unwrap(final @NotNull Resource rsrc) { Resource result = rsrc; while ( result instanceof ResourceWrapper ) { result = ((ResourceWrapper)result).getResource(); } return result; }
/** * Returns a string representation of this wrapper consisting of the class' * simple name, the {@link #getResourceType() resource type} and * {@link #getPath() path} as well as the string representation of the * {@link #getResource() wrapped resource}. */ @Override public String toString() { final String simpleName = getClass().getSimpleName(); final String className = (simpleName.length() > 0) ? simpleName : getClass().getName(); return className + ", type=" + getResourceType() + ", path=" + getPath() + ", resource=[" + getResource() + "]"; }
public SampleResourceWrapper(final Resource resource, final ValueMap overlayProperties) { super(resource); // The use of CompositeValueMap is used to address SLING-6420 which does not handle data type such as Date's well. // Set the overlayedProperties as the "property set" and the resoure's "real" valueMap as the defaults. this.properties = new CompositeValueMap(overlayProperties, super.getValueMap()); }
/** * Returns <code>true</code> if the resource <code>res</code> is a synthetic * resource. * <p> * This method checks whether the resource is an instance of the * <code>org.apache.sling.resource.SyntheticResource</code> class. * * @param res The <code>Resource</code> to check whether it is a synthetic * resource. * @return <code>true</code> if <code>res</code> is a synthetic resource. * <code>false</code> is returned if <code>res</code> is * <code>null</code> or not an instance of the * <code>org.apache.sling.resource.SyntheticResource</code> class. */ public static boolean isSyntheticResource(@NotNull Resource res) { if (res instanceof SyntheticResource) { return true; } if (!(res instanceof ResourceWrapper)) { return false; } do { res = ((ResourceWrapper) res).getResource(); } while (res instanceof ResourceWrapper); return res instanceof SyntheticResource; }
@Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { AdapterType result = super.adaptTo(type); if (result == null) { return (AdapterType) resource; } else { return result; } } }
/** * Returns the value of calling <code>getName</code> on the * {@link #getResource() wrapped resource}. * * @since 2.1.0 (Sling API Bundle 2.1.0) */ @Override public String getName() { return getResource().getName(); }
@Override public final <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type != ValueMap.class) { return super.adaptTo(type); } // Return the ValueMap of the properties passed in return (AdapterType) this.properties; } }
/** * Returns the value of calling <code>getParent</code> on the * {@link #getResource() wrapped resource}. * * @since 2.1.0 (Sling API Bundle 2.1.0) */ @Override public Resource getParent() { return getResource().getParent(); }
@Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type != ValueMap.class) { return super.adaptTo(type); } return (AdapterType) this.getValueMap(); } }
/** * Returns the value of calling <code>getResourceType</code> on the * {@link #getResource() wrapped resource}. */ @Override public String getResourceType() { return getResource().getResourceType(); }
/** * Returns the value of calling <code>adaptTo</code> on the * {@link #getResource() wrapped resource}. */ @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { return getResource().adaptTo(type); }
/** * Returns the value of calling <code>getPath</code> on the * {@link #getResource() wrapped resource}. */ @Override public String getPath() { return getResource().getPath(); }
/** * Returns the value of calling <code>getChild</code> on the * {@link #getResource() wrapped resource}. * * @since 2.1.0 (Sling API Bundle 2.1.0) */ @Override public Resource getChild(String relPath) { return getResource().getChild(relPath); }
/** * Returns the value of calling <code>getResourceSuperType</code> on the * {@link #getResource() wrapped resource}. */ @Override public String getResourceSuperType() { return getResource().getResourceSuperType(); }
/** * Returns the value of calling <code>listChildren</code> on the * {@link #getResource() wrapped resource}. * * @since 2.1.0 (Sling API Bundle 2.1.0) */ @Override public Iterator<Resource> listChildren() { return getResource().listChildren(); }
/** * Returns the value of calling <code>isResourceType</code> on the * {@link #getResource() wrapped resource}. * * @since 2.1.0 (Sling API Bundle 2.1.0) */ @Override public boolean isResourceType(final String resourceType) { return getResource().isResourceType(resourceType); }
/** * Returns the value of calling <code>getResourceMetadata</code> on the * {@link #getResource() wrapped resource}. */ @Override public ResourceMetadata getResourceMetadata() { return getResource().getResourceMetadata(); }
/** * @see org.apache.sling.api.resource.Resource#getValueMap() */ @Override public ValueMap getValueMap() { return getResource().getValueMap(); }
/** * @see org.apache.sling.api.resource.Resource#getChildren() */ @Override public Iterable<Resource> getChildren() { return getResource().getChildren(); }