[Arakhnę-Dev] [325] * Remove '/' as the first character in the resource names on Android operating system.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 325
Author:   galland
Date:     2012-02-06 14:55:51 +0100 (Mon, 06 Feb 2012)
Log Message:
-----------
* Remove '/' as the first character in the resource names on Android operating system.

Modified Paths:
--------------
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemDiskUtilWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemIdentificationType.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemUDevWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
    trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Android.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
-  * $Id$
+ * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2012 Stephane GALLAND.
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
@@ -40,7 +42,7 @@
 	/** Name of the home directory.
 	 */
 	public static final String HOME_DIRECTORY = "sdcard"; //$NON-NLS-1$
-	
+
 	/** Name of the system-wide configuration directory.
 	 */
 	public static final String CONFIGURATION_DIRECTORY = "config"; //$NON-NLS-1$
@@ -52,13 +54,13 @@
 	private static SoftReference<Object> context = null;
 	private static WeakReference<Object> contextResolver = null;
 	private static WeakReference<ClassLoader> contextClassLoader = null;
-	
+
 	/**
 	 */
 	private Android() {
 		//
 	}
-	
+
 	/** Make a valid android application name from the given application name.
 	 * A valid android application name is a package name followed by the name
 	 * of the application.
@@ -76,7 +78,7 @@
 		}
 		return fullName;
 	}
-	
+
 	/** Replies the class {@code Context} from Android.
 	 * 
 	 * @return the class {@code Context} from Android.
@@ -91,7 +93,7 @@
 			throw new AndroidException(e);
 		}
 	}
-	
+
 	/** Replies the class {@code ContextResolver} from Android.
 	 * 
 	 * @return the class {@code ContextResolver} from Android.
@@ -106,7 +108,7 @@
 			throw new AndroidException(e);
 		}
 	}
-	
+
 	private static Class<?> getInnerClass(String enclosingClassname, String innerClassname) throws AndroidException {
 		ClassLoader loader = ClassLoaderFinder.findClassLoader();
 		Throwable ex = null;
@@ -179,6 +181,7 @@
 		catch(Throwable e) {
 			throw new AndroidException(e);
 		}
+		ClassLoaderFinder.setPreferredClassLoader(getContextClassLoader());
 	}
 
 	/** Replies the current {@code Context} for the android task.
@@ -196,7 +199,7 @@
 		if (c==null) throw new AndroidException();
 		return c;
 	}
-	
+
 	/** Replies the class loader of the current Android context.
 	 * 
 	 * @return class loader used by the current Android context.
@@ -229,7 +232,7 @@
 		}
 		return cl;
 	}
-	
+
 	/** Replies the current {@code ContextResolver} for the android task.
 	 * 
 	 * @return the current {@code ContextResolver} for the android task.
@@ -282,7 +285,7 @@
 		public AndroidException() {
 			//
 		}
-		
+
 		/**
 		 * @param message is the error message.
 		 */
@@ -296,7 +299,7 @@
 		public AndroidException(Throwable exception) {
 			super(exception);
 		}
-		
+
 		/**
 		 * @param message is the error message.
 		 * @param exception is the cause of this exception.
@@ -306,5 +309,5 @@
 		}
 
 	} // class AndroidException
-	
+
 }

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/AndroidResourceWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2012 Stephane GALLAND.
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
@@ -35,6 +37,13 @@
  */
 class AndroidResourceWrapper implements ResourceWrapper {
 
+	private String decodeResourceName(String resourceName) {
+		if (resourceName.startsWith("/")) { //$NON-NLS-1$
+			return resourceName.substring(1);
+		}
+		return resourceName;
+	}
+	
 	/**
 	 */
 	public AndroidResourceWrapper() {
@@ -46,17 +55,18 @@
      */
 	@Override
     public URL getResource(ClassLoader classLoader, String path) {
+		String resourceName = decodeResourceName(path);
 		ClassLoader androidClassLoader;
 		try {
 			androidClassLoader = Android.getContextClassLoader();
 			assert(androidClassLoader!=null);
-			URL url = androidClassLoader.getResource(path);
+			URL url = androidClassLoader.getResource(resourceName);
 			if (url!=null) return url;
 		}
 		catch (AndroidException e) {
 			//
 		}
-		return classLoader.getResource(path);
+		return classLoader.getResource(resourceName);
     }
 
     /**
@@ -64,17 +74,18 @@
      */
 	@Override
     public InputStream getResourceAsStream(ClassLoader classLoader, String path) {
+		String resourceName = decodeResourceName(path);
 		ClassLoader androidClassLoader;
 		try {
 			androidClassLoader = Android.getContextClassLoader();
 			assert(androidClassLoader!=null);
-			InputStream stream = androidClassLoader.getResourceAsStream(path);
+			InputStream stream = androidClassLoader.getResourceAsStream(resourceName);
 			if (stream!=null) return stream;
 		}
 		catch (AndroidException e) {
 			//
 		}
-		return classLoader.getResourceAsStream(path);
+		return classLoader.getResourceAsStream(resourceName);
     }
     
 }

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/FileSystem.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2004-2012 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystem.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,5 +1,5 @@
 /* 
-  * $Id$
+ * $Id$
  * 
  * Copyright (C) 2004-2012 Stephane GALLAND.
  * 
@@ -37,12 +37,12 @@
 	 * Windows&reg;.
 	 */
 	WIN,
-	
+
 	/**
 	 * Linux distribution.
 	 */
 	LINUX,
-	
+
 	/**
 	 * Android Linux distribution.
 	 * 
@@ -59,7 +59,7 @@
 	 * Mac OS X&reg;.
 	 */
 	MACOSX,
-	
+
 	/**
 	 * Free BSD.
 	 */
@@ -68,38 +68,38 @@
 	/**
 	 * Net BSD.
 	 */
-    NETBSD,
-    
+	NETBSD,
+
 	/**
 	 * Standard BSD.
 	 */
-    BSD,
-    
+	BSD,
+
 	/**
 	 * Open BSD.
 	 */
-    OPENBSD,
-    
+	OPENBSD,
+
 	/**
 	 * AIX&reg;.
 	 */
-    AIX,
-    
+	AIX,
+
 	/**
 	 * HPUX&reg;.
 	 */
-    HPUX,
-    
+	HPUX,
+
 	/**
 	 * Unknown operating systems.
 	 */
-    OTHER;
-	
+	OTHER;
+
 	private static final String NULL = new String();
 	private static String osSerialNumber = null;
 	private static String osUUID = null;
 	private static OperatingSystem currentOSInstance = null;
-	
+
 	/** Replies the type of identification found on this operating system.
 	 * 
 	 * @return the type of identification found on this operating system.
@@ -109,7 +109,7 @@
 			return OperatingSystemIdentificationType.BIOS;
 		return nativeWrapper.getIdentificationType();
 	}
-	
+
 	/** Replies if the current OperatingSystem constant is corresponding
 	 * to the current operating system.
 	 * 
@@ -144,8 +144,8 @@
 		}
 		return false;
 	}
-	
 
+
 	/** Replies the name of the current OS.
 	 * 
 	 * @return the name of the current operating system.
@@ -154,7 +154,7 @@
 	public static String getCurrentOSName() {
 		return System.getProperty("os.name"); //$NON-NLS-1$
 	}
-	
+
 	/** Replies the version of the current OS.
 	 * 
 	 * @return the version of the current operating system.
@@ -170,7 +170,7 @@
 	 */
 	public static OperatingSystem getCurrentOS() {
 		if (currentOSInstance!=null) return currentOSInstance;
-		
+
 		String os = System.getProperty("os.name").trim().toLowerCase(); //$NON-NLS-1$
 
 		/* Let's try to figure canonical OS name, just in case some
@@ -222,7 +222,7 @@
 			return currentOSInstance=OTHER;
 		}
 	}
-	
+
 	/** Replies the data model of the current operating system: 32 or 64 bits.
 	 * 
 	 * @return the integer which is corresponding to the data model, or <code>0</code> if
@@ -306,13 +306,13 @@
 		}
 		return osUUID==NULL ? null : osUUID;
 	}
-	
+
 	private static OperatingSystemWrapper nativeWrapper; 
-	
+
 	static {
 		OperatingSystemIdentificationType type = OperatingSystemIdentificationType.BIOS;
 		nativeWrapper = null;
-		
+
 		switch(getCurrentOS()) {
 		case BSD:
 		case FREEBSD:
@@ -335,14 +335,14 @@
 		case SOLARIS:
 		case OTHER:
 		}
-		
+
 		Throwable error = null;
 		if (nativeWrapper==null) {
 			try {
 				LibraryLoader.loadPlatformDependentLibrary(
 						"josuuid", //$NON-NLS-1$
 						System.getProperty("os.name").trim().toLowerCase(), //$NON-NLS-1$
-				"org/arakhne/vmutil"); //$NON-NLS-1$
+						"org/arakhne/vmutil"); //$NON-NLS-1$
 			}
 			catch (Throwable e) {
 				error = e;
@@ -351,7 +351,7 @@
 				nativeWrapper = new OperatingSystemNativeWrapper(type);
 			}
 		}
-		
+
 		if (nativeWrapper==null) {
 			try {
 				String errorMsg = Locale.getString("NATIVE_NOT_SUPPORTED"); //$NON-NLS-1$
@@ -367,5 +367,5 @@
 			}
 		}
 	}
-	
+
 }

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemAndroidWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
-  * $Id$
+ * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2012 Stephane GALLAND.
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.
@@ -52,15 +54,15 @@
 			Class<?> secureClass = Android.getSystemSettingsClass();
 
 			Method getStringMethod = secureClass.getMethod("getString", Android.getContextResolverClass(), String.class); //$NON-NLS-1$
-			
+
 			Field androidIdField = secureClass.getField("ANDROID_ID"); //$NON-NLS-1$
 			Object androidId = androidIdField.get(null);
-			
+
 			serial = (String)getStringMethod.invoke(null, Android.getContextResolver(), androidId);
-        }
+		}
 		catch (Throwable _) {
-            serial = null;
-        }
+			serial = null;
+		}
 		return serial;
 	}
 
@@ -73,15 +75,15 @@
 			Class<?> secureClass = Android.getSecureSettingsClass();
 
 			Method getStringMethod = secureClass.getMethod("getString", Android.getContextResolverClass(), String.class); //$NON-NLS-1$
-			
+
 			Field androidIdField = secureClass.getField("ANDROID_ID"); //$NON-NLS-1$
 			Object androidId = androidIdField.get(null);
-			
+
 			serial = (String)getStringMethod.invoke(null, Android.getContextResolver(), androidId);
-        }
+		}
 		catch (Throwable _) {
-            serial = null;
-        }
+			serial = null;
+		}
 		return serial;
 	}
 
@@ -92,5 +94,5 @@
 	public OperatingSystemIdentificationType getIdentificationType() {
 		return OperatingSystemIdentificationType.OPERATING_SYSTEM;
 	}
-	
+
 }

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemDiskUtilWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemDiskUtilWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemDiskUtilWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
   * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2011 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemIdentificationType.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemIdentificationType.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemIdentificationType.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
   * $Id$
  * 
- * Copyright (C) 2004-2011 Stephane GALLAND.
+ * Copyright (C) 2011 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemInfo.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2009, 2011 Stephane GALLAND.
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemNativeWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
   * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2011-12 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemUDevWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemUDevWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemUDevWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
   * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2011-12 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/OperatingSystemWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
   * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2011-12 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/ResourceWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2004-2012 Stephane GALLAND
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Resources.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,7 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLAND.
+ * Copyright (C) 2004-2012 Stephane GALLAND.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java	2012-02-01 21:18:08 UTC (rev 324)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/StandardJREResourceWrapper.java	2012-02-06 13:55:51 UTC (rev 325)
@@ -1,7 +1,9 @@
 /* 
  * $Id$
  * 
- * Copyright (C) 2004-2009 Stephane GALLANDibrary is free software; you can redistribute it and/or
+ * Copyright (C) 2004-2012 Stephane GALLAND.
+ * 
+ * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2.1 of the License, or (at your option) any later version.


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/