org.ow2.weblab.core.extended.util
Class ResourceUtil

java.lang.Object
  extended by org.ow2.weblab.core.extended.util.ResourceUtil

public class ResourceUtil
extends java.lang.Object

A class that contain a useful method when wanting to visualise the content and the structure of a Resource

Author:
Cassidian WebLab Team

Method Summary
static
<T extends Resource>
java.util.List<T>
getSelectedSubResources(Resource res, java.lang.Class<T> resClass)
          The same as ResourceUtil.getSubResources(Resource), but with a filter on the Resource class to be retrieved by the List.
static
<T extends Resource>
java.util.Map<T,Resource>
getSelectedSubResourcesMap(Resource res, java.lang.Class<T> resClass)
          The same as ResourceUtil.getSubResources(Resource, Class<T>); But in addition to the sub-resources by themselves, this method return an reference to the resource containing every subresource.
static java.util.List<Resource> getSubResources(Resource res)
           
static Resource loadFromXMLString(java.lang.String xml)
          Simply transform the XML String into a Resource.
static void printTree(Resource res, java.io.OutputStream stream)
          Simple visualisation method that enable to print a user friendly (non-xml) description of res.
static java.lang.String saveToXMLString(Resource resource)
          Simply transforms resource into an XML String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

printTree

public static void printTree(Resource res,
                             java.io.OutputStream stream)
Simple visualisation method that enable to print a user friendly (non-xml) description of res. Uses a tree representation. For each type of Resource that might me contained by the given Resource and it's contained Resources print their URI and their class simple name. For any Resource, it's contained Resource s might be:

Parameters:
res - The Resource to be printed
stream - The OutputStream to write into

saveToXMLString

public static java.lang.String saveToXMLString(Resource resource)
                                        throws WebLabCheckedException
Simply transforms resource into an XML String. Use the WebLabMarshaller for more configuration, and usage with files or streams.

Parameters:
resource - The Resource to be transformed into an XML String.
Returns:
A String containing the XML view of the Resource
Throws:
WebLabCheckedException
See Also:
WebLabMarshaller

loadFromXMLString

public static Resource loadFromXMLString(java.lang.String xml)
                                  throws WebLabCheckedException
Simply transform the XML String into a Resource. Use the WebLabMarshaller for more configuration, and usage with files or streams.

Parameters:
xml - The XML String representing the Resource
Returns:
The Resource defined in the XML String.
Throws:
WebLabCheckedException

getSubResources

public static java.util.List<Resource> getSubResources(Resource res)
Parameters:
res - The Resource to retrieve children.
Returns:
The subResource List without res it self.

getSelectedSubResources

public static <T extends Resource> java.util.List<T> getSelectedSubResources(Resource res,
                                                                             java.lang.Class<T> resClass)
The same as ResourceUtil.getSubResources(Resource), but with a filter on the Resource class to be retrieved by the List. I.e. the only retrieved Resources are those that are instances of resClass.

Type Parameters:
T - Subclass of Resource to be retrieved
Parameters:
res - The Resource to retrieve children.
resClass - The Class of the only children you need in result List.
Returns:
The subResource List.
See Also:
getSubResources(Resource)

getSelectedSubResourcesMap

public static <T extends Resource> java.util.Map<T,Resource> getSelectedSubResourcesMap(Resource res,
                                                                                        java.lang.Class<T> resClass)
The same as ResourceUtil.getSubResources(Resource, Class<T>); But in addition to the sub-resources by themselves, this method return an reference to the resource containing every subresource.

Type Parameters:
T - Subclass of Resource to be retrieved
Parameters:
res - The Resource to retrieve children.
resClass - The Class of the only children you need in result List.
Returns:
The subResource Map with their parents.
See Also:
getSelectedSubResources(Resource, Class)


Copyright © 2004-2010. All Rights Reserved.