santiagopg    2002/12/04 08:11:18

  Modified:    java/src/org/apache/xalan/xsltc/dom NodeSortRecord.java
                        NodeSortRecordFactory.java
  Added:       java/src/org/apache/xalan/xsltc CollatorFactory.java
               java/src/org/apache/xalan/xsltc/dom CollatorFactoryBase.java
  Log:
   Patch provided by W. Eliot Kimber to support user-defined collators. A
  class implementing the org.apache.xalan.xsltc.CollatorFactory interface
  can be specified from the command line by setting the property:
  
   org.apache.xalan.xsltc.COLLATOR_FACTORY
  
   The class org.apache.xalan.xsltc.dom.CollatorFactoryBase will be used
  by default.
  
  Revision  Changes    Path
  1.1                  
xml-xalan/java/src/org/apache/xalan/xsltc/CollatorFactory.java
  
  Index: CollatorFactory.java
  ===================================================================
  /*
   * @(#)$Id: CollatorFactory.java,v 1.1 2002/12/04 16:11:17 santiagopg Exp $
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Sun
   * Microsystems., http://www.sun.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * @author W. Eliot Kimber ([EMAIL PROTECTED])
   * @author Santiago Pericas-Geertsen
   *
   */
  
  package org.apache.xalan.xsltc;
  
  import java.text.Collator;
  import java.util.Locale;
  
  public interface CollatorFactory {
      
      public Collator getCollator(String lang, String country);
      public Collator getCollator(Locale locale);
  }
  
  
  
  1.10      +26 -3     
xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java
  
  Index: NodeSortRecord.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecord.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- NodeSortRecord.java       26 Nov 2002 16:00:35 -0000      1.9
  +++ NodeSortRecord.java       4 Dec 2002 16:11:18 -0000       1.10
  @@ -59,6 +59,7 @@
    * @author Jacek Ambroziak
    * @author Santiago Pericas-Geertsen
    * @author Morten Jorgensen
  + * @author W. Eliot Kimber ([EMAIL PROTECTED])
    *
    */
   
  @@ -70,6 +71,8 @@
   import java.text.CollationKey;
   
   import org.apache.xalan.xsltc.DOM;
  +import org.apache.xalan.xsltc.TransletException;
  +import org.apache.xalan.xsltc.CollatorFactory;
   import org.apache.xalan.xsltc.runtime.AbstractTranslet;
   
   /**
  @@ -93,6 +96,7 @@
        * specifies a different language (will be updated iff _locale is 
updated).
        */
       protected Collator _collator = Collator.getInstance();
  +    protected CollatorFactory _collatorFactory;
   
       protected int   _levels = 1;
       protected int[] _compareType;
  @@ -126,8 +130,9 @@
        * to the default constructor.
        */
       public final void initialize(int node, int last, DOM dom,
  -                              AbstractTranslet translet,
  -                              int[] order, int[] type) {
  +      AbstractTranslet translet, int[] order, int[] type,
  +      NodeSortRecordFactory nsrFactory) throws TransletException
  +    {
        _dom = dom;
        _node = node;
        _last = last;
  @@ -139,6 +144,24 @@
        _compareType = type;
   
        _values = new Object[_levels];
  +
  +     // -- W. Eliot Kimber ([EMAIL PROTECTED])
  +        String colFactClassname = 
  +         System.getProperty("org.apache.xalan.xsltc.COLLATOR_FACTORY");
  +
  +        if (colFactClassname != null) {
  +            try {
  +             Object candObj = nsrFactory.loadTranslet(colFactClassname);
  +                _collatorFactory = (CollatorFactory)candObj;
  +            } 
  +         catch (ClassNotFoundException e) {
  +             throw new TransletException(e);
  +            }
  +        } 
  +     else {
  +         _collatorFactory = new CollatorFactoryBase();
  +        }
  +        _collator = _collatorFactory.getCollator(_locale);
       }
   
       /**
  
  
  
  1.8       +4 -5      
xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java
  
  Index: NodeSortRecordFactory.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xalan/xsltc/dom/NodeSortRecordFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- NodeSortRecordFactory.java        8 Nov 2001 14:11:15 -0000       1.7
  +++ NodeSortRecordFactory.java        4 Dec 2002 16:11:18 -0000       1.8
  @@ -82,7 +82,7 @@
       private int   _type[];
       private final AbstractTranslet _translet;
   
  -    private Class loadTranslet(String name) throws ClassNotFoundException {
  +    public Class loadTranslet(String name) throws ClassNotFoundException {
        // First try to load the class using the default class loader
        try {
            return Class.forName(name);
  @@ -92,8 +92,7 @@
        }
   
        // Then try to load the class using the bootstrap class loader
  -     TransletLoader loader = new TransletLoader();
  -     return loader.loadTranslet(name);
  +     return new TransletLoader().loadTranslet(name);
       }
   
       /**
  @@ -144,7 +143,7 @@
   
        final NodeSortRecord sortRecord =
            (NodeSortRecord)_class.newInstance();
  -     sortRecord.initialize(node, last, _dom, _translet, _order, _type);
  +     sortRecord.initialize(node, last, _dom, _translet, _order, _type, this);
        return sortRecord;
       }
   
  
  
  
  1.1                  
xml-xalan/java/src/org/apache/xalan/xsltc/dom/CollatorFactoryBase.java
  
  Index: CollatorFactoryBase.java
  ===================================================================
  /*
   * @(#)$Id: CollatorFactoryBase.java,v 1.1 2002/12/04 16:11:18 santiagopg Exp 
$
   *
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 2001, Sun
   * Microsystems., http://www.sun.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * @author W. Eliot Kimber ([EMAIL PROTECTED])
   *
   */
  
  package org.apache.xalan.xsltc.dom;
  
  import java.text.Collator;
  import java.util.Locale;
  
  import org.apache.xalan.xsltc.CollatorFactory;
  
  public class CollatorFactoryBase implements CollatorFactory {
      
      public CollatorFactoryBase() {
      }
      
      public Collator getCollator(String lang, String country) {
          return Collator.getInstance(new Locale(lang, country));
      }
      
      public Collator getCollator(Locale locale) {
          return Collator.getInstance(locale);
      }
  }
  
  
  

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

Reply via email to