This should do it.

- Kasper
---------PATCH Begin-------------
Index: Bytes.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/java/lang/Bytes.java,v

retrieving revision 1.4

diff -u -r1.4 Bytes.java

--- Bytes.java 2001/05/06 17:06:40 1.4

+++ Bytes.java 2001/06/22 10:29:25

@@ -60,6 +60,7 @@

*

* @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>

* @version $Id: Bytes.java,v 1.4 2001/05/06 17:06:40 jvanzyl Exp $

+ * @deprecated sorry, you need to get your Bytes library somewhere else now

*/

public class Bytes

{

Index: MD5.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/java/security/MD5.java,v

retrieving revision 1.3

diff -u -r1.3 MD5.java

--- MD5.java 2001/03/06 06:11:41 1.3

+++ MD5.java 2001/06/22 10:31:36

@@ -65,6 +65,7 @@

*

* @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>

* @version $Id: MD5.java,v 1.3 2001/03/06 06:11:41 chrise Exp $

+ * @deprecated Deprecated in favor of java.security.MessageDigest

*/

public final class MD5

extends MessageDigest

Index: MessageDigest.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/java/security/MessageDig
est.java,v

retrieving revision 1.3

diff -u -r1.3 MessageDigest.java

--- MessageDigest.java 2001/03/06 06:11:42 1.3

+++ MessageDigest.java 2001/06/22 10:31:46

@@ -64,6 +64,7 @@

*

* @author <a href="mailto:[EMAIL PROTECTED]";>Stefano Mazzocchi</a>

* @version $Id: MessageDigest.java,v 1.3 2001/03/06 06:11:42 chrise Exp $

+ * @deprecated Deprecated in favor of java.security.MessageDigest

*/

public abstract class MessageDigest

{

Index: JServUtils.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/jserv/JServUtils.java,v

retrieving revision 1.3

diff -u -r1.3 JServUtils.java

--- JServUtils.java 2001/03/06 06:11:43 1.3

+++ JServUtils.java 2001/06/22 10:32:38

@@ -71,6 +71,7 @@

* @author <a href="mailto:unknown";>Francis J. Lacoste</a>

* @author <a href="mailto:unknown";>Ian Kluft</a>

* @version $Id: JServUtils.java,v 1.3 2001/03/06 06:11:43 chrise Exp $

+ * @deprecated These are all supported by java.net.* constructs now

*/

public final class JServUtils

{

Index: DefaultParameterParser.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/util/parser/Defa
ultParameterParser.java,v

retrieving revision 1.4

diff -u -r1.4 DefaultParameterParser.java

--- DefaultParameterParser.java 2001/05/15 01:54:14 1.4

+++ DefaultParameterParser.java 2001/06/22 10:41:28

@@ -59,8 +59,6 @@


import javax.servlet.http.HttpServletRequest;


-import org.apache.jserv.JServUtils;

-

import org.apache.turbine.util.Log;

import org.apache.turbine.util.ParameterParser;

import org.apache.turbine.util.TurbineException;

@@ -216,12 +214,12 @@

{

if ( name == true )

{

- tmp = JServUtils.URLDecode(st.nextToken());

+ tmp = URLDecode(st.nextToken());

name = false;

}

else

{

- pathPart = JServUtils.URLDecode(st.nextToken());

+ pathPart = URLDecode(st.nextToken());

if ( tmp.length() != 0 )

{

add (convert(tmp), pathPart);

@@ -332,5 +330,90 @@

{

return null;

}

+ }

+

+ /**

+ * This method decodes the given URL-encoded string.

+ *

+ * @param str The URL-encoded string.

+ * @return The decoded string.

+ * @exception IllegalArgumentException, if a '%' is not followed

+ * by a valid 2-digit hex number.

+ */

+ private String URLDecode(String str)

+ throws IllegalArgumentException

+ {

+ if (str == null)

+ return null;

+

+ // Decoded string output.

+ StringBuffer dec = new StringBuffer();

+

+ int strPos = 0;

+ int strLen = str.length();

+

+ dec.ensureCapacity(str.length());

+ while (strPos < strLen)

+ {

+ // Look ahead position.

+ int laPos;

+

+ // Look ahead to next URLencoded metacharacter, if any.

+ for (laPos = strPos; laPos < strLen; laPos++)

+ {

+ char laChar = str.charAt(laPos);

+ if ((laChar == '+') || (laChar == '%'))

+ {

+ break;

+ }

+ }

+

+ // If there were non-metacharacters, copy them all as a

+ // block.

+ if (laPos > strPos)

+ {

+ dec.append(str.substring(strPos,laPos));

+ strPos = laPos;

+ }

+

+ // Shortcut out of here if we're at the end of the string.

+ if (strPos >= strLen)

+ {

+ break;

+ }

+

+ // Process next metacharacter.

+ char metaChar = str.charAt(strPos);

+ if (metaChar == '+')

+ {

+ dec.append(' ');

+ strPos++;

+ continue;

+ }

+ else if (metaChar == '%')

+ {

+ try

+ {

+ dec.append((char)

+ Integer.parseInt(str.substring(strPos + 1,

+ strPos + 3),

+ 16));

+ }

+ catch (NumberFormatException e)

+ {

+ throw new IllegalArgumentException("invalid hexadecimal "

+ + str.substring(strPos + 1, strPos + 3)

+ + " in URLencoded string (illegal unescaped '%'?)" );

+ }

+ catch (StringIndexOutOfBoundsException e)

+ {

+ throw new IllegalArgumentException("illegal unescaped '%' "

+ + " in URLencoded string" );

+ }

+ strPos += 3;

+ }

+ }

+

+ return dec.toString();

}

}

Index: TurbineUniqueIdService.java

===================================================================

RCS file:
/home/cvspublic/jakarta-turbine/src/java/org/apache/turbine/services/uniquei
d/TurbineUniqueIdService.java,v

retrieving revision 1.10

diff -u -r1.10 TurbineUniqueIdService.java

--- TurbineUniqueIdService.java 2001/06/14 14:44:41 1.10

+++ TurbineUniqueIdService.java 2001/06/22 10:47:18

@@ -58,9 +58,9 @@

import org.apache.turbine.services.BaseService;

import org.apache.turbine.services.InitializationException;

import org.apache.turbine.services.servlet.TurbineServlet;

-import org.apache.java.security.MD5;

-import org.apache.java.lang.Bytes;


+import java.security.MessageDigest;

+

/**

* <p> This is an implementation of {@link UniqueIdService}.

*

@@ -111,8 +111,17 @@

url.append ( TurbineServlet.getScriptName() );

turbineURL = url.toString();


- MD5 md5 = new MD5();

- turbineId = Bytes.toString(md5.digest(url.toString().getBytes()));

+ try

+ {

+ MessageDigest md = MessageDigest.getInstance("MD5");

+ turbineId= byteArrayToHex(

+ md.digest( url.toString().getBytes() ) ) ;

+ }

+ catch ( Exception e )

+ {

+ throw new InitializationException(

+ "TurbineUniqueIdService failed to initialize", e);

+ }


getCategory().info("This is Turbine instance running at: " + url);

getCategory().info("The instance id is #" + turbineId);

@@ -177,5 +186,29 @@

public String getPseudorandomId()

{

return GenerateUniqueId.getIdentifier();

+ }

+

+ /**

+ * Returns a string of hexadecimal digits from a byte array,

+ * starting at offset and continuing for length bytes.

+ *

+ * @param b The byte[] to convert.

+ * @return A String.

+ */

+ private String byteArrayToHex(byte[] b)

+ {

+ char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7',

+ '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};

+

+ char[] buf = new char[b.length * 2];

+

+ for (int i = 0, j = 0, k; i < b.length; i++)

+ {

+ k = b[i];

+ buf[j++] = hexDigits[(k >>> 4) & 0x0F];

+ buf[j++] = hexDigits[k & 0x0F];

+ }

+

+ return new String(buf);

}

}

--PATCH END--------------------------

----- Original Message -----
From: "Daniel Rall" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, June 22, 2001 2:19 AM
Subject: Re: Package cleanup proposal


> "Kasper Nielsen" <[EMAIL PROTECTED]> writes:
>
> > One more..
> >
> > 1.
> > getting rid of
> >
> > org.apache.java.lang.Bytes (only used in org.apache.java.security.MD5)
> > org.apache.java.security.MD5
> > org.apache.java.security.MessageDigest
> >
> > having given up Java 1.1 compatibility there is really no reason why we
> > shouldn't use java.security.Digest
>
> +1
>
> > 2.
> > Getting rid of
> > org.apache.jserv.JServUtils, we are only using the decode function in
> > DefaultParameterParser
> > and use
> > java.net.URLDecode instead
>
> And if we need that code, we can always inline it into
> DefaultParameterParser.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to