@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class) { return (AdapterType) valueMap; } return super.adaptTo(type); } }
/** * Returns the name of this resource. * <p> * This method is implemented as a pure string operation by calling the * {@link ResourceUtil#getName(String)} method with the path of this * resource. */ public String getName() { return ResourceUtil.getName(getPath()); }
/** * Checks to see if there are direct children of this resource by invoking * {@link ResourceResolver#hasChildren(Resource)}. */ public boolean hasChildren() { return getResourceResolver().hasChildren(this); }
public Iterator<Resource> iterator() { return listChildren(); } };
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if(type == ValueMap.class) { return (AdapterType)valueMap; } return super.adaptTo(type); } }
/** * Returns an iterator on the direct child resources. * <p> * This method is implemented calling the * {@link ResourceResolver#listChildren(Resource)} method. * <p> * Implementations should not generally overwrite this method without * calling this base class implementation. */ public Iterator<Resource> listChildren() { return getResourceResolver().listChildren(this); }
@Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { AdapterType value = props.get(key, type); if (value!=null) { return value; } return super.adaptTo(type); }
/** * Returns the parent resource of this resource. * <p> * This method is implemented calling the {@link ResourceResolver#getParent(Resource)} method. */ public Resource getParent() { return getResourceResolver().getParent(this); }
/** * @see org.apache.sling.api.adapter.SlingAdaptable#adaptTo(java.lang.Class) */ @SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) { if ( type == Servlet.class ) { final Servlet s = (Servlet)super.adaptTo(type); if ( s != null ) { return (AdapterType)s; } } else if ( type == SlingScript.class ) { final SlingScript s = (SlingScript)super.adaptTo(type); if ( s != null ) { return (AdapterType)s; } } return this.getActiveResource().adaptTo(type); }
/** * Returns <code>true</code> if this resource is of the given resource type * or if any of the super resource types equals the given resource type. * <p> * This method delegates to {@link ResourceResolver#isResourceType(Resource, String)} */ public boolean isResourceType(final String resourceType) { return this.getResourceResolver().isResourceType(this, resourceType); }
@Override @SuppressWarnings("unchecked") public <Type> Type adaptTo(Class<Type> type) { if (type == InputStream.class) { return (Type) getInputStream(); // unchecked cast } else if (type == URL.class) { return (Type) getURL(); // unchecked cast } else if (type == ValueMap.class) { return (Type) valueMap; // unchecked cast } // fall back to adapter factories return super.adaptTo(type); }
/** * Returns the indicated child of this resource. * <p> * This method is implemented calling the * {@link ResourceResolver#getResource(Resource, String)} method. As such * the <code>relPath</code> argument may even be an absolute path or a path * containing relative path segments <code>.</code> (current resource) and * <code>..</code> (parent resource). * <p> * Implementations should not generally overwrite this method without * calling this base class implementation. */ public Resource getChild(String relPath) { return getResourceResolver().getResource(this, relPath); }
@Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class || type == Map.class) { return type.cast(new ValueMapDecorator(getProperties())); } else { if (adapters != null) { for (Object adapter : adapters) { if (adapter == null) continue; if (type.isArray()) { if (adapter.getClass().isArray()) { Object[] adapterArray = (Object[]) adapter; return convertArray(type, adapterArray); } } else if (type.isAssignableFrom(adapter.getClass())) { return type.cast(adapter); } } } } return super.adaptTo(type); }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == Servlet.class && servlet != null) { return (AdapterType) servlet; // unchecked cast } else if ( type == ValueMap.class ) { final Map<String, Object> props = new HashMap<>(); props.put("sling:resourceType", this.getResourceType()); props.put("sling:resourceSuperType", this.getResourceSuperType()); if (servlet != null) { props.put("servletName", this.getServletName()); props.put("servletClass", this.servlet.getClass().getName()); } return (AdapterType) new ValueMapDecorator(props); // unchecked cast } return super.adaptTo(type); }
return super.adaptTo(type);
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(final Class<AdapterType> type) { if ( type == ValueMap.class || type == Map.class ) { return (AdapterType)new ReadonlyValueMapDecorator(this.props); } else if ( type == ModifiableValueMap.class ) { ((MockResourceResolver)this.resolver).addChanged(this.path, this.props); return (AdapterType)this.props; } else if ( type == InputStream.class ) { InputStream is = getFileResourceInputStream(); if (is != null) { return (AdapterType)is; } } return super.adaptTo(type); }
@Override @SuppressWarnings("unchecked") public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ContentFile.class) { return (AdapterType)this.contentFile; } else if (type == ValueMap.class) { return (AdapterType)new DeepReadValueMapDecorator(this, contentFile.getValueMap()); } else if (type == Node.class) { // support a subset of JCR API for content file resources return (AdapterType)new FsNode(contentFile, getResourceResolver()); } return super.adaptTo(type); }
@SuppressWarnings("unchecked") @Override public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) { if (type == ValueMap.class || type == Map.class) { return (AdapterType)new DeepReadValueMapDecorator(this, new NoSqlValueMap(data.getProperties(), this, resourceProvider)); } if (type == ModifiableValueMap.class) { return (AdapterType)new DeepReadModifiableValueMapDecorator(this, new NoSqlValueMap(data.getProperties(), this, resourceProvider)); } return super.adaptTo(type); }