You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oro-user@jakarta.apache.org by "Jones, David G" <Da...@gbr.xerox.com> on 2002/07/18 11:47:59 UTC

Util and Substitute Javadocs/Problems

Hi, does anyone know of any problems with the accuracy of the 2.0.5 and
2.0.6 ORO Javadocs for org.apache.oro.text.regex.Util and
org.apache.oro.text.regex.Substitution or indeed had any trouble compiling
and running with Util and Substitution?  I'm trying to get my own
Substitution implementation working and I'm finding the following problems:

1. When I compile my class (XMLUtil) with the following line in it (in a
static method):
org.apache.oro.text.regex.Util.substitute((StringBuffer) appendBuffer,
	new Perl5Matcher(),
	(Pattern) charEntityPattern,
	(Substitution) new ReverseCharacterEntitySubstitution(),
	(String) str,
	(int) org.apache.oro.text.regex.Util.SUBSTITUTE_ALL);

I get the following compile error, implying that this method does not exist:

    [javac] H:\x\y\z\a\b\util\XMLUtil.java:244: cannot resolve symbol
    [javac] symbol  : method substitute
(java.lang.StringBuffer,org.apache.oro.text.regex.Perl5Matcher,org.apache.or
o.text.regex.Pattern,org.apache.oro.text.regex.Substitution,java.lang.String
,int)
    [javac] location: class org.apache.oro.text.regex.Util
    [javac]
org.apache.oro.text.regex.Util.substitute(substitutionResult, new
Perl5Matcher(), (Pattern) charEntityPattern, (Substitution) new
ReverseCharacterEntitySubstitution(), (String) str, (int)
org.apache.oro.text.regex.Util.SUBSTITUTE_ALL);
    [javac]                                           ^
    [javac] 1 error


2. If I change the method I call from (1) to the following the class
compiles (i.e. remove the stringbuffer and assign to a string):

str = org.apache.oro.text.regex.Util.substitute(new Perl5Matcher(),
	(Pattern) charEntityPattern,
	(Substitution) new ReverseCharacterEntitySubstitution(),
	(String) str,
	(int) org.apache.oro.text.regex.Util.SUBSTITUTE_ALL);

3. My original Substitute implementation followed the signature of
appendSubstitution in the Javadoc to the letter, but produced the following
compile error:

    [javac] H:\x\y\z\a\b\util\ReverseCharacterEntitySubstitution.java:16:
com.xms.util.ReverseCharacterEntitySubstitution should be declared abstract;
it does not define
appendSubstitution(java.lang.StringBuffer,org.apache.oro.text.regex.MatchRes
ult,int,java.lang.String,org.apache.oro.text.regex.PatternMatcher,org.apache
.oro.text.regex.Pattern) in com.xms.util.ReverseCharacterEntitySubstitution
    [javac] public class ReverseCharacterEntitySubstitution implements
org.apache.oro.text.regex.Substitution {
    [javac]        ^
    [javac] 1 error

The class looked like this:

package a.b.util;

import org.apache.oro.text.regex.*;

/**
 */
public class ReverseCharacterEntitySubstitution implements
org.apache.oro.text.regex.Substitution {
    /**
     * Substitute the match, which is a charachter entity, with the
character it
     * represents.
     */
    public void appendSubstitution(StringBuffer appendBuffer,
                                   MatchResult match,
                                   int substitutionCount,
                                   PatternMatcherInput originalInput,
                                   PatternMatcher matcher,
                                   Pattern pattern){

        String entityMatch = match.toString();
        char replacement;
        try{
            if(entityMatch.startsWith("&#x")) {
                replacement = convertHexToChar(entityMatch);
            }
            else{
                replacement = convertDecToChar(entityMatch);
            }
            appendBuffer.append(replacement);
        }
        catch(NumberFormatException nfe){
            System.err.println("NumberFormat Exception converting char refs
to chars: "+nfe.toString());
            nfe.printStackTrace();
            appendBuffer.append(entityMatch);
        }
    }

    /**
     * Convert a hex char ref (&#xdd;) to the char it represents
     */
    private char convertHexToChar(String charRef){
...
    }

    /**
     * Convert a decimal char ref (&#dd;) to the char it represents
     */
    private char convertDecToChar(String charRef){
...
    }
}//End of class ReverseCharacterEntitySubstitution


4. Changing appendSubstitution to the method signature (implied in the
compile error) it compiles but (possibly) causes a runtime
AbstractMethodError when Util.substitute(...) is called.

--8<--
    public void appendSubstitution(StringBuffer appendBuffer,
                                   MatchResult match,
                                   int substitutionCount,
                                   String originalInput,
                                   PatternMatcher matcher,
                                   Pattern pattern){
    }
--8<--


5. Adding both appendSubstitution signatures from (4) and (5) to my
Substitute method seems to work but since it's all been through guesswork
I'm a little worried about using the code!

Can anyone shed any light on my problem please? I've had the same behaviour
with ORO 2.0.5 and 2.0.6; if it makes any difference I'm compiling with Ant
on Win2000 java -version produces the following:

C:\>java -version
java version "1.3.1_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1_03-b03)
Java HotSpot(TM) Client VM (build 1.3.1_03-b03, mixed mode)

Even more intruigingly, a javap -public on both classes produces the
following:

javap -public org.apache.oro.text.regex.Util
No sourcepublic final class org.apache.oro.text.regex.Util extends
java.lang.Object {
    public static final int SUBSTITUTE_ALL;
    public static final int SPLIT_ALL;
    public static void split(java.util.Collection,
org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.regex.Pattern,
java.lang.String, int);
    public static void split(java.util.Collection,
org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.regex.Pattern,
java.lang.String);
    public static java.util.Vector
split(org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.regex.Pat
tern, java.lang.String, int);
    public static java.util.Vector
split(org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.regex.Pat
tern, java.lang.String);
    public static java.lang.String
substitute(org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.rege
x.Pattern, org.apache.oro.text.regex.Substitution, java.lang.String, int);
    public static java.lang.String
substitute(org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.rege
x.Pattern, org.apache.oro.text.regex.Substitution, java.lang.String);
    public static int substitute(java.lang.StringBuffer,
org.apache.oro.text.regex.PatternMatcher,org.apache.oro.text.regex.Pattern,
org.apache.oro.text.regex.Substitution, java.lang.String, int);
    public static int substitute(java.lang.StringBuffer,
org.apache.oro.text.reg
ex.PatternMatcher, org.apache.oro.text.regex.Pattern,
org.apache.oro.text.regex.
Substitution, org.apache.oro.text.regex.PatternMatcherInput, int);
}

No sourcepublic interface org.apache.oro.text.regex.Substitution
    /* ACC_SUPER bit NOT set */
{
    public abstract void appendSubstitution(java.lang.StringBuffer,
org.apache.o
ro.text.regex.MatchResult, int,
org.apache.oro.text.regex.PatternMatcherInput, o
rg.apache.oro.text.regex.PatternMatcher, org.apache.oro.text.regex.Pattern);
}

Which shows that the jar file contains the javadoc'd methods in (1) and (3)!


On the upside, the rest of my ORO code works a treat!  

Thanks

Dave


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>