javax.xml.stream.FactoryConfigurationError Java Examples
The following examples show how to use
javax.xml.stream.FactoryConfigurationError.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HtmlDocumentationWriter.java From nifi with Apache License 2.0 | 6 votes |
@Override public void write(final ConfigurableComponent configurableComponent, final OutputStream streamToWriteTo, final boolean includesAdditionalDocumentation) throws IOException { try { XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( streamToWriteTo, "UTF-8"); xmlStreamWriter.writeDTD("<!DOCTYPE html>"); xmlStreamWriter.writeStartElement("html"); xmlStreamWriter.writeAttribute("lang", "en"); writeHead(configurableComponent, xmlStreamWriter); writeBody(configurableComponent, xmlStreamWriter, includesAdditionalDocumentation); xmlStreamWriter.writeEndElement(); xmlStreamWriter.close(); } catch (XMLStreamException | FactoryConfigurationError e) { throw new IOException("Unable to create XMLOutputStream", e); } }
Example #2
Source File: VespaRecordWriter.java From vespa with Apache License 2.0 | 6 votes |
private String findDocIdFromXml(String xml) { try { XMLEventReader eventReader = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(xml)); while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); if (event.getEventType() == XMLEvent.START_ELEMENT) { StartElement element = event.asStartElement(); String elementName = element.getName().getLocalPart(); if (VespaDocumentOperation.Operation.valid(elementName)) { return element.getAttributeByName(QName.valueOf("documentid")).getValue(); } } } } catch (XMLStreamException | FactoryConfigurationError e) { // as json dude does return null; } return null; }
Example #3
Source File: TestNgReportBuilderCli.java From bootstraped-multi-test-results-report with MIT License | 6 votes |
public static void main(String[] args) throws FactoryConfigurationError, JAXBException, XMLStreamException, IOException { List<String> xmlReports = new ArrayList<String>(); String[] extensions = {"xml"}; String xmlPath = System.getProperty("xmlPath"); String outputPath = System.getProperty("reportsOutputPath"); if (xmlPath == null || outputPath == null) { throw new Error("xmlPath or reportsOutputPath variables have not been set"); } Object[] files = FileUtils.listFiles(new File(xmlPath), extensions, false).toArray(); System.out.println("Found " + files.length + " xml files"); for (Object absFilePath : files) { System.out.println("Found an xml: " + absFilePath); xmlReports.add(((File) absFilePath).getAbsolutePath()); } TestNgReportBuilder repo = new TestNgReportBuilder(xmlReports, outputPath); repo.writeReportsOnDisk(); }
Example #4
Source File: TestNgReportBuilder.java From bootstraped-multi-test-results-report with MIT License | 6 votes |
public TestNgReportBuilder(List<String> xmlReports, String targetBuildPath) throws JAXBException, XMLStreamException, FactoryConfigurationError, IOException { testOverviewPath = targetBuildPath + "/"; classesSummaryPath = targetBuildPath + "/classes-summary/"; processedTestNgReports = new ArrayList<>(); JAXBContext cntx = JAXBContext.newInstance(TestngResultsModel.class); Unmarshaller unm = cntx.createUnmarshaller(); for (String xml : xmlReports) { InputStream inputStream = new FileInputStream(xml); XMLStreamReader xmlStream = XMLInputFactory.newInstance().createXMLStreamReader(inputStream); TestngResultsModel ts = (TestngResultsModel) unm.unmarshal(xmlStream); ts.postProcess(); processedTestNgReports.add(ts); inputStream.close(); xmlStream.close(); } }
Example #5
Source File: XmlTransformer.java From recheck with GNU Affero General Public License v3.0 | 6 votes |
private void convertAndWriteToFile( final InputStream inputStream, final File tmpFile ) throws IOException { try ( final LZ4BlockOutputStream out = new LZ4BlockOutputStream( new FileOutputStream( tmpFile ) ) ) { reset(); final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty( XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, Boolean.FALSE ); final XMLEventReader eventReader = inputFactory.createXMLEventReader( inputStream, StandardCharsets.UTF_8.name() ); final XMLEventWriter eventWriter = XMLOutputFactory.newInstance().createXMLEventWriter( out, StandardCharsets.UTF_8.name() ); while ( eventReader.hasNext() ) { final XMLEvent nextEvent = eventReader.nextEvent(); convert( nextEvent, eventWriter ); } eventReader.close(); eventWriter.flush(); eventWriter.close(); } catch ( final XMLStreamException | FactoryConfigurationError e ) { throw new RuntimeException( e ); } }
Example #6
Source File: StaEDISchemaTest.java From staedi with Apache License 2.0 | 6 votes |
@Test void testLoadV4_TestSimpleTypes() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); InputStream schemaStream = getClass().getResourceAsStream("/x12/IG-999-standard-included.xml"); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); reader.nextTag(); // Pass by <schema> element Map<String, EDIType> types = new SchemaReaderV4(reader, Collections.emptyMap()).readTypes(); schema.setTypes(types); assertEquals(EDIType.Type.TRANSACTION, schema.getType(StaEDISchema.TRANSACTION_ID).getType()); EDIType ak101 = schema.getType("DE0479"); assertEquals(EDIType.Type.ELEMENT, ak101.getType()); assertEquals(ak101, schema.getType("DE0479")); EDIType ak901 = schema.getType("DE0715"); assertEquals(EDIType.Type.ELEMENT, ak901.getType()); assertNotEquals(ak101, ak901); EDIType ak9 = schema.getType("AK9"); assertEquals(EDIType.Type.SEGMENT, ak9.getType()); assertNotEquals(ak101, ak9); }
Example #7
Source File: HtmlExtensionDocWriter.java From nifi-registry with Apache License 2.0 | 6 votes |
@Override public void write(final ExtensionMetadata extensionMetadata, final Extension extension, final OutputStream outputStream) throws IOException { try { final XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, "UTF-8"); xmlStreamWriter.writeDTD("<!DOCTYPE html>"); xmlStreamWriter.writeStartElement("html"); xmlStreamWriter.writeAttribute("lang", "en"); writeHead(extensionMetadata, xmlStreamWriter); writeBody(extensionMetadata, extension, xmlStreamWriter); xmlStreamWriter.writeEndElement(); xmlStreamWriter.close(); outputStream.flush(); } catch (XMLStreamException | FactoryConfigurationError e) { throw new IOException("Unable to create XMLOutputStream", e); } }
Example #8
Source File: XmlDataSetProducer.java From morf with Apache License 2.0 | 6 votes |
/** * @param inputStream The inputstream to read from * @return A new pull parser */ private static XMLStreamReader openPullParser(InputStream inputStream) { try { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, Charsets.UTF_8)); Reader reader; int version = Version2to4TransformingReader.readVersion(bufferedReader); if (version == 2 || version == 3) { reader = new Version2to4TransformingReader(bufferedReader, version); } else { reader = bufferedReader; } if (version > 4) { throw new IllegalStateException("Unknown XML dataset format: "+version +" This dataset has been produced by a later version of Morf"); } return FACTORY.createXMLStreamReader(reader); } catch (XMLStreamException|FactoryConfigurationError e) { throw new RuntimeException(e); } }
Example #9
Source File: JkImlGenerator.java From jeka with Apache License 2.0 | 6 votes |
private String _generate() throws IOException, XMLStreamException, FactoryConfigurationError { final ByteArrayOutputStream fos = new ByteArrayOutputStream(); writer = createWriter(fos); writeHead(); writeOutput(); writeJdk(); writeContent(); writeOrderEntrySourceFolder(); final Set<Path> allPaths = new HashSet<>(); final Set<Path> allModules = new HashSet<>(); if (this.ideSupport.getDependencyResolver()!= null) { writeDependencies(ideSupport.getDependencies(), ideSupport.getDependencyResolver(), allPaths, allModules, false); } if (this.defDependencyResolver != null) { writeDependencies(this.defDependencies, this.defDependencyResolver, allPaths, allModules, true); } writeIntellijModuleImportDependencies(this.importedTestModules, "TEST"); writeFoot(); writer.close(); return fos.toString(ENCODING); }
Example #10
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test serialization of empty syndication title property. EmployeeName is set to NULL after the update (which is * allowed because EmployeeName has default Nullable behavior which is true). * Write of an empty atom title tag is allowed within RFC4287 (http://tools.ietf.org/html/rfc4287#section-4.2.14). */ @Test public void serializeEmployeeWithNullSyndicationTitleProperty() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); employeeData.put("EmployeeName", null); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, properties); String xmlString = verifyResponse(response); assertXpathExists("/a:entry/a:title", xmlString); assertXpathEvaluatesTo("", "/a:entry/a:title", xmlString); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo("Employees('1')/$value", "/a:entry/a:content/@src", xmlString); assertXpathExists("/a:entry/m:properties", xmlString); }
Example #11
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeEmployeeAndCheckOrderOfPropertyTags() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); EdmEntitySet employeeEntitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); ODataResponse response = ser.writeEntry(employeeEntitySet, employeeData, properties); String xmlString = verifyResponse(response); // log.debug(xmlString); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/a:content", xmlString); // verify properties assertXpathExists("/a:entry/m:properties", xmlString); assertXpathEvaluatesTo("9", "count(/a:entry/m:properties/*)", xmlString); // verify order of tags List<String> expectedPropertyNamesFromEdm = employeeEntitySet.getEntityType().getPropertyNames(); verifyTagOrdering(xmlString, expectedPropertyNamesFromEdm.toArray(new String[0])); }
Example #12
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomEntry() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData, properties); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); assertXpathExists("/a:entry/a:content/m:properties", xmlString); }
Example #13
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void serializeEmployeeAndCheckOrderOfPropertyTags() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).mediaResourceMimeType("abc").build(); EdmEntitySet employeeEntitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); ODataResponse response = ser.writeEntry(employeeEntitySet, employeeData, properties); String xmlString = verifyResponse(response); // log.debug(xmlString); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/a:content", xmlString); // verify properties assertXpathExists("/a:entry/m:properties", xmlString); assertXpathEvaluatesTo("9", "count(/a:entry/m:properties/*)", xmlString); // verify order of tags List<String> expectedPropertyNamesFromEdm = employeeEntitySet.getEntityType().getPropertyNames(); verifyTagOrdering(xmlString, expectedPropertyNamesFromEdm.toArray(new String[0])); }
Example #14
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomMediaResourceLinks() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, DEFAULT_PROPERTIES); String xmlString = verifyResponse(response); String rel = Edm.NAMESPACE_REL_2007_08 + "ne_Manager"; assertXpathExists("/a:entry/a:link[@href=\"Employees('1')/ne_Manager\"]", xmlString); assertXpathExists("/a:entry/a:link[@rel='" + rel + "']", xmlString); assertXpathExists("/a:entry/a:link[@type='application/atom+xml;type=entry']", xmlString); assertXpathExists("/a:entry/a:link[@title='ne_Manager']", xmlString); }
Example #15
Source File: HtmlDocumentationWriter.java From localization_nifi with Apache License 2.0 | 6 votes |
@Override public void write(final ConfigurableComponent configurableComponent, final OutputStream streamToWriteTo, final boolean includesAdditionalDocumentation) throws IOException { try { XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( streamToWriteTo, "UTF-8"); xmlStreamWriter.writeDTD("<!DOCTYPE html>"); xmlStreamWriter.writeStartElement("html"); xmlStreamWriter.writeAttribute("lang", "en"); writeHead(configurableComponent, xmlStreamWriter); writeBody(configurableComponent, xmlStreamWriter, includesAdditionalDocumentation); xmlStreamWriter.writeEndElement(); xmlStreamWriter.close(); } catch (XMLStreamException | FactoryConfigurationError e) { throw new IOException("Unable to create XMLOutputStream", e); } }
Example #16
Source File: BootstrapperExample.java From java-client-api with Apache License 2.0 | 6 votes |
public void makeSampleServer() throws ClientProtocolException, IOException, XMLStreamException, FactoryConfigurationError { new Bootstrapper().makeServer( new ConfigServer( "localhost", 8002, "admin", "admin", Authentication.DIGEST ), new RESTServer( "Documents", "Modules", "Default", "DocuREST", 8014 ) ); System.out.println( "Created DocuREST server on 8014 port for Documents database" ); }
Example #17
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomMediaResourceLinks() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); employeeData.setWriteProperties(EntitySerializerProperties.serviceRoot( BASE_URI).build()); HashMap<String,Object> id = new HashMap<String, Object>(); id.put("EmployeeId", "1"); employeeData.addNavigation("ne_Manager", id ); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData); String xmlString = verifyResponse(response); String rel = Edm.NAMESPACE_REL_2007_08 + "ne_Manager"; assertXpathExists("/a:entry/a:link[@href=\"Managers('1')\"]", xmlString); assertXpathExists("/a:entry/a:link[@rel='" + rel + "']", xmlString); assertXpathExists("/a:entry/a:link[@type='application/atom+xml;type=entry']", xmlString); }
Example #18
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeCustomMapping() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); photoData.setWriteProperties(DEFAULT_PROPERTIES); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/custom:CustomProperty", xmlString); //assertXpathExists("/a:entry/ру:Содержание", xmlString); //TODO //assertXpathEvaluatesTo((String) photoData.getProperty("Содержание"), //"/a:entry/ру:Содержание/text()", xmlString); verifyTagOrdering(xmlString, "category", "Содержание", "content", "properties"); }
Example #19
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeWithValueEncoding() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { photoData.addProperty("Type", "< Ö >"); photoData.setWriteProperties(DEFAULT_PROPERTIES); AtomSerializerDeserializer ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:id", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString() + "Container2.Photos(Id=1,Type='%3C%20%C3%96%20%3E')", "/a:entry/a:id/text()", xmlString); assertXpathEvaluatesTo("Container2.Photos(Id=1,Type='%3C%20%C3%96%20%3E')", "/a:entry/a:link/@href", xmlString); }
Example #20
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomEntry() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntitySerializerProperties properties = EntitySerializerProperties.serviceRoot(BASE_URI).build(); AtomSerializerDeserializer ser = createAtomEntityProvider(); roomData.setWriteProperties(properties); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), roomData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); assertXpathExists("/a:entry/a:content/m:properties", xmlString); }
Example #21
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeAtomEntryWithEmptyEntity() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { final EntitySerializerProperties properties = EntitySerializerProperties.serviceRoot(BASE_URI).includeMetadata(false).build(); AtomSerializerDeserializer ser = createAtomEntityProvider(); Entity entity = new Entity(); entity.setWriteProperties(properties); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"), entity); String xmlString = verifyResponse(response); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo(ContentType.APPLICATION_XML.toString(), "/a:entry/a:content/@type", xmlString); }
Example #22
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeEmployeeAndCheckOrderOfPropertyTags() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); EntitySerializerProperties properties = EntitySerializerProperties.serviceRoot(BASE_URI).includeMetadata(true).build(); employeeData.setWriteProperties(properties); EdmEntitySet employeeEntitySet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); ODataResponse response = ser.writeEntry(employeeEntitySet, employeeData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/a:content", xmlString); // verify properties assertXpathExists("/a:entry/m:properties", xmlString); assertXpathEvaluatesTo("8", "count(/a:entry/m:properties/*)", xmlString); // verify order of tags List<String> expectedPropertyNamesFromEdm = new ArrayList<String>(employeeEntitySet.getEntityType() .getPropertyNames()); expectedPropertyNamesFromEdm.remove(String.valueOf("ImageUrl")); verifyTagOrdering(xmlString, expectedPropertyNamesFromEdm.toArray(new String[0])); }
Example #23
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
/** * Test serialization of empty syndication title property. EmployeeName is set to NULL after the update (which is allowed because EmployeeName has default Nullable behavior which is true). * Write of an empty atom title tag is allowed within RFC4287 (http://tools.ietf.org/html/rfc4287#section-4.2.14). */ @Test public void serializeEmployeeWithNullSyndicationTitleProperty() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomEntityProvider ser = createAtomEntityProvider(); EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(BASE_URI).build(); employeeData.put("EmployeeName", null); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData, properties); String xmlString = verifyResponse(response); assertXpathExists("/a:entry/a:title", xmlString); assertXpathEvaluatesTo("", "/a:entry/a:title", xmlString); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:content", xmlString); assertXpathEvaluatesTo("Employees('1')/$value", "/a:entry/a:content/@src", xmlString); assertXpathExists("/a:entry/m:properties", xmlString); }
Example #24
Source File: AtomEntryProducerTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void serializeETagEncoding() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { Edm edm = MockFacade.getMockEdm(); EdmTyped roomIdProperty = edm.getEntityType("RefScenario", "Room").getProperty("Id"); EdmFacets facets = mock(EdmFacets.class); when(facets.getConcurrencyMode()).thenReturn(EdmConcurrencyMode.Fixed); when(facets.getMaxLength()).thenReturn(3); when(((EdmProperty) roomIdProperty).getFacets()).thenReturn(facets); roomData.put("Id", "<\">"); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(edm.getDefaultEntityContainer().getEntitySet("Rooms"), roomData, DEFAULT_PROPERTIES); assertNotNull(response); assertNotNull(response.getEntity()); assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader()); assertEquals("W/\"<\">.3\"", response.getETag()); String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/@m:etag", xmlString); assertXpathEvaluatesTo("W/\"<\">.3\"", "/a:entry/@m:etag", xmlString); }
Example #25
Source File: AtomEntryProducerTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void serializeETagEncoding() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { Edm edm = MockFacade.getMockEdm(); EdmTyped roomIdProperty = edm.getEntityType("RefScenario", "Room").getProperty("Id"); EdmFacets facets = mock(EdmFacets.class); when(facets.getConcurrencyMode()).thenReturn(EdmConcurrencyMode.Fixed); when(facets.getMaxLength()).thenReturn(3); when(((EdmProperty) roomIdProperty).getFacets()).thenReturn(facets); roomData.put("Id", "<\">"); AtomEntityProvider ser = createAtomEntityProvider(); ODataResponse response = ser.writeEntry(edm.getDefaultEntityContainer().getEntitySet("Rooms"), roomData, DEFAULT_PROPERTIES); assertNotNull(response); assertNotNull(response.getEntity()); assertNull("EntityProvider should not set content header", response.getContentHeader()); assertEquals("W/\"<\">.3\"", response.getETag()); String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:entry", xmlString); assertXpathExists("/a:entry/@m:etag", xmlString); assertXpathEvaluatesTo("W/\"<\">.3\"", "/a:entry/@m:etag", xmlString); }
Example #26
Source File: DocViewFormat.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
/** internally formats the given file and computes their checksum * * @param file the file * @param original checksum of the original file * @param formatted checksum of the formatted file * @return the formatted bytes * @throws IOException if an error occurs */ private byte[] format(File file, Checksum original, Checksum formatted) throws IOException { try (InputStream in = new CheckedInputStream(new BufferedInputStream(new FileInputStream(file)), original)) { @SuppressWarnings("resource") ByteArrayOutputStream buffer = formattingBuffer != null ? formattingBuffer.get() : null; if (buffer == null) { buffer = new ByteArrayOutputStream(); formattingBuffer = new WeakReference<>(buffer); } else { buffer.reset(); } try (OutputStream out = new CheckedOutputStream(buffer, formatted); FormattingXmlStreamWriter writer = FormattingXmlStreamWriter.create(out, format)) { // cannot use XMlStreamReader due to comment handling: // https://stackoverflow.com/questions/15792007/why-does-xmlstreamreader-staxsource-strip-comments-from-xml TransformerFactory tf = TransformerFactory.newInstance(); tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); SAXSource saxSource = new SAXSource(new InputSource(in)); SAXParserFactory sf = SAXParserFactory.newInstance(); sf.setNamespaceAware(true); sf.setFeature("http://xml.org/sax/features/namespace-prefixes", true); sf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true); saxSource.setXMLReader(new NormalizingSaxFilter(sf.newSAXParser().getXMLReader())); Transformer t = tf.newTransformer(); StAXResult result = new StAXResult(writer); t.transform(saxSource, result); } return buffer.toByteArray(); } catch (TransformerException | XMLStreamException | FactoryConfigurationError | ParserConfigurationException | SAXException ex) { throw new IOException(ex); } }
Example #27
Source File: StaEDISchemaTest.java From staedi with Apache License 2.0 | 5 votes |
@Test void testRootTypeIsInterchange_00402() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); InputStream schemaStream = getClass().getResourceAsStream("/X12/v00402.xml"); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); reader.nextTag(); // Pass by <schema> element Map<String, EDIType> types = new SchemaReaderV4(reader, Collections.emptyMap()).readTypes(); schema.setTypes(types); assertEquals(EDIType.Type.INTERCHANGE, schema.getType(StaEDISchema.INTERCHANGE_ID).getType()); }
Example #28
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serializeCategory() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); employeeData.setWriteProperties(DEFAULT_PROPERTIES); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"), employeeData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry/a:category", xmlString); assertXpathExists("/a:entry/a:category/@term", xmlString); assertXpathExists("/a:entry/a:category/@scheme", xmlString); assertXpathEvaluatesTo("RefScenario.Employee", "/a:entry/a:category/@term", xmlString); assertXpathEvaluatesTo(Edm.NAMESPACE_SCHEME_2007_08, "/a:entry/a:category/@scheme", xmlString); }
Example #29
Source File: StaEDISchemaTest.java From staedi with Apache License 2.0 | 5 votes |
@Test void testLoadV3TransactionMultipleSyntaxElements_EDIFACT_CONTRL() throws EDISchemaException, XMLStreamException, FactoryConfigurationError { StaEDISchema schema = new StaEDISchema(StaEDISchema.INTERCHANGE_ID, StaEDISchema.TRANSACTION_ID); InputStream schemaStream = getClass().getResourceAsStream("/EDIFACT/CONTRL-v4r02.xml"); XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(schemaStream); reader.nextTag(); // Pass by <schema> element Map<String, EDIType> types = new SchemaReaderV3(reader, Collections.emptyMap()).readTypes(); schema.setTypes(types); assertEquals(EDIType.Type.TRANSACTION, schema.getType(StaEDISchema.TRANSACTION_ID).getType()); assertEquals(4, ((EDIComplexType) schema.getType("UCF")).getSyntaxRules().size()); assertEquals(4, ((EDIComplexType) schema.getType("UCI")).getSyntaxRules().size()); assertEquals(7, ((EDIComplexType) schema.getType("UCM")).getSyntaxRules().size()); }
Example #30
Source File: AtomEntrySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serializeIds() throws IOException, XpathException, SAXException, XMLStreamException, FactoryConfigurationError, ODataException { AtomSerializerDeserializer ser = createAtomEntityProvider(); photoData.setWriteProperties(DEFAULT_PROPERTIES); ODataResponse response = ser.writeEntry(MockFacade.getMockEdm().getEntityContainer("Container2").getEntitySet("Photos"), photoData); String xmlString = verifyResponse(response); assertXpathExists("/a:entry", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString(), "/a:entry/@xml:base", xmlString); assertXpathExists("/a:entry/a:id", xmlString); assertXpathEvaluatesTo(BASE_URI.toASCIIString() + "Container2.Photos(Id=1,Type='image%2Fpng')", "/a:entry/a:id/text()", xmlString); }