< prev index next >

test/javax/xml/jaxp/unittest/catalog/CatalogTest.java

Print this page




   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package catalog;
  24 
  25 import java.io.IOException;
  26 import java.nio.file.Paths;

  27 import javax.xml.catalog.Catalog;
  28 import javax.xml.catalog.CatalogException;
  29 import javax.xml.catalog.CatalogFeatures;
  30 import javax.xml.catalog.CatalogFeatures.Feature;
  31 import javax.xml.catalog.CatalogManager;
  32 import javax.xml.catalog.CatalogResolver;
  33 import javax.xml.catalog.CatalogUriResolver;
  34 import javax.xml.parsers.ParserConfigurationException;
  35 import javax.xml.parsers.SAXParser;
  36 import javax.xml.parsers.SAXParserFactory;
  37 import javax.xml.transform.Source;

  38 import org.testng.Assert;
  39 import org.testng.annotations.BeforeClass;
  40 import org.testng.annotations.DataProvider;

  41 import org.testng.annotations.Test;
  42 import org.xml.sax.Attributes;
  43 import org.xml.sax.ErrorHandler;
  44 import org.xml.sax.InputSource;
  45 import org.xml.sax.SAXException;
  46 import org.xml.sax.XMLReader;
  47 import org.xml.sax.ext.DefaultHandler2;
  48 
  49 /*
  50  * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162, 8152527, 8154220
  51  * @summary Tests basic Catalog functions.
  52  */

  53 public class CatalogTest {
  54     static final String KEY_FILES = "javax.xml.catalog.files";
  55 
  56     public String filepath;
  57 
  58     /*
  59      * Initializing fields
  60      */
  61     @BeforeClass
  62     public void setUpClass() throws Exception {
  63         String file1 = getClass().getResource("first_cat.xml").getFile();
  64         if (System.getProperty("os.name").contains("Windows")) {
  65             filepath = file1.substring(1, file1.lastIndexOf("/") + 1);
  66         } else {
  67             filepath = file1.substring(0, file1.lastIndexOf("/") + 1);
  68         }
  69     }
  70 
  71     /*
  72      * @bug 8150187


 500             {"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()},
 501             {"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()},
 502             {"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()},
 503             {"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()},
 504             {"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()},
 505         };
 506     }
 507 
 508     SAXParser getParser() {
 509         SAXParser saxParser = null;
 510         try {
 511             SAXParserFactory factory = SAXParserFactory.newInstance();
 512             factory.setNamespaceAware(true);
 513             saxParser = factory.newSAXParser();
 514         } catch (ParserConfigurationException | SAXException e) {
 515         }
 516 
 517         return saxParser;
 518     }
 519 
 520 
 521     /**
 522      * SAX handler
 523      */
 524     public class MyHandler extends DefaultHandler2 implements ErrorHandler {
 525 
 526         StringBuilder textContent = new StringBuilder();
 527         SAXParser saxParser;
 528 
 529         MyHandler(SAXParser saxParser) {
 530             textContent.setLength(0);
 531             this.saxParser = saxParser;
 532         }
 533 
 534         String getResult() {
 535             return textContent.toString();
 536         }
 537 
 538         @Override
 539         public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {

 540             textContent.delete(0, textContent.length());
 541             try {
 542                 System.out.println("Element: " + uri + ":" + localName + " " + qName);
 543             } catch (Exception e) {
 544                 throw new SAXException(e);
 545             }
 546 
 547         }
 548 
 549         @Override
 550         public void characters(char ch[], int start, int length) throws SAXException {
 551             textContent.append(ch, start, length);
 552         }
 553     }
 554 }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package catalog;
  24 
  25 import java.io.IOException;
  26 import java.nio.file.Paths;
  27 
  28 import javax.xml.catalog.Catalog;
  29 import javax.xml.catalog.CatalogException;
  30 import javax.xml.catalog.CatalogFeatures;
  31 import javax.xml.catalog.CatalogFeatures.Feature;
  32 import javax.xml.catalog.CatalogManager;
  33 import javax.xml.catalog.CatalogResolver;
  34 import javax.xml.catalog.CatalogUriResolver;
  35 import javax.xml.parsers.ParserConfigurationException;
  36 import javax.xml.parsers.SAXParser;
  37 import javax.xml.parsers.SAXParserFactory;
  38 import javax.xml.transform.Source;
  39 
  40 import org.testng.Assert;
  41 import org.testng.annotations.BeforeClass;
  42 import org.testng.annotations.DataProvider;
  43 import org.testng.annotations.Listeners;
  44 import org.testng.annotations.Test;
  45 import org.xml.sax.Attributes;
  46 import org.xml.sax.ErrorHandler;
  47 import org.xml.sax.InputSource;
  48 import org.xml.sax.SAXException;
  49 import org.xml.sax.XMLReader;
  50 import org.xml.sax.ext.DefaultHandler2;
  51 
  52 /*
  53  * @bug 8081248, 8144966, 8146606, 8146237, 8151154, 8150969, 8151162, 8152527, 8154220
  54  * @summary Tests basic Catalog functions.
  55  */
  56 //@Listeners({jaxp.library.FilePolicy.class}) //uncomment this line after 8161176 is resolved
  57 public class CatalogTest {
  58     static final String KEY_FILES = "javax.xml.catalog.files";
  59 
  60     public String filepath;
  61 
  62     /*
  63      * Initializing fields
  64      */
  65     @BeforeClass
  66     public void setUpClass() throws Exception {
  67         String file1 = getClass().getResource("first_cat.xml").getFile();
  68         if (System.getProperty("os.name").contains("Windows")) {
  69             filepath = file1.substring(1, file1.lastIndexOf("/") + 1);
  70         } else {
  71             filepath = file1.substring(0, file1.lastIndexOf("/") + 1);
  72         }
  73     }
  74 
  75     /*
  76      * @bug 8150187


 504             {"testRewriteSystem1", "Test rewritesystem entry", "catalog.xml", "rewritesystem1.xml", getParser()},
 505             {"testSystemSuffix", "Test systemsuffix entry", "catalog.xml", "systemsuffix.xml", getParser()},
 506             {"testDelegateSystem", "Test delegatesystem entry", "catalog.xml", "delegatesystem.xml", getParser()},
 507             {"testPublic", "Test public entry", "catalog.xml", "public.xml", getParser()},
 508             {"testDelegatePublic", "Test delegatepublic entry", "catalog.xml", "delegatepublic.xml", getParser()},
 509         };
 510     }
 511 
 512     SAXParser getParser() {
 513         SAXParser saxParser = null;
 514         try {
 515             SAXParserFactory factory = SAXParserFactory.newInstance();
 516             factory.setNamespaceAware(true);
 517             saxParser = factory.newSAXParser();
 518         } catch (ParserConfigurationException | SAXException e) {
 519         }
 520 
 521         return saxParser;
 522     }
 523 

 524     /**
 525      * SAX handler
 526      */
 527     public class MyHandler extends DefaultHandler2 implements ErrorHandler {
 528 
 529         StringBuilder textContent = new StringBuilder();
 530         SAXParser saxParser;
 531 
 532         MyHandler(SAXParser saxParser) {
 533             textContent.setLength(0);
 534             this.saxParser = saxParser;
 535         }
 536 
 537         String getResult() {
 538             return textContent.toString();
 539         }
 540 
 541         @Override
 542         public void startElement(String uri, String localName, String qName, Attributes attributes)
 543                 throws SAXException {
 544             textContent.delete(0, textContent.length());
 545             try {
 546                 System.out.println("Element: " + uri + ":" + localName + " " + qName);
 547             } catch (Exception e) {
 548                 throw new SAXException(e);
 549             }
 550 
 551         }
 552 
 553         @Override
 554         public void characters(char ch[], int start, int length) throws SAXException {
 555             textContent.append(ch, start, length);
 556         }
 557     }
 558 }
< prev index next >