xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From daver...@apache.org
Subject cvs commit: xml-xmlbeans/v2/test/tools/src/tools/util JarUtil.java
Date Thu, 04 Nov 2004 00:25:33 GMT
daveremy    2004/11/03 16:25:33

  Modified:    v2/test/cases/xbean/scomp/attribute
                        LocalAttrFixedDefault.xsd
               v2/test/src/dom/detailed AttrNamespaceTest.java
                        MoveImportNodeTest.java
               v2/test/src/dom/detailed/w3c alltests.java
               v2/test/src/misc/checkin CharUtilTests.java
               v2/test/src/scomp/contentType/complex/detailed
                        MixedContentTest.java NamedTest.java
               v2/test/src/scomp/elements/detailed GlobalEltFixed.java
                        GlobalEltNillable.java NillTest.java
               v2/test/src/xmlcursor/checkin CopyTest.java StoreTests.java
               v2/test/src/xmlcursor/detailed InsertAttributeTest2.java
                        ToBookmarkTest.java
               v2/test/src/xmlcursor/jsr173/common GeneralMethodsTest.java
               v2/test/src/xmlcursor/jsr173/detailed
                        CursorGeneralMethodsTest.java
               v2/test/src/xmlobject/detailed
                        XmlObjectAbstractClassTest.java
               v2/test/tools/src/tools/util JarUtil.java
  Added:       v2/test/cases/xbean/scomp/derivation/facets Facets.xsd
               v2/test/cases/xbean/xmlobject CR192525.xsd
               v2/test/src/scomp/derivation/restriction/facets/detailed
                        FacetsTest.java
  Log:
  Contributed by:Yana Kadiyska. Adding/fixing tests
  
  Revision  Changes    Path
  1.2       +1 -1      xml-xmlbeans/v2/test/cases/xbean/scomp/attribute/LocalAttrFixedDefault.xsd
  
  Index: LocalAttrFixedDefault.xsd
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/cases/xbean/scomp/attribute/LocalAttrFixedDefault.xsd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocalAttrFixedDefault.xsd	16 Aug 2004 17:36:10 -0000	1.1
  +++ LocalAttrFixedDefault.xsd	4 Nov 2004 00:25:32 -0000	1.2
  @@ -8,7 +8,7 @@
     <xsd:attribute name="attDefault" type="xsd:integer" default="1"/>
   
     <xsd:complexType name="LocalAttrFixedDefaultT">
  -      <xsd:attribute ref="attFixed" fixed="NEWXBeanAttrStr" />
  +      <xsd:attribute ref="attFixed"/>
         <xsd:attribute ref="attDefault" default="2"/>
     </xsd:complexType>
   
  
  
  
  1.1                  xml-xmlbeans/v2/test/cases/xbean/scomp/derivation/facets/Facets.xsd
  
  Index: Facets.xsd
  ===================================================================
  <xs:schema
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace="http://xbean/scomp/derivation/facets/Facets"
      xmlns="http://xbean/scomp/derivation/facets/Facets"
  >
  
      <xs:simpleType name="MinMaxInclusiveT">
          <xs:restriction base="xs:integer">
              <xs:minInclusive value="2"/>
              <xs:maxInclusive value="10"/>
          </xs:restriction>
      </xs:simpleType>
  
      <xs:simpleType name="MinMaxInclusiveDateT">
              <xs:restriction base="xs:date">
                  <xs:minInclusive value="2003-12-10"/>
                  <xs:maxInclusive value="2003-12-25"/>
              </xs:restriction>
          </xs:simpleType>
  
  
  
      <xs:simpleType name="MinMaxExclusiveT">
          <xs:restriction base="xs:integer">
              <xs:minExclusive value="2"/>
              <xs:maxExclusive value="10"/>
          </xs:restriction>
      </xs:simpleType>
  
       <xs:simpleType name="MinMaxExclusiveDateT">
          <xs:restriction base="xs:date">
              <xs:minExclusive value="2003-12-10"/>
              <xs:maxExclusive value="2003-12-25"/>
          </xs:restriction>
      </xs:simpleType>
  
  
      <xs:simpleType name="LengthT">
             <xs:restriction base="xs:string">
                 <xs:length value="2"/>
             </xs:restriction>
         </xs:simpleType>
  
      <xs:simpleType name="MinMaxLengthT">
             <xs:restriction base="xs:string">
                 <xs:minLength value="2"/>
                 <xs:maxLength value="5"/>
             </xs:restriction>
         </xs:simpleType>
  
      <xs:simpleType name="DigitsT">
             <xs:restriction base="xs:decimal">
                 <xs:totalDigits value="3"/>
                 <xs:fractionDigits value="1"/>
             </xs:restriction>
         </xs:simpleType>
  
      <xs:simpleType name="WST">
             <xs:restriction base="xs:string">
                 <xs:whiteSpace value="replace"/>
             </xs:restriction>
         </xs:simpleType>
  
       <xs:simpleType name="EnumT">
             <xs:restriction base="xs:string">
                 <xs:enumeration value="a"/>
                 <xs:enumeration value="b"/>
                 <xs:enumeration value="c"/>
             </xs:restriction>
         </xs:simpleType>
  
      <xs:simpleType name="PatternT">
             <xs:restriction base="xs:string">
                 <xs:pattern value="(a[^bc]d){3}"/>
             </xs:restriction>
         </xs:simpleType>
  
      <xs:element name="MinMaxInclusiveElt" type="MinMaxInclusiveT"/>
       <xs:element name="MinMaxInclusiveDateElt" type="MinMaxInclusiveDateT"/>
      <xs:element name="MinMaxExclusiveElt" type="MinMaxExclusiveT"/>
      <xs:element name="MinMaxExclusiveDateElt" type="MinMaxExclusiveDateT"/>
      <xs:element name="LengthElt" type="LengthT"/>
      <xs:element name="MinMaxLengthElt" type="MinMaxLengthT"/>
      <xs:element name="DigitsElt" type="DigitsT"/>
      <xs:element name="WSElt" type="WST"/>
      <xs:element name="EnumElt" type="EnumT"/>
      <xs:element name="PatternElt" type="PatternT"/>
  
  
  
  
  
  </xs:schema>
  
  
  1.1                  xml-xmlbeans/v2/test/cases/xbean/xmlobject/CR192525.xsd
  
  Index: CR192525.xsd
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://openuri.org/bea/samples/workshop" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="credit-card-data" type="wor:credit-card-dataType" xmlns:wor="http://openuri.org/bea/samples/workshop"/>
    <xs:complexType name="cardType">
      <xs:sequence>
        <xs:element type="xs:byte" name="available-credit" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
        <xs:element type="xs:byte" name="credit-used" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
      </xs:sequence>
      <xs:attribute type="xs:string" name="name" use="optional" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
      <xs:attribute type="xs:string" name="number" use="optional" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
    </xs:complexType>
    <xs:complexType name="customerType">
      <xs:sequence>
        <xs:element type="wor:cardType" name="card" maxOccurs="unbounded" minOccurs="0" xmlns:wor="http://openuri.org/bea/samples/workshop"/>
      </xs:sequence>
      <xs:attribute type="xs:byte" name="id" use="optional" xmlns:xs="http://www.w3.org/2001/XMLSchema"/>
    </xs:complexType>
    <xs:complexType name="credit-card-dataType">
      <xs:sequence>
        <xs:element type="wor:customerType" name="customer" maxOccurs="unbounded" minOccurs="0" xmlns:wor="http://openuri.org/bea/samples/workshop"/>
      </xs:sequence>
    </xs:complexType>
  </xs:schema>
  
  
  1.3       +71 -47    xml-xmlbeans/v2/test/src/dom/detailed/AttrNamespaceTest.java
  
  Index: AttrNamespaceTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/dom/detailed/AttrNamespaceTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AttrNamespaceTest.java	17 Jun 2004 16:26:45 -0000	1.2
  +++ AttrNamespaceTest.java	4 Nov 2004 00:25:32 -0000	1.3
  @@ -23,44 +23,47 @@
   import org.w3c.dom.Document;
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
  +import org.xml.sax.InputSource;
  +import org.apache.xmlbeans.XmlObject;
  +
  +import java.io.StringReader;
  +import java.io.IOException;
   
   
   /**
    * Tests conversion of regular attributes to namespaces and vv
  - *
  - *
  - *
    */
   
  -public class AttrNamespaceTest extends TestCase{
  -    String sXml="<foo at0=\"nonsattr\"></foo>";
  -    String sXmlNS="<foo xmlns:myns=\"http://foo.org\"><myns:bar/></foo>";
  +public class AttrNamespaceTest extends TestCase {
  +    String sXml = "<foo at0=\"nonsattr\"></foo>";
  +    String sXmlNS = "<foo xmlns:myns=\"http://foo.org\"><myns:bar/></foo>";
       Document m_doc,
  -	m_docNS;
  +    m_docNS;
       Node m_node;
   
   
  -    public AttrNamespaceTest(String name){
  -	super(name);
  +    public AttrNamespaceTest(String name) {
  +        super(name);
       }
  +
       public static Test suite() {
  -	return new TestSuite(AttrNamespaceTest.class);
  +        return new TestSuite(AttrNamespaceTest.class);
       }
   
  -    public void testDefaultNamespace(){
  -	//assertEquals(true,((Element)m_node).hasAttribute("xmlns"));
  +    public void testDefaultNamespace() {
  +        //assertEquals(true,((Element)m_node).hasAttribute("xmlns"));
       }
   
  -    public void testAttr2Namespace(){
  -	Attr at=(Attr)((Element)m_node).getAttributeNode("at0");
  -	String namespaceURI="http://foo.org";
  -	String qualifiedName="xmlns:bar";
  -	at.setValue(namespaceURI);
  -	m_node.appendChild(m_doc.createElementNS(namespaceURI,qualifiedName));
  -	Element bar=(Element)((Element)m_node).getElementsByTagNameNS(namespaceURI,"bar").item(0);
  -	assertFalse(null==bar);
  -	assertEquals(namespaceURI,bar.getNamespaceURI());
  -	assertEquals(qualifiedName,bar.getNodeName());
  +    public void testAttr2Namespace() {
  +        Attr at = (Attr) ((Element) m_node).getAttributeNode("at0");
  +        String namespaceURI = "http://foo.org";
  +        String qualifiedName = "xmlns:bar";
  +        at.setValue(namespaceURI);
  +        m_node.appendChild(m_doc.createElementNS(namespaceURI, qualifiedName));
  +        Element bar = (Element) ((Element) m_node).getElementsByTagNameNS(namespaceURI, "bar").item(0);
  +        assertFalse(null == bar);
  +        assertEquals(namespaceURI, bar.getNamespaceURI());
  +        assertEquals(qualifiedName, bar.getNodeName());
           /*
   	org.apache.xmlbeans.XmlCursor cur=Public2.getCursor(m_node);
   	assertFalse(cur.isAttr());
  @@ -69,41 +72,62 @@
   	*/
       }
   
  -    public void testNamespace2Attr(){
  -	m_node=m_docNS.getFirstChild();
  +    public void testNamespace2Attr() {
  +        m_node = m_docNS.getFirstChild();
   
  -	int nAttrCount=((Element)m_node).getAttributes().getLength();
  -	((Element)m_node).removeAttribute("xmlns:myns");
  -	assertEquals(nAttrCount-1,((Element)m_node).getAttributes().getLength());//assertRemoved
  -	((Element)m_node).setAttribute("myns","reg_attr_val");
  -	Attr at=(Attr)((Element)m_node).getAttributeNode("myns");
  +        int nAttrCount = ((Element) m_node).getAttributes().getLength();
  +        ((Element) m_node).removeAttribute("xmlns:myns");
  +        assertEquals(nAttrCount - 1, ((Element) m_node).getAttributes().getLength());//assertRemoved
  +        ((Element) m_node).setAttribute("myns", "reg_attr_val");
  +        Attr at = (Attr) ((Element) m_node).getAttributeNode("myns");
   
  -	assertEquals("reg_attr_val",at.getValue());
  -	assertEquals("myns:bar",m_node.getFirstChild().getNodeName());
  +        assertEquals("reg_attr_val", at.getValue());
  +        assertEquals("myns:bar", m_node.getFirstChild().getNodeName());
   
  -	/*
  +        /*
   
  -	if(!(m_node instanceof DomImpl))
  -	    fail(m_node.getClass().toString());
  +        if(!(m_node instanceof DomImpl))
  +            fail(m_node.getClass().toString());
   
  -	org.apache.xmlbeans.XmlCursor  cur=Public2.getCursor(m_node);
  +        org.apache.xmlbeans.XmlCursor  cur=Public2.getCursor(m_node);
   
  -	assertFalse(cur.isNamespace());
  -	assertTrue(cur.isAnyAttr());
  -	assertTrue(cur.isAttr());
  -	*/
  +        assertFalse(cur.isNamespace());
  +        assertTrue(cur.isAnyAttr());
  +        assertTrue(cur.isAttr());
  +        */
       }
   
  +    /**
  +     * Insert a namespace attribute and set it's value to
  +     * ""/NULL...Do we get an error since now there is a prefix
  +     * with NULL URI?
  +     */
  +    public void testInsertBadAttribute() throws Exception{
  +        String sER="<foo/>";
  +        org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
  +        parser.parse(new InputSource(new StringReader(sER)));
  +        Document xercesDocument = parser.getDocument();
  +        Document beanDocument=(Document)XmlObject.Factory.parse(sER)
  +                .getDomNode();
  +        Attr at_xerces=xercesDocument.createAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:ns");
  +        Attr at_bean=beanDocument.createAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:ns");
  +
  +        beanDocument.getDocumentElement().setAttributeNode(at_bean);
  +        xercesDocument.getDocumentElement().setAttributeNode(at_xerces);
  +        at_bean.setValue(null);
  +        at_xerces.setValue(null);
  +         at_bean.setValue("");
  +        at_xerces.setValue("");
  +    }
   
   
  +    public void setUp() throws Exception {
   
  -    public void setUp() throws Exception{
  -
  -	if (sXml==null && sXmlNS==null) throw new IllegalArgumentException("Test bug : Initialize xml strings");
  -        Loader loader=Loader.getLoader();
  -	m_doc=(org.w3c.dom.Document)loader.load(sXml);
  -	if(sXmlNS!=null && sXmlNS.length()>0)
  -	    m_docNS=(org.w3c.dom.Document)loader.load(sXmlNS);
  -	m_node=m_doc.getFirstChild();
  +        if (sXml == null && sXmlNS == null) throw new IllegalArgumentException("Test bug : Initialize xml strings");
  +        Loader loader = Loader.getLoader();
  +        m_doc = (org.w3c.dom.Document) loader.load(sXml);
  +        if (sXmlNS != null && sXmlNS.length() > 0)
  +            m_docNS = (org.w3c.dom.Document) loader.load(sXmlNS);
  +        m_node = m_doc.getFirstChild();
       }
   }
  
  
  
  1.3       +3 -1      xml-xmlbeans/v2/test/src/dom/detailed/MoveImportNodeTest.java
  
  Index: MoveImportNodeTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/dom/detailed/MoveImportNodeTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MoveImportNodeTest.java	17 Jun 2004 16:26:45 -0000	1.2
  +++ MoveImportNodeTest.java	4 Nov 2004 00:25:32 -0000	1.3
  @@ -87,7 +87,8 @@
       }
   
       public void testMoveDiffImplementations() throws Exception{
  -	org.apache.xerces.parsers.DOMParser parser = new org.apache.xerces.parsers.DOMParser();
  +	org.apache.xerces.parsers.DOMParser parser =
  +            new org.apache.xerces.parsers.DOMParser();
   
   
   	parser.parse(new InputSource(new StringReader(sXmlNS)));
  @@ -116,6 +117,7 @@
       }
   
   
  +   // public void 
       public void testImportSameDoc(){
   	//inspired by nist documentimportnode10?
   
  
  
  
  1.5       +1 -1      xml-xmlbeans/v2/test/src/dom/detailed/w3c/alltests.java
  
  Index: alltests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/dom/detailed/w3c/alltests.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- alltests.java	7 Oct 2004 22:07:43 -0000	1.4
  +++ alltests.java	4 Nov 2004 00:25:32 -0000	1.5
  @@ -95,7 +95,7 @@
         sink.addTestSuite(documentimportnode18.class);
        // sink.addTestSuite(documentimportnode19.class);
        // sink.addTestSuite(documentimportnode20.class);
  -      sink.addTestSuite(documentimportnode21.class);
  +     // sink.addTestSuite(documentimportnode21.class);
       //  sink.addTestSuite(documentimportnode22.class);
       //  sink.addTestSuite(documenttypeinternalSubset01.class);
        // sink.addTestSuite(documenttypepublicid01.class);
  
  
  
  1.2       +2 -1      xml-xmlbeans/v2/test/src/misc/checkin/CharUtilTests.java
  
  Index: CharUtilTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/misc/checkin/CharUtilTests.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CharUtilTests.java	9 Oct 2004 17:30:17 -0000	1.1
  +++ CharUtilTests.java	4 Nov 2004 00:25:32 -0000	1.2
  @@ -39,7 +39,8 @@
       }
   
       private static class Triple
  -    {
  +    {                                 
  +
           Triple ( Object src, int off, int cch )
           {
               _src = src;
  
  
  
  1.5       +1 -1      xml-xmlbeans/v2/test/src/scomp/contentType/complex/detailed/MixedContentTest.java
  
  Index: MixedContentTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/scomp/contentType/complex/detailed/MixedContentTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MixedContentTest.java	15 Sep 2004 19:14:21 -0000	1.4
  +++ MixedContentTest.java	4 Nov 2004 00:25:32 -0000	1.5
  @@ -176,7 +176,7 @@
           assertTrue (! doc.validate(validateOptions));
           showErrors();
           String[] expected=new String[]
  -        {XmlErrorCodes.ELEM_LOCALLY_VALID};
  +        {XmlErrorCodes.ELEM_LOCALLY_VALID$FIXED_WITH_CONTENT};
           assertTrue(compareErrorCodes(expected));
   
       }
  
  
  
  1.2       +0 -1      xml-xmlbeans/v2/test/src/scomp/contentType/complex/detailed/NamedTest.java
  
  Index: NamedTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/scomp/contentType/complex/detailed/NamedTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NamedTest.java	16 Aug 2004 18:01:55 -0000	1.1
  +++ NamedTest.java	4 Nov 2004 00:25:32 -0000	1.2
  @@ -26,7 +26,6 @@
   import xbean.scomp.contentType.named.NamedMixedEltDocument;
   import xbean.scomp.contentType.named.MixedT;
   
  -import tools.xml.XmlComparator;
   import scomp.common.BaseCase;
   
   /**
  
  
  
  1.1                  xml-xmlbeans/v2/test/src/scomp/derivation/restriction/facets/detailed/FacetsTest.java
  
  Index: FacetsTest.java
  ===================================================================
  /*   Copyright 2004 The Apache Software Foundation
   *
   *   Licensed under the Apache License, Version 2.0 (the "License");
   *   you may not use this file except in compliance with the License.
   *   You may obtain a copy of the License at
   *
   *       http://www.apache.org/licenses/LICENSE-2.0
   *
   *   Unless required by applicable law or agreed to in writing, software
   *   distributed under the License is distributed on an "AS IS" BASIS,
   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *   See the License for the specific language governing permissions and
   *  limitations under the License.
   */
  package scomp.derivation.restriction.facets.detailed;
  
  import scomp.common.BaseCase;
  import xbean.scomp.derivation.facets.facets.*;
  
  import java.math.BigDecimal;
  import java.util.Calendar;
  import java.util.GregorianCalendar;
  import java.util.Date;
  import java.util.TimeZone;
  
  import org.apache.xmlbeans.XmlErrorCodes;
  
  /**
   * Date: Oct 25, 2004
   * Time: 1:23:08 PM
   *
   * @owner ykadiysk
   */
  public class FacetsTest extends BaseCase {
  
      public void testMinMaxInclusiveElt() throws Throwable {
          MinMaxInclusiveEltDocument doc =
                  MinMaxInclusiveEltDocument.Factory.newInstance();
          doc.setMinMaxInclusiveElt(3);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MIN_INCLUSIVE_VALID};
  
          doc.setMinMaxInclusiveElt(1);
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          clearErrors();
          errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MAX_INCLUSIVE_VALID};
          doc.setMinMaxInclusiveElt(11);
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
      }
  
      public void testMinMaxInclusiveDateElt() throws Throwable {
          MinMaxInclusiveDateEltDocument doc =
                  MinMaxInclusiveDateEltDocument.Factory.newInstance();
          TimeZone tz = TimeZone.getDefault();
          Calendar c = new GregorianCalendar(tz);
          c.set(2003, 11, 24);
          doc.setMinMaxInclusiveDateElt(c);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          c = new GregorianCalendar(2003, 11, 28);
          doc.setMinMaxInclusiveDateElt(c);
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MAX_INCLUSIVE_VALID};
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
  
      }
  
      public void testMinMaxExclusiveElt() throws Throwable {
          MinMaxExclusiveEltDocument doc =
                  MinMaxExclusiveEltDocument.Factory.newInstance();
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_LENGTH_VALID$LIST_LENGTH};
  
          doc.setMinMaxExclusiveElt(3);
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
          doc.setMinMaxExclusiveElt(1);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          doc.setMinMaxExclusiveElt(11);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
  
      }
  
      public void testMinMaxExclusiveDateElt() throws Throwable {
          MinMaxExclusiveDateEltDocument doc = MinMaxExclusiveDateEltDocument.Factory.newInstance();
          Calendar c = new GregorianCalendar(2003, 11, 24);
          doc.setMinMaxExclusiveDateElt(c);
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MAX_EXCLUSIVE_VALID};
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          c = new GregorianCalendar(2003, 11, 28);
          doc.setMinMaxExclusiveDateElt(c);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
  
  
      }
  
      public void testLengthElt() throws Throwable {
          LengthEltDocument doc = LengthEltDocument.Factory.newInstance();
          doc.setLengthElt("foobar");
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_LENGTH_VALID$STRING};
  
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          doc.setLengthElt("f");
          clearErrors();
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          doc.setLengthElt("fo");
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
      }
  
      public void testMinMaxLengthElt() throws Throwable {
          MinMaxLengthEltDocument doc = MinMaxLengthEltDocument.Factory.newInstance();
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MAX_LENGTH_VALID$STRING};
  
          doc.setMinMaxLengthElt("foobar");
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          doc.setMinMaxLengthElt("f");
          errExpected = new String[]{
              XmlErrorCodes.DATATYPE_MIN_LENGTH_VALID$STRING};
          clearErrors();
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          doc.setMinMaxLengthElt("fo");
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          doc.setMinMaxLengthElt("fooba");
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
  
      }
  
      public void testDigitsElt() throws Throwable {
          DigitsEltDocument doc = DigitsEltDocument.Factory.newInstance();
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_TOTAL_DIGITS_VALID};
  
          doc.setDigitsElt(new BigDecimal("234.5"));
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
          doc.setDigitsElt(new BigDecimal("12.3"));
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          clearErrors();
          errExpected = new String[]{
              XmlErrorCodes.DATATYPE_FRACTION_DIGITS_VALID};
          doc.setDigitsElt(new BigDecimal(".45"));
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
      }
  
      public void testWSElt() throws Throwable {
          fail("do this test");
      }
  
      public void testEnumElt() throws Throwable {
          EnumEltDocument doc = EnumEltDocument.Factory.newInstance();
          doc.setEnumElt(EnumT.A);
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          doc = EnumEltDocument.Factory.parse("<EnumElt xmlns=\"http://xbean/scomp/derivation/facets/Facets\">" +
                  "foo" +
                  "</EnumElt>");
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_ENUM_VALID};
  
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
      }
  
      public void testPatternElt() throws Throwable {
          PatternEltDocument doc = PatternEltDocument.Factory.newInstance();
          doc.setPatternElt("aedaedaed");
          try {
              assertTrue(doc.validate(validateOptions));
          } catch (Throwable t) {
              showErrors();
              throw t;
          }
          String[] errExpected = new String[]{
              XmlErrorCodes.DATATYPE_VALID$PATTERN_VALID};
  
          doc.setPatternElt("abdadad");
          assertTrue(!doc.validate(validateOptions));
          assertTrue(compareErrorCodes(errExpected));
  
  
      }
  }
  
  
  
  1.5       +2 -0      xml-xmlbeans/v2/test/src/scomp/elements/detailed/GlobalEltFixed.java
  
  Index: GlobalEltFixed.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/scomp/elements/detailed/GlobalEltFixed.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GlobalEltFixed.java	27 Sep 2004 21:27:18 -0000	1.4
  +++ GlobalEltFixed.java	4 Nov 2004 00:25:32 -0000	1.5
  @@ -84,4 +84,6 @@
           assertTrue(compareErrorCodes(errExpected));
   
       }
  +
  +   
   }
  
  
  
  1.5       +15 -5     xml-xmlbeans/v2/test/src/scomp/elements/detailed/GlobalEltNillable.java
  
  Index: GlobalEltNillable.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/scomp/elements/detailed/GlobalEltNillable.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- GlobalEltNillable.java	1 Sep 2004 17:27:12 -0000	1.4
  +++ GlobalEltNillable.java	4 Nov 2004 00:25:32 -0000	1.5
  @@ -46,6 +46,12 @@
   
       /**
        * Try to set a non-nillable elt. to nill
  +     * CR CR192914:
  +     * Regardless of Schema definition,
  +     * setXXX(null) will clear the value of the
  +     * XXX attribute/element and if the container is an
  +     * element, will also add the "xsi:nil" attribute.
  +
        *
        * @throws Exception
        */
  @@ -67,6 +73,12 @@
           }
   
           testElt.setGlobalEltNotNillable(null);
  +        //assert that value is cleared
  +        assertEquals("<glob:GlobalEltNotNillable " +
  +                "xsi:nil=\"true\" " +
  +                "xmlns:glob=\"http://xbean/scomp/element/GlobalEltNillable\" " +
  +                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>"
  +                ,testElt.xmlText());
           assertTrue(!testElt.validate(validateOptions));
           assertEquals(1, errorList.size());
           showErrors();
  @@ -74,9 +86,7 @@
                   new String[]{
                       XmlErrorCodes.ELEM_LOCALLY_VALID$NOT_NILLABLE};
                assertTrue(compareErrorCodes(errExpected));
  -
  -        fail("Why is the last setter not throwing an exception?");
  -    }
  +}
   
       //for nillable, fixed value cannot be specified (instance error) :
       // Walmsley p.137 footnote
  @@ -181,9 +191,9 @@
               throw t;
           }
           testElt.getGlobalEltComplex().setNil();
  -        assertEquals("<pre:GlobalEltComplex " +
  -                "xsi:nil=\"true\" " +
  +        assertEquals("<pre:GlobalEltComplex " +                 
                   "testattribute=\"foobar\" " +
  +                "xsi:nil=\"true\" " +
                   "xmlns:pre=\"http://xbean/scomp/element/GlobalEltNillable\" " +
                   "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
                   testElt.xmlText());
  
  
  
  1.4       +8 -2      xml-xmlbeans/v2/test/src/scomp/elements/detailed/NillTest.java
  
  Index: NillTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/scomp/elements/detailed/NillTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- NillTest.java	1 Sep 2004 17:27:12 -0000	1.3
  +++ NillTest.java	4 Nov 2004 00:25:32 -0000	1.4
  @@ -35,15 +35,19 @@
       /**
        * Tests exceptions when setting values to
        * null for non-nillable elems
  +     *  * CR CR192914:
  +     * Regardless of Schema definition,
  +     * setXXX(null) will clear the value of the
  +     * XXX attribute/element and if the container is an
  +     * element, will also add the "xsi:nil" attribute.
        */
       public void testNillable() {
           Contact contact = Contact.Factory.newInstance();
   
          // if the first name is null, xmlbeans doest not thrown any exceptions...
  -        //eric says this should fail:
  -        // elt is not nillable--at least xsi:nil should never be there
           contact.setFirstName(null);
          assertEquals("<firstName " +
  +               "xsi:nil=\"true\" " +
                  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>",
                  contact.xmlText());
           GlobalEltNotNillableDocument testElt = GlobalEltNotNillableDocument
  @@ -62,6 +66,8 @@
           //this can be null
           address.setGlobalEltNotNillable(null);
           // ...whereas this optional field cannot be null
  +        //???throws an exception:
  +        //likely due to the fact that it is a facet.
           address.setCityName(null);
       }
   }
  
  
  
  1.9       +20 -0     xml-xmlbeans/v2/test/src/xmlcursor/checkin/CopyTest.java
  
  Index: CopyTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/checkin/CopyTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CopyTest.java	9 Oct 2004 17:30:17 -0000	1.8
  +++ CopyTest.java	4 Nov 2004 00:25:33 -0000	1.9
  @@ -20,6 +20,7 @@
   import org.apache.xmlbeans.XmlCursor;
   import org.apache.xmlbeans.XmlCursor.TokenType;
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.XmlException;
   import tools.util.JarUtil;
   import xmlcursor.common.BasicCursorTestCase;
   import xmlcursor.common.Common;
  @@ -227,6 +228,25 @@
           assertEquals("Old ", xc1.getChars());
           // verify m_xc
           assertEquals("<po:city "+exp_ns+">Mill Valley</po:city>", m_xc.xmlText());
  +    }
  +
  +    //this is per CR128353
  +    public void testCopyNamespaceMigration()throws XmlException{
  +        String s1="<X xmlns=\"foo\" xmlns:xsi=\"bar\"><zzz>123</zzz></X>";
  +       String s2="<Y> ... [some content] ... </Y>";
  +        XmlCursor xc1=XmlObject.Factory.parse(s1).newCursor();
  +        xc1.toFirstContentToken();
  +        xc1.toFirstChild();
  +        XmlCursor xc2=XmlObject.Factory.parse(s2).newCursor();
  +        assertEquals(TokenType.START,xc2.toFirstContentToken());
  +        xc2.toNextToken();
  +        xc1.copyXml(xc2);
  +        xc2.toStartDoc();
  +        assertEquals("<Y>" +
  +                "<foo:zzz xmlns:foo=\"foo\" xmlns:xsi=\"bar\">123</foo:zzz>" +
  +                " ... [some content] ... </Y>",xc2.xmlText());
  +       xc1.dispose();
  +        xc2.dispose();
       }
   
   
  
  
  
  1.8       +2 -2      xml-xmlbeans/v2/test/src/xmlcursor/checkin/StoreTests.java
  
  Index: StoreTests.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/checkin/StoreTests.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StoreTests.java	9 Oct 2004 17:30:17 -0000	1.7
  +++ StoreTests.java	4 Nov 2004 00:25:33 -0000	1.8
  @@ -862,7 +862,7 @@
           return sb.toString();
       }
       
  -    public void testThatAssertIsOn ( )
  +    /*public void testThatAssertIsOn ( )
       {
           try
           {
  @@ -874,7 +874,7 @@
           {
           }
       }
  -            
  +     */
       static class MyMark extends XmlBookmark
       {
       }
  
  
  
  1.4       +4 -3      xml-xmlbeans/v2/test/src/xmlcursor/detailed/InsertAttributeTest2.java
  
  Index: InsertAttributeTest2.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/detailed/InsertAttributeTest2.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- InsertAttributeTest2.java	3 Nov 2004 18:04:59 -0000	1.3
  +++ InsertAttributeTest2.java	4 Nov 2004 00:25:33 -0000	1.4
  @@ -56,13 +56,14 @@
       public void testNormalCase(){
   	for (int i=0;i<50;i++){
   	    m_xc.insertAttribute("at"+i,"com.bea.foo");
  -	    System.out.println(i);
  +	    //System.out.println(i);
   	}
   	toPrevTokenOfType(m_xc, TokenType.ATTR);
   
   	int i=0;
   	do{
  -	    i++;System.out.println(m_xc.xmlText());
  +	    i++;
  +        //System.out.println(m_xc.xmlText());
   	}while(m_xc.toPrevAttribute());
   
   	assertEquals(i,50);
  @@ -122,7 +123,7 @@
   	toPrevTokenOfType(m_xc,XmlCursor.TokenType.START);
   	m_xc.toFirstAttribute();
   	int i=1;
  -	System.out.println(m_xc.xmlText());
  +//	System.out.println(m_xc.xmlText());
   	while(m_xc.toNextAttribute()) i++;
   	assertEquals(i,2);
       }
  
  
  
  1.9       +4 -1      xml-xmlbeans/v2/test/src/xmlcursor/detailed/ToBookmarkTest.java
  
  Index: ToBookmarkTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/detailed/ToBookmarkTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ToBookmarkTest.java	3 Nov 2004 18:04:59 -0000	1.8
  +++ ToBookmarkTest.java	4 Nov 2004 00:25:33 -0000	1.9
  @@ -281,7 +281,10 @@
           //move xc1 to outer space
           xc1.toBookmark(_theBookmark);
           assertTrue(!m_xc.isInSameDocument(xc1));
  -//        assertTrue(!m_xc.isLeftOf(xc1));
  +        try{
  +        assertTrue(!m_xc.isLeftOf(xc1));
  +            fail("Expected Illegal Arg exception--diff docs");
  +        }catch (IllegalArgumentException e){}
       }
   
       public void testToBookmarkPostRemove() throws Exception {
  
  
  
  1.4       +17 -3     xml-xmlbeans/v2/test/src/xmlcursor/jsr173/common/GeneralMethodsTest.java
  
  Index: GeneralMethodsTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/jsr173/common/GeneralMethodsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GeneralMethodsTest.java	14 Sep 2004 02:01:29 -0000	1.3
  +++ GeneralMethodsTest.java	4 Nov 2004 00:25:33 -0000	1.4
  @@ -17,6 +17,8 @@
   
   import org.apache.xmlbeans.XmlCursor;
   import org.apache.xmlbeans.XmlObject;
  +import org.apache.xmlbeans.XmlOptions;
  +import org.apache.xmlbeans.XmlDocumentProperties;
   
   import javax.xml.stream.XMLStreamReader;
   import javax.xml.stream.*;
  @@ -47,7 +49,8 @@
    */
   public abstract class GeneralMethodsTest extends TestCase {
   
  -     public abstract XMLStreamReader getStream(XmlCursor c)throws Exception;
  +     public abstract XMLStreamReader getStream(XmlCursor c)
  +             throws Exception;
       public void testClose() throws Exception {
           m_stream.close();
   
  @@ -61,7 +64,11 @@
             m_stream.next();
            m_stream.next();
           assertEquals("utf-8", m_stream.getCharacterEncodingScheme());
  -        assertEquals("utf-8", m_stream.getEncoding());
  +       //  Eric says this refers to actual encoding, not xml def
  +        //  assertEquals("utf-8", m_stream.getEncoding());
  +
  +         assertEquals(null, m_stream1.getCharacterEncodingScheme());
  +        assertEquals(null, m_stream1.getEncoding());
           //TODO: why is this still -1???
           Location l = m_stream.getLocation();
           assertEquals(-1, l.getCharacterOffset());
  @@ -111,7 +118,12 @@
           cur.insertProcInst("xml-stylesheet", "http://foobar");
   
           cur.toStartDoc();
  -        m_stream = getStream( cur );;
  +        XmlDocumentProperties opt=cur.documentProperties();
  +
  +        m_stream1 = getStream( cur );
  +
  +         opt.setEncoding("utf-8");
  +        m_stream=  getStream( cur );
   
       }
   
  @@ -121,7 +133,9 @@
       }
   
       private XMLStreamReader m_stream;
  +     private XMLStreamReader m_stream1;
       private XmlCursor cur;
  +    private XmlOptions opt;
   
   
   }
  
  
  
  1.3       +3 -1      xml-xmlbeans/v2/test/src/xmlcursor/jsr173/detailed/CursorGeneralMethodsTest.java
  
  Index: CursorGeneralMethodsTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlcursor/jsr173/detailed/CursorGeneralMethodsTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CursorGeneralMethodsTest.java	17 Jun 2004 16:29:40 -0000	1.2
  +++ CursorGeneralMethodsTest.java	4 Nov 2004 00:25:33 -0000	1.3
  @@ -21,6 +21,8 @@
   import javax.xml.stream.XMLStreamReader;
   
   import org.apache.xmlbeans.XmlCursor;
  +import org.apache.xmlbeans.XmlOptions;
  +import org.apache.xmlbeans.XmlDocumentProperties;
   /**
    *
    *
  @@ -31,6 +33,6 @@
   
       public  XMLStreamReader getStream(XmlCursor c)
       throws Exception{
  -        return c.newXMLStreamReader();
  +            return c.newXMLStreamReader();
       }
   }
  
  
  
  1.4       +6 -6      xml-xmlbeans/v2/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java
  
  Index: XmlObjectAbstractClassTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/src/xmlobject/detailed/XmlObjectAbstractClassTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XmlObjectAbstractClassTest.java	1 Jul 2004 00:01:30 -0000	1.3
  +++ XmlObjectAbstractClassTest.java	4 Nov 2004 00:25:33 -0000	1.4
  @@ -45,13 +45,13 @@
           // create the source file
           //String src = JarUtil.getResourceFromJarasStream(Common.XMLCASES_JAR, "xbean/xmlobject/SimpleXmlObject.java.txt");
           File to = new File("SimpleXmlObject.java");
  -        assertTrue("Could not create source file",
  -                copyTo(
  -                        new InputStreamReader(
  +        InputStreamReader r=new InputStreamReader(
                                   JarUtil.getResourceFromJarasStream(
  -                                        "xbean/xmlobject/SimpleXmlObject.java.txt")),
  -                        to));
  -        assertTrue("Could not compile SimpleXmlObject.java", compileFile(to));
  +                                        "xbean/xmlobject/SimpleXmlObject.java.txt"));
  +        assertTrue("Could not create source file",
  +                copyTo(r , to));
  +        assertTrue("Could not compile SimpleXmlObject.java",
  +                compileFile(to));
       }
   
   
  
  
  
  1.6       +1 -1      xml-xmlbeans/v2/test/tools/src/tools/util/JarUtil.java
  
  Index: JarUtil.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/test/tools/src/tools/util/JarUtil.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JarUtil.java	22 Jul 2004 20:31:52 -0000	1.5
  +++ JarUtil.java	4 Nov 2004 00:25:33 -0000	1.6
  @@ -1 +1 @@
  -package tools.util;


import java.io.BufferedReader;
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.jar.JarFile;
import java.util.jar.JarEntry;

/**
 * @author jacobd
 *         Date: Dec 8, 2003
 */

public class JarUtil {

    final static String EOL = System.getProperty("line.separator");

    /**
     * returns an File Object within the given jarFile as a String. jarFile must exist in classpath
     * pre: jar containing resource is in the classpath
     *
     * @param pathToResource
     * @return File
     */
    public static File getResourceFromJarasFile(String pathToResource)
            throws IOException {

        String[] tokens = pathToResource.split("/");
        String fileName = tokens[tokens.length - 1];
        tokens = fileName.split("\\.");
        String extension= (tokens.length < 2) ? null:"." + tokens[1];
        String prefix= ( tokens[0].length()<3 ) ? tokens[0]+"abc":tokens[0];
        File temp = File.createTempFile(prefix,extension );
        temp.deleteOnExit();
        PrintWriter pr = null;
        try {
            pr = new PrintWriter(new FileWriter(temp));
            String content = getResourceFromJar(pathToResource);
            pr.write(content);
        }
        finally {
            if (pr != null) pr.close();
        }
        return temp;
    }


    /**
     * returns an item within the given jarFile as a String. jarFile must exist in classpath
     *
     * @param pathToResource
     * @return String
     */

    public static String getResourceFromJar(String pathToResource)
            throws IOException {

        URL url = ClassLoader.getSystemClassLoader().getResource(
                pathToResource);
        if (url == null) {
            throw new FileNotFoundException(
                    "Resource: " + pathToResource + " was not found ");
        }
        JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
        JarFile jar = jarConnection.getJarFile();
        if (jar.getJarEntry(pathToResource) == null) {
            throw new FileNotFoundException(
                    "Resource: " + pathToResource + " was not found ");
        }

        JarEntry item = jar.getJarEntry(pathToResource);
        BufferedReader in = new BufferedReader(
                new InputStreamReader(jar.getInputStream(item)));

        StringBuffer stb = new StringBuffer();
        String buffer;

        while (!((buffer = in.readLine()) == null)) {
            stb.append(buffer + EOL);
        }
        return stb.toString();
    }

    /**
     * returns an item within the given jarFile as a Stream
     *
     * @param pathToResource
     * @return String
     */

    public static InputStream getResourceFromJarasStream(String pathToResource)
            throws IOException {
        return ClassLoader.getSystemClassLoader().getResourceAsStream(
                pathToResource);
    }

    /**
     * Returns the classpath entry of a given item on the classpath. The item should be a jarFile reference
     *
     * @param jarFile
     * @return String
     * @throws FileNotFoundException
     */

    public static String getFilePath(String jarFile)
            throws FileNotFoundException {
        String sClassPath = System.getProperty("java.class.path");
        int jarIndex = sClassPath.indexOf(jarFile);
        if (jarIndex <= 0) {
            throw new FileNotFoundException(
                    "File: " + jarFile + " was not found on the classpath");
        }

        String P = File.pathSeparator;
        String[] pathList = sClassPath.split(P);
        for (int i = 0; i < pathList.length; i++) {
            if (pathList[i].toLowerCase().endsWith(jarFile.toLowerCase())) {
                return pathList[i];
            }
        }
        throw new FileNotFoundException(
                "File: " + jarFile + " was not found when iterating classpath");
    }
}

  \ No newline at end of file
  +package tools.util;


import java.io.BufferedReader;
import java.io.*;
import java.net.JarURLConnection;
import java.net.URL;
import java.util.jar.JarFile;
import java.util.jar.JarEntry;

/**
 * @author jacobd
 *         Date: Dec 8, 2003
 */

public class JarUtil {

    final static String EOL = System.getProperty("line.separator");

    /**
     * returns an File Object within the given jarFile as a String. jarFile must exist in classpath
     * pre: jar containing resource is in the classpath
     *
     * @param pathToResource
     * @return File
     */
    public static File getResourceFromJarasFile(String pathToResource)
            throws IOException {

        String[] tokens = pathToResource.split("/");
        String fileName = tokens[tokens.length - 1];
        tokens = fileName.split("\\.");
        String extension= (tokens.length < 2) ? null:"." + tokens[1];
        String prefix= ( tokens[0].length()<3 ) ? tokens[0]+"abc":tokens[0];
        File temp = File.createTempFile(prefix,extension );
        temp.deleteOnExit();
        PrintWriter pr = null;
        try {
            pr = new PrintWriter(new FileWriter(temp));
            String content = getResourceFromJar(pathToResource);
            pr.write(content);
        }
        finally {
            if (pr != null) pr.close();
        }
        return temp;
    }


    /**
     * returns an item within the given jarFile as a String. jarFile must exist in classpath
     *
     * @param pathToResource
     * @return String
     */

    public static String getResourceFromJar(String pathToResource)
            throws IOException {

        URL url = ClassLoader.getSystemClassLoader().getResource(
                pathToResource);
        if (url == null) {
            throw new FileNotFoundException(
                    "Resource: " + pathToResource + " was not found ");
        }
        JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
        JarFile jar = jarConnection.getJarFile();
        if (jar.getJarEntry(pathToResource) == null) {
            throw new FileNotFoundException(
                    "Resource: " + pathToResource + " was not found ");
        }

        JarEntry item = jar.getJarEntry(pathToResource);
        BufferedReader in = new BufferedReader(
                new InputStreamReader(jar.getInputStream(item)));

        StringBuffer stb = new StringBuffer();
        String buffer;

        while (!((buffer = in.readLine()) == null)) {
            stb.append(buffer + EOL);
        }
        return stb.toString();
    }

    /**
     * returns an item within the given jarFile as a Stream
     *
     * @param pathToResource
     * @return String
     */

    public static InputStream getResourceFromJarasStream(String pathToResource)
            throws IOException {
         InputStream resource=ClassLoader.getSystemClassLoader().getResourceAsStream(
                pathToResource);
        if ( resource==null ){
            throw new IOException(" Resource "+pathToResource+" was not found. " +
                    "Make sure Jar w/ resource is on classpath");
        }
        return resource;
    }

    /**
     * Returns the classpath entry of a given item on the classpath. The item should be a jarFile reference
     *
     * @param jarFile
     * @return String
     * @throws FileNotFoundException
     */

    public static String getFilePath(String jarFile)
            throws FileNotFoundException {
        String sClassPath = System.getProperty("java.class.path");
        int jarIndex = sClassPath.indexOf(jarFile);
        if (jarIndex <= 0) {
            throw new FileNotFoundException(
                    "File: " + jarFile + " was not found on the classpath");
        }

        String P = File.pathSeparator;
        String[] pathList = sClassPath.split(P);
        for (int i = 0; i < pathList.length; i++) {
            if (pathList[i].toLowerCase().endsWith(jarFile.toLowerCase())) {
                return pathList[i];
            }
        }
        throw new FileNotFoundException(
                "File: " + jarFile + " was not found when iterating classpath");
    }
}

  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: commits-help@xmlbeans.apache.org


Mime
View raw message