Re: patch on AbstractTxFileStoreService about idMapper

Martin van den Bemt <[email protected]> Sun, 25 Feb 2007 21:10:34 +0100
Newsgroups gmane.comp.jakarta.slide.devel
Message-ID <[email protected]>
Could you please attach this to a bugzilla issue, so it doesn't get lost or is forgotten ?

Mvgr,
Martin

Guillaume Bailleul wrote:
> I made a little mod on AbstractTxFileStoreService to load a
> ResourceIdToPathMapper specified in the configuration (Domain.xml).
> Maybe this patch could be useful for someone else.
> 
> I needed a special ResourceIdToPathMapper for some "obfuscation" needs
> on the storage disk.
> 
> In the patch, I reuse the use-portable-path parameter. This is maybe
> not a good idea. A new parameter should be a good idea. The new
> problem in that case is the concurrency between this new parameter,
> use-portable-path and url-encode-path (already a problem in the
> current version for the 2 last).
> 
> There are 3 patches, for different implementation. The 2 first are
> compatible with current version, the last changes the configuration
> and the behaviour.
> 
> resourceidmapper.java13.patch for java 1.3 and later
> resourceidmapper.java5.patch for java 5 (only template use)
> 
> resourceidmapper.choose.patch : the value of url-encode-path can be :
> - "encode" : to use classic commons-transaction mapper
> - "portable" : to use the txfile mapper
> - "<classname>" : the classname of the specific
> ResourceIdToPathMapper implementation.
> 
> 
> Best regards,
> 
> Guillaume
> 
> 
> ------------------------------------------------------------------------
> 
> Index: /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java
> ===================================================================
> --- /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(revision 511557)
> +++ /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(working copy)
> @@ -62,7 +62,6 @@
>      protected static final String TIMEOUT_PARAMETER = "timeout";
>      protected static final String URLENCODE_PATH_PARAMETER = "url-encode-path";
>      protected static final String DEBUG_MODE_PARAMETER = "debug";
> -    protected static final String USE_PORTABLE_PATH_PARAMETER = "use-portable-path";
>  
>      protected FileResourceManager rm;
>      protected boolean started = false;
> @@ -98,14 +97,24 @@
>          
>          String urlEncodePathString = (String) parameters.get(URLENCODE_PATH_PARAMETER);
>          if (urlEncodePathString != null) {
> -            boolean urlEncodePath = "true".equals(urlEncodePathString);
> -            if (urlEncodePath) idMapper = new URLEncodeIdMapper();
> -        }
> -
> -        String usePortablePathString = (String) parameters.get(USE_PORTABLE_PATH_PARAMETER);
> -        if (usePortablePathString != null) {
> -            boolean usePortablePath = "true".equals(usePortablePathString);
> -            if (usePortablePath) idMapper = new PortableIdMapper();
> +        	if ("encode".equals(urlEncodePathString)) {
> +              idMapper = new URLEncodeIdMapper();
> +        	} else if ("portable".equals(urlEncodePathString)) {
> +        		idMapper = new PortableIdMapper();
> +        	} else {
> +            	// specify a class name instead of a boolean value
> +            	try {
> +            		Class clz = Class.forName(urlEncodePathString);
> +            		idMapper =(ResourceIdToPathMapper) clz.newInstance();
> +            	} catch (Exception exception) {
> +            		getLogger().log(
> +                            "Cannot load the specified path mapper '"+urlEncodePathString+"'.",
> +                            exception,
> +                            getLogChannel(),
> +                            Logger.ERROR);
> +            		throw new ServiceParameterErrorException(this,URLENCODE_PATH_PARAMETER);
> +    			}
> +        	}
>          }
>          
>          rm =
> 
> 
> ------------------------------------------------------------------------
> 
> Index: /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java
> ===================================================================
> --- /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(revision 511557)
> +++ /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(working copy)
> @@ -105,7 +105,24 @@
>          String usePortablePathString = (String) parameters.get(USE_PORTABLE_PATH_PARAMETER);
>          if (usePortablePathString != null) {
>              boolean usePortablePath = "true".equals(usePortablePathString);
> -            if (usePortablePath) idMapper = new PortableIdMapper();
> +            if (usePortablePath) {
> +            	idMapper = new PortableIdMapper();
> +            } else if("false".equals(usePortablePathString)) {
> +            	// do nothing
> +            } else {
> +            	// specify a class name instead of a boolean value
> +            	try {
> +            		Class<? extends ResourceIdToPathMapper> clz = Class.forName(usePortablePathString).asSubclass(ResourceIdToPathMapper.class);
> +            		idMapper = clz.newInstance();
> +            	} catch (Exception exception) {
> +            		getLogger().log(
> +                            "Cannot load the specified path mapper '"+usePortablePathString+"'.",
> +                            exception,
> +                            getLogChannel(),
> +                            Logger.ERROR);
> +            		throw new ServiceParameterErrorException(this,USE_PORTABLE_PATH_PARAMETER);
> +    			}
> +            }
>          }
>          
>          rm =
> 
> 
> ------------------------------------------------------------------------
> 
> Index: /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java
> ===================================================================
> --- /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(revision 511557)
> +++ /home/guignol/slide/workspace/slide-trunk/src/stores/org/apache/slide/store/txfile/AbstractTxFileStoreService.java	(working copy)
> @@ -105,7 +105,24 @@
>          String usePortablePathString = (String) parameters.get(USE_PORTABLE_PATH_PARAMETER);
>          if (usePortablePathString != null) {
>              boolean usePortablePath = "true".equals(usePortablePathString);
> -            if (usePortablePath) idMapper = new PortableIdMapper();
> +            if (usePortablePath) {
> +            	idMapper = new PortableIdMapper();
> +            } else if("false".equals(usePortablePathString)) {
> +            	// do nothing
> +            } else {
> +            	// specify a class name instead of a boolean value
> +            	try {
> +            		Class clz = Class.forName(usePortablePathString);
> +            		idMapper =(ResourceIdToPathMapper) clz.newInstance();
> +            	} catch (Exception exception) {
> +            		getLogger().log(
> +                            "Cannot load the specified path mapper '"+usePortablePathString+"'.",
> +                            exception,
> +                            getLogChannel(),
> +                            Logger.ERROR);
> +            		throw new ServiceParameterErrorException(this,USE_PORTABLE_PATH_PARAMETER);
> +    			}
> +            }
>          }
>          
>          rm =
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]