--- old/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java 2014-11-05 14:44:22.000000000 -0800 +++ new/test/javax/xml/jaxp/libs/jaxp/library/JAXPTestUtilities.java 2014-11-05 14:44:22.000000000 -0800 @@ -22,11 +22,15 @@ */ package jaxp.library; - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import static org.testng.Assert.fail; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; /** * This is an interface provide basic support for JAXP functional test. @@ -60,13 +64,13 @@ /** * Compare contents of golden file with test output file line by line. - * return true if they're identical. + * return true if they're identical. * @param goldfile Golden output file name * @param outputfile Test output file name * @return true if two files are identical. * false if two files are not identical. - * @throws IOException if an I/O error occurs reading from the file or a - * malformed or unmappable byte sequence is read + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read */ public static boolean compareWithGold(String goldfile, String outputfile) throws IOException { @@ -75,8 +79,39 @@ } /** + * Compare contents of golden file with test output file by their document + * representation. + * Here we ignore the white space and comments. return true if they're + * lexical identical. + * @param goldfile Golden output file name. + * @param resultFile Test output file name. + * @return true if two file's document representation are identical. + * false if two file's document representation are not identical. + * @throws FactoryConfigurationError in case of service configuration error. + * or if the implementation is not available or cannot be instantiated. + * @throws SAXException If any parse errors occur. + * @throws IOException if an I/O error occurs reading from the file or a + * malformed or unmappable byte sequence is read . + */ + public static boolean compareDocumentWithGold(String goldfile, String resultFile) + throws ParserConfigurationException, SAXException, IOException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + factory.setCoalescing(true); + factory.setIgnoringElementContentWhitespace(true); + factory.setIgnoringComments(true); + DocumentBuilder db = factory.newDocumentBuilder(); + + Document goldD = db.parse(Paths.get(goldfile).toFile()); + goldD.normalizeDocument(); + Document resultD = db.parse(Paths.get(resultFile).toFile()); + resultD.normalizeDocument(); + return goldD.isEqualNode(resultD); + } + + /** * Prints error message if an exception is thrown - * @param ex The exception is thrown by test. + * @param ex The exception is thrown by test. */ public static void failUnexpected(Throwable ex) { fail(ERROR_MSG_HEADER, ex); @@ -84,10 +119,10 @@ /** * Prints error message if an exception is thrown when clean up a file. - * @param ex The exception is thrown in cleaning up a file. - * @param name Cleaning up file name. + * @param ex The exception is thrown in cleaning up a file. + * @param name Cleaning up file name. */ public static void failCleanup(IOException ex, String name) { fail(String.format(ERROR_MSG_CLEANUP, name), ex); - } + } } --- /dev/null 2014-11-05 14:44:23.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/AuctionController.java 2014-11-05 14:44:23.000000000 -0800 @@ -0,0 +1,393 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_LANGUAGE; +import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_SOURCE; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.math.BigInteger; +import java.nio.file.Paths; +import java.util.GregorianCalendar; +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeConstants; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.Duration; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.DOMConfiguration; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.TypeInfo; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSSerializer; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import static test.auctionportal.HiBidConstants.PORTAL_ACCOUNT_NS; +import static test.auctionportal.HiBidConstants.XML_DIR; + +/** + * This is the user controller class for the Auction portal HiBid.com. + */ +public class AuctionController { + /** + * Check for DOMErrorHandler handling DOMError. Before fix of bug 4890927 + * DOMConfiguration.setParameter("well-formed",true) throws an exception. + */ + @Test + public void testCreateNewItem2Sell() { + String xmlFile = XML_DIR + "novelsInvalid.xml"; + + try { + Document document = DocumentBuilderFactory.newInstance() + .newDocumentBuilder().parse(xmlFile); + + document.getDomConfig().setParameter("well-formed", true); + + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + MyDOMOutput domOutput = new MyDOMOutput(); + domOutput.setByteStream(System.out); + LSSerializer writer = impl.createLSSerializer(); + writer.write(document, domOutput); + } catch (ParserConfigurationException | SAXException | IOException + | ClassNotFoundException | InstantiationException + | IllegalAccessException | ClassCastException e) { + failUnexpected(e); + } + } + + /** + * Check for DOMErrorHandler handling DOMError. Before fix of bug 4896132 + * test throws DOM Level 1 node error. + */ + @Test + public void testCreateNewItem2SellRetry() { + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + Document document = dbf.newDocumentBuilder().parse(xmlFile); + + DOMConfiguration domConfig = document.getDomConfig(); + MyDOMErrorHandler errHandler = new MyDOMErrorHandler(); + domConfig.setParameter("error-handler", errHandler); + + DOMImplementationLS impl = + (DOMImplementationLS) DOMImplementationRegistry.newInstance() + .getDOMImplementation("LS"); + LSSerializer writer = impl.createLSSerializer(); + MyDOMOutput domoutput = new MyDOMOutput(); + + domoutput.setByteStream(System.out); + writer.write(document, domoutput); + + document.normalizeDocument(); + writer.write(document, domoutput); + assertFalse(errHandler.isError()); + } catch (ParserConfigurationException | SAXException | IOException + | ClassNotFoundException | InstantiationException + | IllegalAccessException | ClassCastException e) { + failUnexpected(e); + } + } + + /** + * Check if setting the attribute to be of type ID works. This will affect + * the Attr.isID method according to the spec. + */ + @Test + public void testCreateID() { + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + + Document document = dbf.newDocumentBuilder().parse(xmlFile); + Element account = (Element)document + .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Account").item(0); + + account.setIdAttributeNS(PORTAL_ACCOUNT_NS, "accountID", true); + Attr aID = account.getAttributeNodeNS(PORTAL_ACCOUNT_NS, "accountID"); + assertTrue(aID.isId()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check the user data on the node. + */ + @Test + public void testCheckingUserData() { + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + Document document = docBuilder.parse(xmlFile); + + Element account = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Account").item(0); + assertEquals(account.getNodeName(), "acc:Account"); + Element firstName = (Element) document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "FirstName").item(0); + assertEquals(firstName.getNodeName(), "FirstName"); + + Document doc1 = docBuilder.newDocument(); + Element someName = doc1.createElement("newelem"); + + someName.setUserData("mykey", "dd", + (operation, key, data, src, dst) -> { + System.err.println("In UserDataHandler" + key); + System.out.println("In UserDataHandler"); + }); + Element impAccount = (Element)document.importNode(someName, true); + assertEquals(impAccount.getNodeName(), "newelem"); + document.normalizeDocument(); + String data = (someName.getUserData("mykey")).toString(); + assertEquals(data, "dd"); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check the UTF-16 XMLEncoding. + */ + @Test + public void testCheckingEncoding() { + String movie_utf16 + = "\n" + + "\n" + + " \n" + + " \n" + + " ઠકતિ\n" + + " Vipul Shah\n" + + " Indian\n" + + " Gujarati\n" + + " 1997-03-02-08:00\n" + + " \n" + + " \n" + + ""; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + Document document = dbf.newDocumentBuilder().parse( + new InputSource(new StringReader(movie_utf16))); + assertEquals(document.getXmlEncoding(), "UTF-16"); + assertEquals(document.getXmlStandalone(), true); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check validation API features. A schema which is including in Bug 4909119 + * used to be testing for the functionalities. + * @see userDetails.xsd + */ + @Test + public void testGetOwnerInfo() { + String schemaFile = XML_DIR + "userDetails.xsd"; + String xmlFile = XML_DIR + "userDetails.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + + SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); + Schema schema = schemaFactory.newSchema(Paths.get(schemaFile).toFile()); + + Validator validator = schema.newValidator(); + MyErrorHandler eh = new MyErrorHandler(); + validator.setErrorHandler(eh); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + docBuilder.setErrorHandler(eh); + + Document document = docBuilder.parse(new FileInputStream(xmlFile)); + DOMResult dResult = new DOMResult(); + DOMSource domSource = new DOMSource(document); + validator.validate(domSource, dResult); + assertFalse(eh.isAnyError()); + } catch (SAXException | ParserConfigurationException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check grammar caching with imported schemas. + * @see coins.xsd + * @see coinsImportMe.xsd + */ + @Test + public void testGetOwnerItemList() { + String xsdFile = XML_DIR + "coins.xsd"; + String xmlFile = XML_DIR + "coins.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + dbf.setValidating(false); + + SchemaFactory schemaFactory = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI); + Schema schema = schemaFactory.newSchema(new File(((xsdFile)))); + + MyErrorHandler eh = new MyErrorHandler(); + Validator validator = schema.newValidator(); + validator.setErrorHandler(eh); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + Document document = docBuilder.parse(new FileInputStream(xmlFile)); + validator.validate(new DOMSource(document), new DOMResult()); + assertFalse(eh.isAnyError()); + } catch (SAXException | ParserConfigurationException | IOException e) { + failUnexpected(e); + } + } + + + /** + * Check for the same imported schemas but will use SAXParserFactory and try + * parsing using the SAXParser. SCHEMA_SOURCE attribute is using for this + * test. + * @see coins.xsd + * @see coinsImportMe.xsd + */ + + @Test + public void testGetOwnerItemList1() { + String xsdFile = XML_DIR + "coins.xsd"; + String xmlFile = XML_DIR + "coins.xml"; + + try { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setValidating(true); + + SAXParser sp = spf.newSAXParser(); + sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + sp.setProperty(JAXP_SCHEMA_SOURCE, xsdFile); + + MyErrorHandler eh = new MyErrorHandler(); + sp.parse(new File(xmlFile), eh); + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check usage of javax.xml.datatype.Duration class. + */ + @Test + public void testGetItemDuration() { + String xmlFile = XML_DIR + "itemsDuration.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + Document document = dbf.newDocumentBuilder().parse(xmlFile); + + Element durationElement = (Element) document.getElementsByTagName("sellDuration").item(0); + + NodeList childList = durationElement.getChildNodes(); + + for (int i = 0; i < childList.getLength(); i++) { + System.out.println("child " + i + childList.item(i)); + } + + Duration duration = DatatypeFactory.newInstance().newDuration("P365D"); + Duration sellDuration = DatatypeFactory.newInstance().newDuration(childList.item(0).getNodeValue()); + assertFalse(sellDuration.isShorterThan(duration)); + assertFalse(sellDuration.isLongerThan(duration)); + assertEquals(sellDuration.getField(DatatypeConstants.DAYS), BigInteger.valueOf(365)); + assertEquals(sellDuration.normalizeWith(new GregorianCalendar(1999, 2, 22)), duration); + + Duration myDuration = sellDuration.add(duration); + assertEquals(myDuration.normalizeWith(new GregorianCalendar(2003, 2, 22)), + DatatypeFactory.newInstance().newDuration("P730D")); + } catch (ParserConfigurationException | DatatypeConfigurationException + | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Check usage of TypeInfo interface introduced in DOM L3. + */ + @Test + public void testGetTypeInfo() { + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + docBuilder.setErrorHandler(new MyErrorHandler()); + + Document document = docBuilder.parse(xmlFile); + Element userId = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "UserID").item(0); + TypeInfo typeInfo = userId.getSchemaTypeInfo(); + assertTrue(typeInfo.getTypeName().equals("nonNegativeInteger")); + assertTrue(typeInfo.getTypeNamespace().equals(W3C_XML_SCHEMA_NS_URI)); + + Element role = (Element)document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Role").item(0); + TypeInfo roletypeInfo = role.getSchemaTypeInfo(); + assertTrue(roletypeInfo.getTypeName().equals("BuyOrSell")); + assertTrue(roletypeInfo.getTypeNamespace().equals(PORTAL_ACCOUNT_NS)); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } +} --- /dev/null 2014-11-05 14:44:23.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/AuctionItemRepository.java 2014-11-05 14:44:23.000000000 -0800 @@ -0,0 +1,482 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import static com.sun.org.apache.xerces.internal.impl.Constants.SP_ENTITY_EXPANSION_LIMIT; +import static com.sun.org.apache.xerces.internal.impl.Constants.SP_MAX_OCCUR_LIMIT; +import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_LANGUAGE; +import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_SOURCE; +import static org.testng.Assert.assertTrue; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import static javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING; +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import static jaxp.library.JAXPTestUtilities.compareDocumentWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertFalse; + +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import static test.auctionportal.HiBidConstants.CLASS_DIR; +import static test.auctionportal.HiBidConstants.GOLDEN_DIR; +import static test.auctionportal.HiBidConstants.XML_DIR; + +/** + * This is a test class for the Auction portal HiBid.com. + */ +public class AuctionItemRepository { + /** + * XML file for parsing. + */ + private final static String ENTITY_XML = XML_DIR + "entity.xml"; + + /** + * Feature name. + */ + private final static String FEATURE_NAME = "http://xml.org/sax/features/namespace-prefixes"; + + /** + * Setting the EntityExpansion Limit to 128000 and checks if the XML + * document that has more than two levels of entity expansion is parsed or + * not. Previous system property was changed to jdk.xml.entityExpansionLimit + * see http://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html. + */ + @Test + public void testEntityExpansionSAXPos() { + try { + SAXParserFactory factory = SAXParserFactory.newInstance(); + // Secure processing will limit XML processing to conform to + // implementation limits. + factory.setFeature(FEATURE_SECURE_PROCESSING, true); + // Set entityExpansionLimit as 2 should expect fatalError + System.setProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(128000)); + SAXParser parser = factory.newSAXParser(); + + MyErrorHandler fatalHandler = new MyErrorHandler(); + parser.parse(new File(ENTITY_XML), fatalHandler); + assertFalse(fatalHandler.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + /** + * Setting the EntityExpansion Limit to 2 and checks if the XML + * document that has more than two levels of entity expansion is parsed or + * not. Previous system property was changed to jdk.xml.entityExpansionLimit + * see http://docs.oracle.com/javase/tutorial/jaxp/limits/limits.html. + */ + @Test(expectedExceptions = SAXParseException.class) + public void testEntityExpansionSAXNeg() throws SAXParseException { + // + try { + SAXParserFactory factory = SAXParserFactory.newInstance(); + // Secure processing will limit XML processing to conform to + // implementation limits. + factory.setFeature(FEATURE_SECURE_PROCESSING, true); + // Set entityExpansionLimit as 2 should expect SAXParseException + System.setProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(2)); + SAXParser parser = factory.newSAXParser(); + + MyErrorHandler fatalHandler = new MyErrorHandler(); + parser.parse(new File(ENTITY_XML), fatalHandler); + } catch (SAXParseException e) { + throw e; + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Testing set MaxOccursLimit to 10000 in the secure processing enabled for + * SAXParserFactory. + */ + @Test + public void testMaxOccurLimitPos() { + String schema_file = XML_DIR + "toys.xsd"; + String xml_file = XML_DIR + "toys.xml"; + + try (InputStream is = new FileInputStream(xml_file)) { + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setValidating(true); + factory.setFeature(FEATURE_SECURE_PROCESSING, true); + System.setProperty(SP_MAX_OCCUR_LIMIT, String.valueOf(10000)); + SAXParser parser = factory.newSAXParser(); + parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + parser.setProperty(JAXP_SCHEMA_SOURCE, new File(schema_file)); + MyErrorHandler eh = new MyErrorHandler(); + parser.parse(is, eh); + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Use a DocumentBuilder to create a DOM object and see if Secure Processing + * feature affects the entity expansion. + */ + @Test + public void testEntityExpansionDOMPos() { + try { + DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); + dfactory.setFeature(FEATURE_SECURE_PROCESSING, true); + System.setProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(10000)); + DocumentBuilder dBuilder = dfactory.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + dBuilder.setErrorHandler(eh); + dBuilder.parse(ENTITY_XML); + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | IOException | SAXException e) { + failUnexpected(e); + } + } + + /** + * Use a DocumentBuilder to create a DOM object and see how does the Secure + * Processing feature and entityExpansionLimit value affects output. + * Negative test that when entityExpansionLimit is too small. + */ + @Test(expectedExceptions = SAXParseException.class) + public void testEntityExpansionDOMNeg() throws SAXParseException { + try { + DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance(); + dfactory.setFeature(FEATURE_SECURE_PROCESSING, true); + System.setProperty(SP_ENTITY_EXPANSION_LIMIT, String.valueOf(2)); + DocumentBuilder dBuilder = dfactory.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + dBuilder.setErrorHandler(eh); + dBuilder.parse(ENTITY_XML); + } catch (SAXParseException e) { + throw e; + } catch (ParserConfigurationException | IOException | SAXException e) { + failUnexpected(e); + } + } + + /** + * Test xi:include with a SAXParserFactory. + */ + @Test + public void testXIncludeSAXPos() { + String resultFile = CLASS_DIR + "doc_xinclude.out"; + String goldFile = GOLDEN_DIR + "doc_xincludeGold.xml"; + String xmlFile = XML_DIR + "doc_xinclude.xml"; + + try { + try(FileOutputStream fos = new FileOutputStream(resultFile)) { + XInclHandler xh = new XInclHandler(fos, null); + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setXIncludeAware(true); + spf.setFeature(FEATURE_NAME, true); + spf.newSAXParser().parse(new File(xmlFile), xh); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test the simple case of including a document using xi:include using a + * DocumentBuilder. + */ + @Test + public void testXIncludeDOMPos() { + String resultFile = CLASS_DIR + "doc_xincludeDOM.out"; + String goldFile = GOLDEN_DIR + "doc_xincludeGold.xml"; + String xmlFile = XML_DIR + "doc_xinclude.xml"; + try { + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + + Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile)); + doc.setXmlStandalone(true); + + TransformerFactory.newInstance().newTransformer(). + transform(new DOMSource(doc), new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test the simple case of including a document using xi:include within a + * xi:fallback using a DocumentBuilder. + */ + @Test + public void testXIncludeFallbackDOMPos() { + String resultFile = CLASS_DIR + "doc_fallbackDOM.out"; + String goldFile = GOLDEN_DIR + "doc_fallbackGold.xml"; + String xmlFile = XML_DIR + "doc_fallback.xml"; + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + + Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile)); + doc.setXmlStandalone(true); + TransformerFactory.newInstance().newTransformer() + .transform(new DOMSource(doc), new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test for xi:fallback where the fall back text is parsed as text. This + * test uses a nested xi:include for the fallback test. + */ + @Test + public void testXIncludeFallbackTextPos() { + String resultFile = CLASS_DIR + "doc_fallback_text.out"; + String goldFile = GOLDEN_DIR + "doc_fallback_textGold.xml"; + String xmlFile = XML_DIR + "doc_fallback_text.xml"; + + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + + Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile)); + doc.setXmlStandalone(true); + TransformerFactory.newInstance().newTransformer() + .transform(new DOMSource(doc), new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test the XPointer element() framework with XInclude. + */ + @Test + public void testXpointerElementPos() { + String resultFile = CLASS_DIR + "doc_xpointer_element.out"; + String goldFile = GOLDEN_DIR + "doc_xpointerGold.xml"; + String xmlFile = XML_DIR + "doc_xpointer_element.xml"; + + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + + DocumentBuilder db = dbf.newDocumentBuilder(); + + TransformerFactory.newInstance().newTransformer() + .transform(new DOMSource(db.parse(new File(xmlFile))), + new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test the XPointer framework with a SAX object. + */ + @Test + public void testXPointerPos() { + String resultFile = CLASS_DIR + "doc_xpointer.out"; + String goldFile = GOLDEN_DIR + "doc_xpointerGold.xml"; + String xmlFile = XML_DIR + "doc_xpointer.xml"; + + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + SAXParserFactory spf = SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + spf.setXIncludeAware(true); + spf.setFeature(FEATURE_NAME, true); + // parse the file + spf.newSAXParser().parse(new File(xmlFile), new XInclHandler(fos, null)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test if xi:include may reference the doc containing the include if the + * parse type is text. + */ + @Test + public void testXIncludeLoopPos() { + String resultFile = CLASS_DIR + "doc_xinc_loops.out"; + String goldFile = GOLDEN_DIR + "doc_xinc_loopGold.xml"; + String xmlFile = XML_DIR + "doc_xinc_loops.xml"; + + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document doc = db.parse(new File(xmlFile)); + doc.normalizeDocument(); + doc.setXmlStandalone(true); + + TransformerFactory.newInstance().newTransformer() + .transform(new DOMSource(doc), new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } + + /** + * Test if two non nested xi:include elements can include the same document + * with an xi:include statement. + */ + @Test + public void testXIncludeNestedPos() { + String resultFile = CLASS_DIR + "schedule.out"; + String goldFile = GOLDEN_DIR + "scheduleGold.xml"; + String xmlFile = XML_DIR + "schedule.xml"; + + try{ + try (FileOutputStream fos = new FileOutputStream(resultFile)) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setXIncludeAware(true); + dbf.setNamespaceAware(true); + + Document doc = dbf.newDocumentBuilder().parse(new File(xmlFile)); + doc.setXmlStandalone(true); + TransformerFactory.newInstance().newTransformer() + .transform(new DOMSource(doc), new StreamResult(fos)); + } + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ParserConfigurationException | SAXException | IOException + | TransformerException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } +} --- /dev/null 2014-11-05 14:44:24.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/MyDOMErrorHandler.java 2014-11-05 14:44:24.000000000 -0800 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import org.w3c.dom.DOMErrorHandler; +import org.w3c.dom.DOMError; + +/** + * Error handler for recording DOM processing error. + */ +public class MyDOMErrorHandler implements DOMErrorHandler { + /** + * flag shows if there is any error. + */ + private volatile boolean errorOccured = false; + + /** + * Set errorOcurred to true when an error occurs. + * @param error The error object that describes the error. This object + * may be reused by the DOM implementation across multiple calls to + * the handleError method. + * @return true that processing may continue depending on. + */ + @Override + public boolean handleError (DOMError error) { + System.err.println( "ERROR" + error.getMessage()); + System.err.println( "ERROR" + error.getRelatedData()); + errorOccured = true; + return true; + } + + /** + * Showing if any error was handled. + * @return true if there is one or more error. + * false no error occurs. + */ + public boolean isError() { + return errorOccured; + } +} --- /dev/null 2014-11-05 14:44:24.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/MyDOMOutput.java 2014-11-05 14:44:24.000000000 -0800 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import org.w3c.dom.ls.LSOutput; +import java.io.OutputStream; +import java.io.Writer; + +/** + * A Thread-safe LS output destination for DOM processing. LSOutput objects + * belong to the application. The DOM implementation will never modify them + * (though it may make copies and modify the copies, if necessary). + */ +public class MyDOMOutput implements LSOutput { + /** + * An attribute of a language and binding dependent type that represents a + * writable stream of bytes. + */ + private OutputStream bytestream; + + /** + * character encoding to use for the output. + */ + private String encoding; + + /** + * The system identifier. + */ + private String sysId; + + /** + * Writable stream to which 16-bit units can be output. + */ + private Writer writer; + + /** + * An attribute of a language and binding dependent type that represents a + * writable stream of bytes. + * + * @return a writable stream. + */ + @Override + public OutputStream getByteStream() { + return bytestream; + } + + /** + * An attribute of a language and binding dependent type that represents a + * writable stream to which 16-bit units can be output. + * + * @return writable stream instance. + */ + @Override + public Writer getCharacterStream() { + return writer; + } + + /** + * The character encoding to use for the output. + * + * @return the character encoding. + */ + @Override + public String getEncoding() { + return encoding; + } + + /** + * The system identifier for this output destination. + * + * @return system identifier. + */ + @Override + public String getSystemId() { + return sysId; + } + + /** + * Set writable stream of bytes. + * + * @param bs OutputStream instance + */ + @Override + public void setByteStream(OutputStream bs) { + bytestream = bs; + } + + /** + * Set 16 bits unit writable stream. + * + * @param bs a Writer instance + */ + @Override + public void setCharacterStream(Writer cs) { + writer = cs; + } + + /** + * Set character encoding to use for the output. + * + * @param encoding encoding set to the output + */ + @Override + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + /** + * Set the system identifier for the output. + * + * @param sysId system identifier string. + */ + @Override + public void setSystemId(String sysId) { + this.sysId = sysId; + } +} --- /dev/null 2014-11-05 14:44:25.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/MyErrorHandler.java 2014-11-05 14:44:25.000000000 -0800 @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import org.xml.sax.SAXParseException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * ErrorHandler for error handling. Set state if any method in error, warning + * or fatalError was called. + */ +public final class MyErrorHandler extends DefaultHandler { + /** + * Enumeration for ErrorHandler's state. + */ + private enum STATE { ERROR, FATAL, WARNING, NORMAL}; + + /** + * Set state as normal by default. + */ + private volatile STATE state = STATE.NORMAL; + + /** + * Keep exception for further investigation. + */ + private volatile SAXParseException exception; + + /** + * Save exception and set state to ERROR. + * @param e exception wrap error. + */ + @Override + public void error (SAXParseException e) { + state = STATE.ERROR; + exception = e; + } + + /** + * Save exception and set state to FATAL. + * @param e exception wrap error. + */ + @Override + public void fatalError (SAXParseException e) { + state = STATE.FATAL; + exception = e; + } + + /** + * Save exception and set state to WARNING. + * @param e exception wrap error. + */ + @Override + public void warning (SAXParseException e) { + state = STATE.WARNING; + exception = e; + } + + /** + * return ErrorHandle's state . + * @return true No error, fatalError and warning. + * false there is any error, fatalError or warning in processing. + */ + public boolean isAnyError() { + if (state != STATE.NORMAL) + System.out.println(exception); + return state != STATE.NORMAL; + } + + /** + * return whether fatalError is the only error. + * @return true fatalError is the only error. + * false there is no error, or other error besides fatalError. + */ + public boolean isFatalError() { + if (state == STATE.FATAL) + System.out.println(exception); + return state == STATE.FATAL; + } + +} --- /dev/null 2014-11-05 14:44:25.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/UserController.java 2014-11-05 14:44:25.000000000 -0800 @@ -0,0 +1,338 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import static com.sun.org.apache.xerces.internal.jaxp.JAXPConstants.JAXP_SCHEMA_LANGUAGE; +import static org.testng.Assert.assertFalse; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import static jaxp.library.JAXPTestUtilities.compareDocumentWithGold; +import static jaxp.library.JAXPTestUtilities.failCleanup; +import static jaxp.library.JAXPTestUtilities.failUnexpected; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.testng.annotations.Test; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; +import org.w3c.dom.bootstrap.DOMImplementationRegistry; +import org.w3c.dom.ls.DOMImplementationLS; +import org.w3c.dom.ls.LSParser; +import org.w3c.dom.ls.LSSerializer; +import org.xml.sax.SAXException; +import static test.auctionportal.HiBidConstants.CLASS_DIR; +import static test.auctionportal.HiBidConstants.GOLDEN_DIR; +import static test.auctionportal.HiBidConstants.PORTAL_ACCOUNT_NS; +import static test.auctionportal.HiBidConstants.XML_DIR; + +/** + * This is the user controller class for the Auction portal HiBid.com. + */ +public class UserController { + /** + * Checking when creating an XML document using DOM Level 2 validating + * it without having a schema source or a schema location It must throw a + * sax parse exception. + */ + @Test + public void testCreateNewUser() { + String resultFile = CLASS_DIR + "accountInfoOut.xml"; + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + docBuilder.setErrorHandler(eh); + + Document document = docBuilder.newDocument(); + + Element account = document.createElementNS(PORTAL_ACCOUNT_NS, "acc:Account"); + Attr accountID = document.createAttributeNS(PORTAL_ACCOUNT_NS, "acc:accountID"); + account.setAttributeNode(accountID); + + account.appendChild(document.createElement("FirstName")); + account.appendChild(document.createElementNS(PORTAL_ACCOUNT_NS, "acc:LastName")); + account.appendChild(document.createElement("UserID")); + + DOMImplementationLS impl + = (DOMImplementationLS) DOMImplementationRegistry + .newInstance().getDOMImplementation("LS"); + LSSerializer writer = impl.createLSSerializer(); + LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); + FileOutputStream output = new FileOutputStream(resultFile); + MyDOMOutput domOutput = new MyDOMOutput(); + + domOutput.setByteStream(output); + writer.write(account, domOutput); + docBuilder.parse(resultFile); + + assertTrue(eh.isAnyError()); + } catch (ParserConfigurationException | ClassNotFoundException | + InstantiationException | IllegalAccessException + | ClassCastException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Checking conflicting namespaces and use renameNode and normalizeDocument. + * @see accountInfo.xml + */ + @Test + public void testAddUser() { + String resultFile = CLASS_DIR + "accountRole.out"; + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + // Copy schema for outputfile + Files.copy(Paths.get(XML_DIR, "accountInfo.xsd"), + Paths.get(CLASS_DIR, "accountInfo.xsd"), + StandardCopyOption.REPLACE_EXISTING); + MyErrorHandler eh = new MyErrorHandler(); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + docBuilder.setErrorHandler(eh); + + Document document = docBuilder.parse(xmlFile); + Element sell = (Element) document.getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Sell").item(0); + Element role = (Element) sell.getParentNode(); + + Element buy = (Element) document.renameNode(sell, PORTAL_ACCOUNT_NS, "acc:Buy"); + role.appendChild(buy); + + DOMImplementationLS impl + = (DOMImplementationLS) DOMImplementationRegistry + .newInstance().getDOMImplementation("LS"); + LSSerializer writer = impl.createLSSerializer(); + + + try(FileOutputStream output = new FileOutputStream(resultFile)) { + MyDOMOutput mydomoutput = new MyDOMOutput(); + mydomoutput.setByteStream(output); + writer.write(document, mydomoutput); + } + + docBuilder.parse(resultFile); + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException + | ClassNotFoundException | InstantiationException + | IllegalAccessException | ClassCastException e) { + failUnexpected(e); + } + } + + /** + * Checking Text content in XML file. + * @see accountInfo.xml + */ + @Test + public void testMoreUserInfo() { + String xmlFile = XML_DIR + "accountInfo.xml"; + + try { + System.out.println("Checking additional user info"); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + docBuilder.setErrorHandler(eh); + + Document document = docBuilder.parse(xmlFile); + Element account = (Element)document + .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "Account").item(0); + String textContent = account.getTextContent(); + assertTrue(textContent.trim().regionMatches(0, "Rachel", 0, 6)); + assertEquals(textContent, "RachelGreen744"); + + Attr accountID = account.getAttributeNodeNS(PORTAL_ACCOUNT_NS, "accountID"); + assertTrue(accountID.getTextContent().trim().equals("1")); + + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * This will check if adoptNode works will adoptNode from + * @see userInfo.xml + * @see accountInfo.xml. This is + * adopting a node from the XML file which is validated by a DTD and + * into an XML file which is validated by the schema This covers Row 5 + * for the table + * http://javaweb.sfbay/~jsuttor/JSR206/jsr-206-html/ch03s05.html. Filed + * bug 4893745 because there was a difference in behavior + */ + @Test + public void testCreateUserAccount() { + System.out.println("Creating user account"); + String userXmlFile = XML_DIR + "userInfo.xml"; + String accountXmlFile = XML_DIR + "accountInfo.xml"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + docBuilder.setErrorHandler(eh); + + Document document = docBuilder.parse(userXmlFile); + Element user = (Element) document.getElementsByTagName("FirstName").item(0); + // Set schema after parsing userInfo.xml. Otherwise it will conflict + // with DTD validation. + dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA_NS_URI); + DocumentBuilder docBuilder1 = dbf.newDocumentBuilder(); + docBuilder1.setErrorHandler(eh); + Document accDocument = docBuilder1.parse(accountXmlFile); + + Element firstName = (Element) accDocument + .getElementsByTagNameNS(PORTAL_ACCOUNT_NS, "FirstName").item(0); + Element adoptedAccount = (Element) accDocument.adoptNode(user); + + Element parent = (Element) firstName.getParentNode(); + parent.replaceChild(adoptedAccount, firstName); + + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + LSSerializer writer = impl.createLSSerializer(); + + MyDOMOutput mydomoutput = new MyDOMOutput(); + mydomoutput.setByteStream(System.out); + + writer.write(document, mydomoutput); + writer.write(accDocument, mydomoutput); + + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException + | ClassNotFoundException | InstantiationException + | IllegalAccessException | ClassCastException e) { + failUnexpected(e); + } + } + + /** + * Checking for Row 8 from the schema table when setting the schemaSource + * without the schemaLanguage must report an error. + */ + @Test(expectedExceptions = IllegalArgumentException.class) + public void testUserError() throws IllegalArgumentException { + System.out.println("Creating an error in user account"); + + String xmlFile = XML_DIR + "userInfo.xml"; + String schema = "http://java.sun.com/xml/jaxp/properties/schemaSource"; + String schemaValue = "http://dummy.com/dummy.xsd"; + + try { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setNamespaceAware(true); + dbf.setValidating(true); + dbf.setAttribute(schema, schemaValue); + + DocumentBuilder docBuilder = dbf.newDocumentBuilder(); + MyErrorHandler eh = new MyErrorHandler(); + docBuilder.setErrorHandler(eh); + Document document = docBuilder.parse(xmlFile); + assertFalse(eh.isAnyError()); + } catch (ParserConfigurationException | SAXException | IOException e) { + failUnexpected(e); + } + } + + /** + * Checking for namespace normalization. + * @see screenName.xml has prefix of + * userName is bound to "http://hibid.com/user" namespace normalization + * will create a namespace of prefix us and attach userEmail. + */ + @Test + public void testCheckScreenNameExists() { + String resultFile = CLASS_DIR + "screenName.out"; + String xmlFile = XML_DIR + "screenName.xml"; + String goldFile = GOLDEN_DIR + "screenNameGold.xml"; + + String nsTagName = "http://hibid.com/screenName"; + String userNs = "http://hibid.com/user"; + + try (FileOutputStream output = new FileOutputStream(resultFile)) { + DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); + DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); + LSSerializer writer = impl.createLSSerializer(); + LSParser builder = impl.createLSParser(DOMImplementationLS.MODE_SYNCHRONOUS, null); + Document document = builder.parseURI(xmlFile); + NodeList nl = document.getElementsByTagNameNS(nsTagName, "screen-name"); + assertEquals(nl.getLength(), 1); + Element screenName = (Element)nl.item(0); + Element userEmail = document.createElementNS(userNs, "userEmail"); + assertTrue(userEmail.isDefaultNamespace(userNs)); + + Text email = document.createTextNode("myid@hibid.com"); + userEmail.appendChild(email); + screenName.appendChild(userEmail); + document.normalizeDocument(); + + MyDOMOutput domoutput = new MyDOMOutput(); + domoutput.setByteStream(output); + writer.write(document, domoutput); + + assertTrue(compareDocumentWithGold(goldFile, resultFile)); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | ClassCastException | IOException + | ParserConfigurationException | SAXException e) { + failUnexpected(e); + } finally { + try { + Path resultPath = Paths.get(resultFile); + if (Files.exists(resultPath)) { + Files.delete(resultPath); + } + } catch (IOException ex) { + failCleanup(ex, resultFile); + } + } + } +} --- /dev/null 2014-11-05 14:44:26.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/XInclHandler.java 2014-11-05 14:44:26.000000000 -0800 @@ -0,0 +1,382 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.util.stream.Collectors; + +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; +import org.xml.sax.ext.LexicalHandler; +import org.xml.sax.helpers.DefaultHandler; + +/** + * A SAX2 event handlers. + * This SAX2 ContentHandler receives callback event then print whole document + * that is parsed. + */ +public class XInclHandler extends DefaultHandler implements LexicalHandler { + /** + * Print writer. + */ + private final PrintWriter fOut; + + /** + * Canonical output. + */ + private volatile boolean fCanonical; + + /** + * Element depth. + */ + private volatile int fElementDepth; + + /** + * Sets whether output is canonical. + */ + public void setCanonical(boolean canonical) { + fCanonical = canonical; + } + + /** + * Sets the output stream for printing. + * @param stream OutputStream for message output. + * @param encoding File encoding for message output. + */ + public XInclHandler(OutputStream stream, String encoding) + throws UnsupportedEncodingException { + // At least set one encoding. + if (encoding == null) { + encoding = "UTF8"; + } + + fOut = new PrintWriter(new OutputStreamWriter(stream, encoding), false); + } + + /** + * Receive notification of the beginning of the document. Write the start + * document tag if it's not canonical mode. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + */ + @Override + public void startDocument() throws SAXException { + fElementDepth = 0; + + if (!fCanonical) { + writeFlush(""); + } + } + + /** + * Receive notification of a processing instruction. + * @param target The processing instruction target. + * @param data The processing instruction data, or null if + * none is supplied. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + */ + @Override + public void processingInstruction (String target, String data) + throws SAXException { + if (fElementDepth > 0) { + StringBuilder instruction = new StringBuilder(" 0) { + instruction.append(' ').append(data); + } + instruction.append("?>"); + writeFlush(instruction.toString()); + } + } + + /** + * Receive notification of the start of an element then write the normalized + * output to the file. + * @param uri The Namespace URI, or the empty string if the + * element has no Namespace URI or if Namespace + * processing is not being performed. + * @param localName The local name (without prefix), or the + * empty string if Namespace processing is not being + * performed. + * @param qName The qualified name (with prefix), or the + * empty string if qualified names are not available. + * @param attributes The attributes attached to the element. If + * there are no attributes, it shall be an empty + * Attributes object. + */ + @Override + public void startElement(String uri, String local, String raw, + Attributes attrs) throws SAXException { + fElementDepth++; + StringBuilder start = new StringBuilder().append('<').append(raw); + if (attrs != null) { + for (int i = 0; i < attrs.getLength(); i++) { + start.append(' ').append(attrs.getQName(i)).append("=\""). + append(normalizeAndPrint(attrs.getValue(i))).append('"'); + } + } + start.append('>'); + writeFlush(start.toString()); + } + + /** + * Receive notification of character data inside an element and write + * normalized characters to file. + * @param ch The characters. + * @param start The start position in the character array. + * @param length The number of characters to use from the + * character array. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + */ + @Override + public void characters(char ch[], int start, int length) + throws SAXException { + writeFlush(normalizeAndPrint(ch, start, length)); + } + + /** + * Receiving notification of ignorable whitespace in element content and + * writing normalized ignorable characters to file. + * @param ch The characters. + * @param start The start position in the character array. + * @param length The number of characters to use from the + * character array. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + */ + @Override + public void ignorableWhitespace(char ch[], int start, int length) + throws SAXException { + characters(ch, start, length); + } + + /** + * Receive notification of the end of an element and print end element. + * + * @param uri The Namespace URI, or the empty string if the + * element has no Namespace URI or if Namespace + * processing is not being performed. + * @param localName The local name (without prefix), or the + * empty string if Namespace processing is not being + * performed. + * @param qName The qualified name (with prefix), or the + * empty string if qualified names are not available. + */ + @Override + public void endElement(String uri, String local, String raw) + throws SAXException { + fElementDepth--; + writeFlush(""); + } + + /** + * Receive notification of a parser warning and print it out. + * @param e The warning information encoded as an exception. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + */ + @Override + public void warning(SAXParseException ex) throws SAXException { + printError("Warning", ex); + } + + /** + * Receive notification of a parser error and print it out. + * @param e The error information encoded as an exception. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + + */ + @Override + public void error(SAXParseException ex) throws SAXException { + printError("Error", ex); + } + + /** + * Receive notification of a parser fatal error. Throw out fatal error + * following print fatal error message. + * @param e The fatal error information encoded as an exception. + * @exception org.xml.sax.SAXException Any SAX exception, possibly + * wrapping another exception. + + */ + @Override + public void fatalError(SAXParseException ex) throws SAXException { + printError("Fatal Error", ex); + throw ex; + } + + /** + * Do nothing on start DTD. + * @param name The document type name. + * @param publicId The declared public identifier for the + * external DTD subset, or null if none was declared. + * @param systemId The declared system identifier for the + * external DTD subset, or null if none was declared. + * (Note that this is not resolved against the document + * base URI.) + * @exception SAXException The application may raise an + * exception. + */ + @Override + public void startDTD(String name, String publicId, String systemId) + throws SAXException { + } + + /** + * Do nothing on end DTD. + * @exception SAXException The application may raise an exception. + */ + @Override + public void endDTD() throws SAXException { + } + + /** + * Do nothing on start entity. + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%', and if it is the + * external DTD subset, it will be "[dtd]". + * @exception SAXException The application may raise an exception. + */ + @Override + public void startEntity(String name) throws SAXException { + } + + /** + * Do nothing on end entity. + * @param name The name of the entity. If it is a parameter + * entity, the name will begin with '%', and if it is the + * external DTD subset, it will be "[dtd]". + * @exception SAXException The application may raise an exception. + */ + @Override + public void endEntity(String name) throws SAXException { + } + + /** + * Do nothing on start CDATA section. + * @exception SAXException The application may raise an exception. + */ + @Override + public void startCDATA() throws SAXException { + } + + /** + * Do nothing on end CDATA section. + * @exception SAXException The application may raise an exception. + */ + @Override + public void endCDATA() throws SAXException { + } + + /** + * Report an normalized XML comment when receive a comment in the document. + * + * @param ch An array holding the characters in the comment. + * @param start The starting position in the array. + * @param length The number of characters to use from the array. + * @exception SAXException The application may raise an exception. + */ + @Override + public void comment(char ch[], int start, int length) throws SAXException { + if (!fCanonical && fElementDepth > 0) { + writeFlush(""); + } + } + + /** + * Normalizes and prints the given string. + * @param s String to be normalized + */ + private String normalizeAndPrint(String s) { + return s.chars().mapToObj(c -> normalizeAndPrint((char)c)). + collect(Collectors.joining()); + } + + /** + * Normalizes and prints the given array of characters. + * @param ch The characters to be normalized. + * @param start The start position in the character array. + * @param length The number of characters to use from the + * character array. + */ + private String normalizeAndPrint(char[] ch, int offset, int length) { + return normalizeAndPrint(new String(ch, offset, length)); + } + + /** + * Normalizes given character. + * @param c char to be normalized. + */ + private String normalizeAndPrint(char c) { + switch (c) { + case '<': + return "<"; + case '>': + return ">"; + case '&': + return "&"; + case '"': + return """; + case '\r': + case '\n': + return fCanonical ? "&#" + Integer.toString(c) + ";" : String.valueOf(c); + default: + return String.valueOf(c); + } + } + + /** + * Prints the error message. + * @param type error type + * @param ex exception that need to be printed + */ + private void printError(String type, SAXParseException ex) { + System.err.print("[" + type + "] "); + String systemId = ex.getSystemId(); + if (systemId != null) { + int index = systemId.lastIndexOf('/'); + if (index != -1) + systemId = systemId.substring(index + 1); + System.err.print(systemId); + } + System.err.print(':' + ex.getLineNumber()); + System.err.print(':' + ex.getColumnNumber()); + System.err.println(": " + ex.getMessage()); + System.err.flush(); + } + + /** + * Write out and flush. + * @param out string to be written. + */ + private void writeFlush(String out) { + fOut.print(out); + fOut.flush(); + } +} --- /dev/null 2014-11-05 14:44:26.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/accountInfo.xml 2014-11-05 14:44:26.000000000 -0800 @@ -0,0 +1,11 @@ + + + + Rachel + Green + 744 + + --- /dev/null 2014-11-05 14:44:27.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/accountInfo.xsd 2014-11-05 14:44:27.000000000 -0800 @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:27.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/activity.xml 2014-11-05 14:44:27.000000000 -0800 @@ -0,0 +1,6 @@ + + + Code + Some description + + --- /dev/null 2014-11-05 14:44:28.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/bookInfo.dtd 2014-11-05 14:44:27.000000000 -0800 @@ -0,0 +1,13 @@ + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:28.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/bookInfo.xml 2014-11-05 14:44:28.000000000 -0800 @@ -0,0 +1,25 @@ + + + + Publishers of the Music of New York Women Composers + + The Publishers + + + Alfred Publishing + &ws; + 15535 Morrison + South Oaks CA 91403 + + + + eXtensible Markup Language + + + + + + Publishers are not noted in report by time. + + --- /dev/null 2014-11-05 14:44:29.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/coins.xml 2014-11-05 14:44:28.000000000 -0800 @@ -0,0 +1,16 @@ + + + + 1950 gold coin + + + + 1950-04-04T00:00:00 + 1960 + + + --- /dev/null 2014-11-05 14:44:29.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/coins.xsd 2014-11-05 14:44:29.000000000 -0800 @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:29.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/coinsImportMe.xsd 2014-11-05 14:44:29.000000000 -0800 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:30.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/data.xml 2014-11-05 14:44:30.000000000 -0800 @@ -0,0 +1,18 @@ + + + + timepass + M + 10 + Fair +
36-28-36
+
+ + COOOOL + F + 20 + Dark +
26-32-26
+
+
+ --- /dev/null 2014-11-05 14:44:30.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_fallback.xml 2014-11-05 14:44:30.000000000 -0800 @@ -0,0 +1,11 @@ + + +

The following is the source of the "task.xml" resource:

+ + + + + + + +
--- /dev/null 2014-11-05 14:44:31.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_fallback_text.xml 2014-11-05 14:44:31.000000000 -0800 @@ -0,0 +1,11 @@ + + +

The following is the source of the "tasks.xml" resource:

+ + + + + + + +
\ No newline at end of file --- /dev/null 2014-11-05 14:44:31.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_xinc_loops.xml 2014-11-05 14:44:31.000000000 -0800 @@ -0,0 +1,13 @@ + + +

The following is the outer XML file

+ + + + + + + + +
+ --- /dev/null 2014-11-05 14:44:32.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_xinclude.xml 2014-11-05 14:44:31.000000000 -0800 @@ -0,0 +1,6 @@ + + +

The following is the source of the "data.xml" resource:

+ +
+ --- /dev/null 2014-11-05 14:44:32.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_xincludeGold.xml 2014-11-05 14:44:32.000000000 -0800 @@ -0,0 +1,18 @@ + +

The following is the source of the "data.xml" resource:

+ + + John doe + 10/02/2003 + 11/02/2003 + This is task 1 + + + Jane Doe + 10/02/2003 + 11/02/2003 + This is task 2 + + +
+ --- /dev/null 2014-11-05 14:44:32.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_xpointer.xml 2014-11-05 14:44:32.000000000 -0800 @@ -0,0 +1,6 @@ + + +

The following is the source of the "tasks.xml" resource:

+ +
+ --- /dev/null 2014-11-05 14:44:33.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/doc_xpointer_element.xml 2014-11-05 14:44:33.000000000 -0800 @@ -0,0 +1,5 @@ + + +

The following is the source of the "tasks.xml" resource:

+ +
--- /dev/null 2014-11-05 14:44:33.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/document_xinclude.xml 2014-11-05 14:44:33.000000000 -0800 @@ -0,0 +1,6 @@ + + +

The following is the source of the "data.xml" resource:

+ +
+ --- /dev/null 2014-11-05 14:44:34.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/entity.xml 2014-11-05 14:44:34.000000000 -0800 @@ -0,0 +1,32 @@ + + + + + + + + + +]> + + + + Test Id + Test Name + My Desc + &fifthEntity; + + + --- /dev/null 2014-11-05 14:44:34.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/fallback.xml 2014-11-05 14:44:34.000000000 -0800 @@ -0,0 +1,4 @@ + + + This is the fallback text + --- /dev/null 2014-11-05 14:44:35.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/fallback_text.xml 2014-11-05 14:44:35.000000000 -0800 @@ -0,0 +1 @@ +This is the fallback text as a text --- /dev/null 2014-11-05 14:44:35.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/inclusion.xml 2014-11-05 14:44:35.000000000 -0800 @@ -0,0 +1,5 @@ + + + + + --- /dev/null 2014-11-05 14:44:36.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/itemsDuration.xml 2014-11-05 14:44:35.000000000 -0800 @@ -0,0 +1,14 @@ + + + + 20th century vase. Really unique . Really antique + 2 + 2002-03-11T15:23:45 + 2002-03-11 + 15:23:45 + P365D + a2 + + + + --- /dev/null 2014-11-05 14:44:36.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/novels.xsd 2014-11-05 14:44:36.000000000 -0800 @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:36.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/novelsInvalid.xml 2014-11-05 14:44:36.000000000 -0800 @@ -0,0 +1,9 @@ + + + Mystery of Whispering Mummy + http://www.links.com + + Mystery of Vanishing Treasure + http://www.alfrdhitchcock.com + + --- /dev/null 2014-11-05 14:44:37.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/schedule.xml 2014-11-05 14:44:37.000000000 -0800 @@ -0,0 +1,9 @@ + + + + + + + + + --- /dev/null 2014-11-05 14:44:37.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/screenName.xml 2014-11-05 14:44:37.000000000 -0800 @@ -0,0 +1,10 @@ + + + + + xmlns="http://hibid.com/screenName"> + + tom + 10 + + --- /dev/null 2014-11-05 14:44:38.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/tasks.xml 2014-11-05 14:44:38.000000000 -0800 @@ -0,0 +1,16 @@ + + + + John doe + 10/02/2003 + 11/02/2003 + This is task 1 + + + Jane Doe + 10/02/2003 + 11/02/2003 + This is task 2 + + + --- /dev/null 2014-11-05 14:44:38.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/toys.xml 2014-11-05 14:44:38.000000000 -0800 @@ -0,0 +1,40 @@ + + + + + + + Lego-Model01 + 65.99 + + + Lego-Model2 + 69.99 + + + Lego-Model3 + 14.99 + + + Barbie-Pink + 12.99 + + + Barbie-Blue + 13.99 + + + Barbie-White + 13.99 + + + Barbie-Plain + 13.99 + + + --- /dev/null 2014-11-05 14:44:39.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/toys.xsd 2014-11-05 14:44:39.000000000 -0800 @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:39.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/userAddress.xsd 2014-11-05 14:44:39.000000000 -0800 @@ -0,0 +1,16 @@ + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:40.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/userDetails.xml 2014-11-05 14:44:40.000000000 -0800 @@ -0,0 +1,13 @@ + + + Bob + + + 555 Beverly Hills Rd + + + + + --- /dev/null 2014-11-05 14:44:40.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/userDetails.xsd 2014-11-05 14:44:40.000000000 -0800 @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --- /dev/null 2014-11-05 14:44:41.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/userInfo.dtd 2014-11-05 14:44:41.000000000 -0800 @@ -0,0 +1,6 @@ + + + + + + --- /dev/null 2014-11-05 14:44:41.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/auctionportal/userInfo.xml 2014-11-05 14:44:41.000000000 -0800 @@ -0,0 +1,12 @@ + + + + + King + + Kong + + 007 + + + --- /dev/null 2014-11-05 14:44:42.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/doc_fallbackGold.xml 2014-11-05 14:44:41.000000000 -0800 @@ -0,0 +1,9 @@ + +

The following is the source of the "task.xml" resource:

+ + + This is the fallback text + + +
+ --- /dev/null 2014-11-05 14:44:42.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/doc_fallback_textGold.xml 2014-11-05 14:44:42.000000000 -0800 @@ -0,0 +1,10 @@ + + +

The following is the source of the "tasks.xml" resource:

+ + + This is the fallback text as a text + + + +
--- /dev/null 2014-11-05 14:44:42.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/doc_xinc_loopGold.xml 2014-11-05 14:44:42.000000000 -0800 @@ -0,0 +1,24 @@ + + +

The following is the outer XML file

+ + + + <?xml version="1.0" encoding="UTF-8"?> +<root xmlns:xi="http://www.w3.org/2001/XInclude"> + <p>The following is the outer XML file</p> + <example> + + <xi:include href="task.xml" parse="xml"> + <xi:fallback> + <xi:include href="doc_xinc_loops.xml" parse="text" /> + </xi:fallback> + </xi:include> + </example> +</root> + + + + +
+ --- /dev/null 2014-11-05 14:44:43.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/doc_xincludeGold.xml 2014-11-05 14:44:43.000000000 -0800 @@ -0,0 +1,18 @@ + +

The following is the source of the "data.xml" resource:

+ + + John doe + 10/02/2003 + 11/02/2003 + This is task 1 + + + Jane Doe + 10/02/2003 + 11/02/2003 + This is task 2 + + +
+ --- /dev/null 2014-11-05 14:44:43.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/doc_xpointerGold.xml 2014-11-05 14:44:43.000000000 -0800 @@ -0,0 +1,4 @@ + +

The following is the source of the "tasks.xml" resource:

+ Jane Doe +
--- /dev/null 2014-11-05 14:44:44.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/scheduleGold.xml 2014-11-05 14:44:44.000000000 -0800 @@ -0,0 +1,19 @@ + + + + + Code + Some description + + + + + + + Code + Some description + + + + + --- /dev/null 2014-11-05 14:44:44.000000000 -0800 +++ new/test/javax/xml/jaxp/functional/test/golden/screenNameGold.xml 2014-11-05 14:44:44.000000000 -0800 @@ -0,0 +1,8 @@ + + + xmlns="http://hibid.com/screenName"> + + tom + 10 + myid@hibid.com + --- /dev/null 2014-11-05 14:44:45.000000000 -0800 +++ new/test/javax/xml/jaxp/libs/test/auctionportal/HiBidConstants.java 2014-11-05 14:44:45.000000000 -0800 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package test.auctionportal; + +import static jaxp.library.JAXPTestUtilities.FILE_SEP; +import static jaxp.library.JAXPTestUtilities.USER_DIR; + +/** + * This is the Base test class provide basic support for Auction portal test. + */ +public class HiBidConstants { + /** + * Current test directory. + */ + public static final String CLASS_DIR + = System.getProperty("test.classes", ".") + FILE_SEP; + + /** + * Package name that separates by slash. + */ + public static final String PACKAGE_NAME = FILE_SEP + + HiBidConstants.class.getPackage().getName().replaceAll("[.]", FILE_SEP); + + /** + * Test base directory. Every package has its own test package directory. + */ + public static final String BASE_DIR = System.getProperty("test.src", USER_DIR) + .replaceAll("\\" + System.getProperty("file.separator"), "/") + + PACKAGE_NAME + FILE_SEP + ".."; + + /** + * Source XML file directory. Auction portal's test files are co-located + * with Java file. + */ + public static final String XML_DIR = System.getProperty("test.src", USER_DIR) + .replaceAll("\\" + System.getProperty("file.separator"), "/") + + PACKAGE_NAME + FILE_SEP; + + /** + * Golden output file directory. + * We pre-define all expected output in golden output file. Test verifies + * whether the standard output is same as content of golden file. + */ + public static final String GOLDEN_DIR = BASE_DIR + FILE_SEP + "golden" + FILE_SEP; + + /** + * Name space for account operation. + */ + public static final String PORTAL_ACCOUNT_NS = "http://www.auctionportal.org/Accounts"; +}