You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by cz...@apache.org on 2001/11/22 08:51:13 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml AbstractXMLConsumer.java JaxpParser.java XercesParser.java
cziegeler 01/11/21 23:51:13
Modified: src/scratchpad/org/apache/avalon/excalibur/source
SourceParameters.java SourceResolverImpl.java
URLSource.java
src/scratchpad/org/apache/avalon/excalibur/xml
AbstractXMLConsumer.java JaxpParser.java
XercesParser.java
Added: src/scratchpad/org/apache/avalon/excalibur/source
SourceUtil.java
Log:
Factored out utilitiy methods to SourceUtil, changed to LogEnabled
Revision Changes Path
1.3 +2 -76 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceParameters.java
Index: SourceParameters.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceParameters.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- SourceParameters.java 2001/11/14 07:46:52 1.2
+++ SourceParameters.java 2001/11/22 07:51:13 1.3
@@ -17,7 +17,7 @@
* more than one value for a parameter.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version $Id: SourceParameters.java,v 1.2 2001/11/14 07:46:52 cziegeler Exp $
+ * @version $Id: SourceParameters.java,v 1.3 2001/11/22 07:51:13 cziegeler Exp $
*/
public final class SourceParameters
implements Serializable {
@@ -248,7 +248,7 @@
while (listIterator.hasNext() == true) {
if (first == false) result.append('&');
value = (String)listIterator.next();
- result.append(key).append('=').append(this.encode(value));
+ result.append(key).append('=').append(SourceUtil.encode(value));
first = false;
}
}
@@ -351,80 +351,6 @@
if (this.names.containsKey(name) == true) {
this.names.remove(name);
}
- }
-
- /** A BitSet defining the characters which don't need encoding */
- static BitSet charactersDontNeedingEncoding;
- static final int characterCaseDiff = ('a' - 'A');
-
- /** Initialize the BitSet */
- static {
- charactersDontNeedingEncoding = new BitSet(256);
- int i;
- for (i = 'a'; i <= 'z'; i++) {
- charactersDontNeedingEncoding.set(i);
- }
- for (i = 'A'; i <= 'Z'; i++) {
- charactersDontNeedingEncoding.set(i);
- }
- for (i = '0'; i <= '9'; i++) {
- charactersDontNeedingEncoding.set(i);
- }
- charactersDontNeedingEncoding.set(' ');
- charactersDontNeedingEncoding.set('-');
- charactersDontNeedingEncoding.set('_');
- charactersDontNeedingEncoding.set('.');
- charactersDontNeedingEncoding.set('*');
- charactersDontNeedingEncoding.set('"');
- }
-
- /**
- * Translates a string into <code>x-www-form-urlencoded</code> format.
- *
- * @param s <code>String</code> to be translated.
- * @return the translated <code>String</code>.
- */
- private String encode(String s) {
- StringBuffer out = new StringBuffer(s.length());
- ByteArrayOutputStream buf = new ByteArrayOutputStream(32);
- OutputStreamWriter writer = new OutputStreamWriter(buf);
- for (int i = 0; i < s.length(); i++) {
- int c = (int)s.charAt(i);
- if (charactersDontNeedingEncoding.get(c)) {
- if (c == ' ') {
- out.append("%20");
- } else {
- out.append((char)c);
- }
- } else {
- try {
- writer.write(c);
- writer.flush();
- } catch(IOException e) {
- buf.reset();
- continue;
- }
- byte[] ba = buf.toByteArray();
- for (int j = 0; j < ba.length; j++) {
- out.append('%');
- char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
- // converting to use uppercase letter as part of
- // the hex value if ch is a letter.
- if (Character.isLetter(ch)) {
- ch -= characterCaseDiff;
- }
- out.append(ch);
- ch = Character.forDigit(ba[j] & 0xF, 16);
- if (Character.isLetter(ch)) {
- ch -= characterCaseDiff;
- }
- out.append(ch);
- }
- buf.reset();
- }
- }
-
- return out.toString();
}
}
1.8 +6 -6 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java
Index: SourceResolverImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceResolverImpl.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- SourceResolverImpl.java 2001/11/16 15:13:03 1.7
+++ SourceResolverImpl.java 2001/11/22 07:51:13 1.8
@@ -20,8 +20,8 @@
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
-import org.apache.avalon.framework.logger.AbstractLoggable;
-import org.apache.avalon.framework.logger.Loggable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.LogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
import java.io.File;
@@ -45,10 +45,10 @@
* looking up components from a <code>ComponentManager</code>.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version $Id: SourceResolverImpl.java,v 1.7 2001/11/16 15:13:03 cziegeler Exp $
+ * @version $Id: SourceResolverImpl.java,v 1.8 2001/11/22 07:51:13 cziegeler Exp $
*/
public class SourceResolverImpl
-extends AbstractLoggable
+extends AbstractLogEnabled
implements Composable,
Configurable,
Contextualizable,
@@ -224,8 +224,8 @@
source = new URLSource((new File(systemID)).toURL(), parameters);
}
}
- if (source instanceof Loggable) {
- ((Loggable) source).setLogger(getLogger());
+ if (source instanceof LogEnabled) {
+ ((LogEnabled) source).enableLogging(getLogger());
}
try {
if (source instanceof Contextualizable) {
1.6 +3 -82 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java
Index: URLSource.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/URLSource.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- URLSource.java 2001/11/14 15:58:03 1.5
+++ URLSource.java 2001/11/22 07:51:13 1.6
@@ -26,7 +26,7 @@
* Description of a source which is described by an URL.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.5 $ $Date: 2001/11/14 15:58:03 $
+ * @version CVS $Revision: 1.6 $ $Date: 2001/11/22 07:51:13 $
*/
public final class URLSource implements ModifiableSource, XMLizable {
@@ -92,7 +92,7 @@
this.connection = this.url.openConnection();
String userInfo = this.getUserInfo();
if (this.url.getProtocol().startsWith("http") == true && userInfo != null) {
- this.connection.setRequestProperty("Authorization","Basic "+this.encodeBASE64(userInfo));
+ this.connection.setRequestProperty("Authorization","Basic "+SourceUtil.encodeBASE64(userInfo));
}
}
this.lastModificationDate = this.connection.getLastModified();
@@ -143,7 +143,7 @@
/* The following requires a jdk 1.3 */
String userInfo = this.getUserInfo();
if (this.url.getProtocol().startsWith("http") == true && userInfo != null) {
- this.connection.setRequestProperty("Authorization","Basic "+encodeBASE64(userInfo));
+ this.connection.setRequestProperty("Authorization","Basic "+SourceUtil.encodeBASE64(userInfo));
}
}
@@ -219,85 +219,6 @@
newObject.setSystemId(this.systemId);
return newObject;
}
-
- public static final char [ ] alphabet = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
- 'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
- '4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63
-
- /**
- * BASE 64 encoding.
- * See also RFC 1421
- */
- public static String encodeBASE64 ( String s ) {
- return encodeBASE64 ( s.getBytes ( ) );
- }
-
- /**
- * BASE 64 encoding.
- * See also RFC 1421
- */
- public static String encodeBASE64 ( byte [ ] octetString ) {
- int bits24;
- int bits6;
-
- char [ ] out
- = new char [ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ];
-
- int outIndex = 0;
- int i = 0;
-
- while ( ( i + 3 ) <= octetString.length ) {
- // store the octets
- bits24 = ( octetString [ i++ ] & 0xFF ) << 16;
- bits24 |= ( octetString [ i++ ] & 0xFF ) << 8;
- bits24 |= ( octetString [ i++ ] & 0xFF ) << 0;
-
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x00000FC0 ) >> 6;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x0000003F );
- out [ outIndex++ ] = alphabet [ bits6 ];
- }
-
- if ( octetString.length - i == 2 ) {
- // store the octets
- bits24 = ( octetString [ i ] & 0xFF ) << 16;
- bits24 |= ( octetString [ i + 1 ] & 0xFF ) << 8;
-
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x00000FC0 ) >> 6;
- out [ outIndex++ ] = alphabet [ bits6 ];
-
- // padding
- out [ outIndex++ ] = '=';
- } else if ( octetString.length - i == 1 ) {
- // store the octets
- bits24 = ( octetString [ i ] & 0xFF ) << 16;
-
- bits6 = ( bits24 & 0x00FC0000 ) >> 18;
- out [ outIndex++ ] = alphabet [ bits6 ];
- bits6 = ( bits24 & 0x0003F000 ) >> 12;
- out [ outIndex++ ] = alphabet [ bits6 ];
-
- // padding
- out [ outIndex++ ] = '=';
- out [ outIndex++ ] = '=';
- }
-
- return new String ( out );
- }
/**
* Stream content to a content handler or to an XMLConsumer.
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/source/SourceUtil.java
Index: SourceUtil.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package org.apache.avalon.excalibur.source;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.BitSet;
/**
*
* Utility class for source resolving.
*
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
* @version CVS $Revision: 1.1 $ $Date: 2001/11/22 07:51:13 $
*/
public final class SourceUtil {
private static final char [ ] alphabet = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // 0 to 7
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', // 8 to 15
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', // 16 to 23
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', // 24 to 31
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', // 32 to 39
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', // 40 to 47
'w', 'x', 'y', 'z', '0', '1', '2', '3', // 48 to 55
'4', '5', '6', '7', '8', '9', '+', '/' }; // 56 to 63
/**
* BASE 64 encoding.
* See also RFC 1421
*/
public static String encodeBASE64 ( String s ) {
return encodeBASE64 ( s.getBytes ( ) );
}
/**
* BASE 64 encoding.
* See also RFC 1421
*/
public static String encodeBASE64 ( byte [ ] octetString ) {
int bits24;
int bits6;
char [ ] out = new char [ ( ( octetString.length - 1 ) / 3 + 1 ) * 4 ];
int outIndex = 0;
int i = 0;
while ( ( i + 3 ) <= octetString.length ) {
// store the octets
bits24 = ( octetString [ i++ ] & 0xFF ) << 16;
bits24 |= ( octetString [ i++ ] & 0xFF ) << 8;
bits24 |= ( octetString [ i++ ] & 0xFF ) << 0;
bits6 = ( bits24 & 0x00FC0000 ) >> 18;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x0003F000 ) >> 12;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x00000FC0 ) >> 6;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x0000003F );
out [ outIndex++ ] = alphabet [ bits6 ];
}
if ( octetString.length - i == 2 ) {
// store the octets
bits24 = ( octetString [ i ] & 0xFF ) << 16;
bits24 |= ( octetString [ i + 1 ] & 0xFF ) << 8;
bits6 = ( bits24 & 0x00FC0000 ) >> 18;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x0003F000 ) >> 12;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x00000FC0 ) >> 6;
out [ outIndex++ ] = alphabet [ bits6 ];
// padding
out [ outIndex++ ] = '=';
} else if ( octetString.length - i == 1 ) {
// store the octets
bits24 = ( octetString [ i ] & 0xFF ) << 16;
bits6 = ( bits24 & 0x00FC0000 ) >> 18;
out [ outIndex++ ] = alphabet [ bits6 ];
bits6 = ( bits24 & 0x0003F000 ) >> 12;
out [ outIndex++ ] = alphabet [ bits6 ];
// padding
out [ outIndex++ ] = '=';
out [ outIndex++ ] = '=';
}
return new String ( out );
}
/** A BitSet defining the characters which don't need encoding */
static BitSet charactersDontNeedingEncoding;
static final int characterCaseDiff = ('a' - 'A');
/** Initialize the BitSet */
static {
charactersDontNeedingEncoding = new BitSet(256);
int i;
for (i = 'a'; i <= 'z'; i++) {
charactersDontNeedingEncoding.set(i);
}
for (i = 'A'; i <= 'Z'; i++) {
charactersDontNeedingEncoding.set(i);
}
for (i = '0'; i <= '9'; i++) {
charactersDontNeedingEncoding.set(i);
}
charactersDontNeedingEncoding.set(' ');
charactersDontNeedingEncoding.set('-');
charactersDontNeedingEncoding.set('_');
charactersDontNeedingEncoding.set('.');
charactersDontNeedingEncoding.set('*');
charactersDontNeedingEncoding.set('"');
}
/**
* Translates a string into <code>x-www-form-urlencoded</code> format.
*
* @param s <code>String</code> to be translated.
* @return the translated <code>String</code>.
*/
public static String encode(String s) {
StringBuffer out = new StringBuffer(s.length());
ByteArrayOutputStream buf = new ByteArrayOutputStream(32);
OutputStreamWriter writer = new OutputStreamWriter(buf);
for (int i = 0; i < s.length(); i++) {
int c = (int)s.charAt(i);
if (charactersDontNeedingEncoding.get(c)) {
if (c == ' ') {
out.append("%20");
} else {
out.append((char)c);
}
} else {
try {
writer.write(c);
writer.flush();
} catch(IOException e) {
buf.reset();
continue;
}
byte[] ba = buf.toByteArray();
for (int j = 0; j < ba.length; j++) {
out.append('%');
char ch = Character.forDigit((ba[j] >> 4) & 0xF, 16);
// converting to use uppercase letter as part of
// the hex value if ch is a letter.
if (Character.isLetter(ch)) {
ch -= characterCaseDiff;
}
out.append(ch);
ch = Character.forDigit(ba[j] & 0xF, 16);
if (Character.isLetter(ch)) {
ch -= characterCaseDiff;
}
out.append(ch);
}
buf.reset();
}
}
return out.toString();
}
}
1.3 +5 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/AbstractXMLConsumer.java
Index: AbstractXMLConsumer.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/AbstractXMLConsumer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractXMLConsumer.java 2001/11/13 12:48:45 1.2
+++ AbstractXMLConsumer.java 2001/11/22 07:51:13 1.3
@@ -7,7 +7,7 @@
*/
package org.apache.avalon.excalibur.xml;
-import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
@@ -18,9 +18,11 @@
*
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
- * @version CVS $Revision: 1.2 $ $Date: 2001/11/13 12:48:45 $
+ * @version CVS $Revision: 1.3 $ $Date: 2001/11/22 07:51:13 $
*/
-public abstract class AbstractXMLConsumer extends AbstractLoggable implements XMLConsumer {
+public abstract class AbstractXMLConsumer
+extends AbstractLogEnabled
+implements XMLConsumer {
/**
* Receive an object for locating the origin of SAX document events.
1.4 +3 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/JaxpParser.java
Index: JaxpParser.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/JaxpParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JaxpParser.java 2001/11/13 12:48:45 1.3
+++ JaxpParser.java 2001/11/22 07:51:13 1.4
@@ -11,7 +11,7 @@
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.w3c.dom.Document;
import org.xml.sax.*;
@@ -26,10 +26,10 @@
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.3 $ $Date: 2001/11/13 12:48:45 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/11/22 07:51:13 $
*/
public class JaxpParser
-extends AbstractLoggable
+extends AbstractLogEnabled
implements Parser, ErrorHandler, Configurable, Recyclable {
/** the SAX Parser factory */
1.4 +3 -3 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XercesParser.java
Index: XercesParser.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/xml/XercesParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- XercesParser.java 2001/11/13 12:48:45 1.3
+++ XercesParser.java 2001/11/22 07:51:13 1.4
@@ -7,7 +7,7 @@
*/
package org.apache.avalon.excalibur.xml;
-import org.apache.avalon.framework.logger.AbstractLoggable;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.SingleThreaded;
import org.apache.xerces.parsers.DOMParser;
import org.apache.xerces.parsers.SAXParser;
@@ -24,10 +24,10 @@
*
* @author <a href="mailto:fumagalli@exoffice.com">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
- * @version CVS $Revision: 1.3 $ $Date: 2001/11/13 12:48:45 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/11/22 07:51:13 $
*/
public class XercesParser
-extends AbstractLoggable
+extends AbstractLogEnabled
implements Parser, ErrorHandler, SingleThreaded {
/** the SAX Parser */
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>