You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-dev@xml.apache.org by ks...@apache.org on 2002/02/26 08:17:02 UTC

cvs commit: xml-xindice/java/src/org/apache/xindice/tools/command AddDocument.java RetrieveDocument.java

kstaken     02/02/25 23:17:02

  Modified:    java/src/org/apache/xindice/tools/command AddDocument.java
                        RetrieveDocument.java
  Log:
  Adding simple encoding patch for commandline tools.
  Submitted by: James Bates
  Reviewed by: Kimbro Staken
  
  Revision  Changes    Path
  1.2       +14 -9     xml-xindice/java/src/org/apache/xindice/tools/command/AddDocument.java
  
  Index: AddDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/tools/command/AddDocument.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AddDocument.java	6 Dec 2001 19:33:57 -0000	1.1
  +++ AddDocument.java	26 Feb 2002 07:17:02 -0000	1.2
  @@ -56,7 +56,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: AddDocument.java,v 1.1 2001/12/06 19:33:57 bradford Exp $
  + * $Id: AddDocument.java,v 1.2 2002/02/26 07:17:02 kstaken Exp $
    */
   
   import java.util.Hashtable;
  @@ -73,6 +73,11 @@
   
   import org.w3c.dom.*;
   
  +import javax.xml.transform.Transformer;
  +import javax.xml.transform.TransformerFactory;
  +import javax.xml.transform.stream.StreamResult;
  +import javax.xml.transform.stream.StreamSource;
  +
   /**
    * AddDocument.java is designed to let the user add Single Documents
    * and/or Multiple Documents to an existing Collection or Nested Collection
  @@ -111,21 +116,21 @@
               return false;
            }
   
  -         // Open a new file input stream and read in the document
  +         // Parse in XML using JAXP libraries
  +         StringWriter inString = new StringWriter();
            File file = new File((String) table.get("filePath"));
  -         FileInputStream insr = new FileInputStream(file);
  -
  -         byte[] fileBuffer = new byte[(int) file.length()];
  -
  -         insr.read(fileBuffer);
  -         insr.close();
   
  +         Transformer tf 
  +                = TransformerFactory.newInstance().newTransformer();
  +         tf.transform(new StreamSource(new FileInputStream(file)),
  +                      new StreamResult(inString));
  +         
            // Create the XMLResource and store the document
            XMLResource resource =
                  (XMLResource) col.createResource((String) table.get("nameOf"),
                     "XMLResource");
   
  -         resource.setContent(new String(fileBuffer));
  +         resource.setContent(inString.toString());
            col.storeResource(resource);
                              
            System.out.println("Added document " + table.get("collection") + "/" +
  
  
  
  1.2       +2 -2      xml-xindice/java/src/org/apache/xindice/tools/command/RetrieveDocument.java
  
  Index: RetrieveDocument.java
  ===================================================================
  RCS file: /home/cvs/xml-xindice/java/src/org/apache/xindice/tools/command/RetrieveDocument.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RetrieveDocument.java	6 Dec 2001 19:33:57 -0000	1.1
  +++ RetrieveDocument.java	26 Feb 2002 07:17:02 -0000	1.2
  @@ -56,7 +56,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    *
  - * $Id: RetrieveDocument.java,v 1.1 2001/12/06 19:33:57 bradford Exp $
  + * $Id: RetrieveDocument.java,v 1.2 2002/02/26 07:17:02 kstaken Exp $
    */
   
   import java.util.Hashtable;
  @@ -118,7 +118,7 @@
                           
                           System.out.println("Writing...");
                           
  -                        out.write(documentstr.getBytes());
  +                        out.write(documentstr.getBytes("utf-8"));
                           out.close();
                           
                           System.out.println("Wrote file " + table.get("filePath") );