List of usage examples for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI
String W3C_XML_SCHEMA_NS_URI
To view the source code for javax.xml XMLConstants W3C_XML_SCHEMA_NS_URI.
Click Source Link
From source file:ddf.test.itests.platform.TestSingleSignOn.java
private void validateSaml(String xml, SamlSchema schema) throws IOException { // Prepare the schema and xml String schemaFileName = "saml-schema-" + schema.toString().toLowerCase() + "-2.0.xsd"; URL schemaURL = getClass().getClassLoader().getResource(schemaFileName); StreamSource streamSource = new StreamSource(new StringReader(xml)); // If we fail to create a validator we don't want to stop the show, so we just log a warning Validator validator = null;//from www. ja va 2 s . c om try { validator = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaURL) .newValidator(); } catch (SAXException e) { LOGGER.warn("Exception creating validator. ", e); } // If the xml is invalid, then we want to fail completely if (validator != null) { try { validator.validate(streamSource); } catch (SAXException e) { fail("Failed to validate SAML " + e.getMessage()); } } }
From source file:org.eclipse.winery.repository.client.WineryRepositoryClient.java
/** * @param useProxy if a debugging proxy should be used * * @throws IllegalStateException if DOM parser could not be created *//* w w w . ja v a 2 s. c om*/ public WineryRepositoryClient(boolean useProxy) { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getClasses().add(JacksonJsonProvider.class); if (useProxy) { URLConnectionClientHandler ch = new URLConnectionClientHandler(new ConnectionFactory()); this.client = new Client(ch, clientConfig); } else { this.client = Client.create(clientConfig); } this.entityTypeDataCache = new HashMap<>(); this.nameCache = new HashMap<>(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); if (WineryRepositoryClient.VALIDATING) { factory.setValidating(true); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema; URL resource = this.getClass().getResource("/TOSCA-v1.0.xsd"); try { schema = schemaFactory.newSchema(resource); } catch (SAXException e) { throw new IllegalStateException("Schema could not be initalized", e); } factory.setSchema(schema); } try { this.toscaDocumentBuilder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IllegalStateException("document builder could not be initalized", e); } /* TODO: include this somehow - in the case of VALIDATING Does not work with TTopolgoyTemplate as this is not allowed in the root of an XML document this.toscaDocumentBuilder.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException arg0) throws SAXException { throw arg0; } @Override public void fatalError(SAXParseException arg0) throws SAXException { throw arg0; } @Override public void error(SAXParseException arg0) throws SAXException { throw arg0; } }); */ }
From source file:com.mymita.vaadlets.JAXBUtils.java
private static final Vaadlets unmarshal(final Reader aReader, final Resource theSchemaResource) { try {//from w ww . j av a 2 s .com final JAXBContext jc = JAXBContext.newInstance(CONTEXTPATH); final Unmarshaller unmarshaller = jc.createUnmarshaller(); if (theSchemaResource != null) { final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); schemaFactory.setResourceResolver(new ClasspathResourceResolver()); final Schema schema = schemaFactory.newSchema(new StreamSource(theSchemaResource.getInputStream())); unmarshaller.setSchema(schema); } return unmarshaller .unmarshal(XMLInputFactory.newInstance().createXMLStreamReader(aReader), Vaadlets.class) .getValue(); } catch (final JAXBException | SAXException | XMLStreamException | FactoryConfigurationError | IOException e) { throw new RuntimeException("Can't unmarschal", e); } }
From source file:cz.strmik.cmmitool.cmmi.DefaultRatingScalesProvider.java
private void validateScalesDocument(Document document) throws SAXException, IOException { SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source schemaFile = new StreamSource(getClass().getClassLoader().getResourceAsStream(SCALES_XSD)); Schema schema = schemaFactory.newSchema(schemaFile); Validator validator = schema.newValidator(); validator.validate(new DOMSource(document)); }
From source file:alter.vitro.vgw.service.query.SimpleQueryHandler.java
/** * * Init method. Required for handling AND responding to queries *///from w w w . j av a 2 s . co m public void initInstance(String pPeerId, String pPeerName, GWCommandMQMessageConsumerProducer gwCommandMQMessageConsumerProducer, WsiAdapterCon myDCon) { myPeerId = pPeerId; myPeerName = pPeerName; myPipeDataProducer = gwCommandMQMessageConsumerProducer.getProducer(); myPipeDataSession = gwCommandMQMessageConsumerProducer.getSession(); this.myDCon = myDCon; if (schema == null) { try { schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/aggrquery/PublicQueryAggrMsg.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema from PublicQueryAggrMsg.xsd", saxEx); } } if (enDisFromVSPschema == null) { try { enDisFromVSPschema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/enablednodessynch/fromvsp/fromvsp.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema (enable synch) from fromvsp.xsd", saxEx); } } if (equivSynchFromVSPschema == null) { try { equivSynchFromVSPschema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new File( "src/main/java/alter/vitro/vgw/service/query/xmlmessages/equivlistsynch/fromvsp/fromvsp.xsd")); } catch (SAXException saxEx) { logger.error("Exception while initializing schema (equiv list synch) from fromvsp.xsd", saxEx); } } }
From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java
private void validateExtraRequest(final Node transportNode, final ServletContext servletContext) throws Exception { // Validator-Objekt mit eXTra-Schema als Basis erstellen final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = factory.newSchema(servletContext.getResource(SCHEMA_PATH)); final Validator validator = schema.newValidator(); try {/*from w w w . j a va 2s . c o m*/ // Validiere Transport-Element gegen eXTra-Schema validator.validate(new DOMSource(transportNode)); } catch (final SAXException e) { // Falls MTOM-Attachement, dann den Fehler bzgl. cid-Referenz // ignorieren if (!(e.getMessage().contains("cid:") && e.getMessage().contains("'base64Binary'"))) { LOG.warn("Fehler bei der XML-Validierung: " + e.getMessage()); throw new InvalidExtraRequestException(e.getMessage()); } } }
From source file:admincommands.Reload.java
private Schema getSchema(String xml_schema) { Schema schema = null;/*from w w w . ja v a2 s.co m*/ SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { schema = sf.newSchema(new File(xml_schema)); } catch (SAXException saxe) { throw new Error("Error while getting schema", saxe); } return schema; }
From source file:cz.cas.lib.proarc.common.imports.TiffImporterTest.java
@Test public void testConsume() throws Exception { temp.setDeleteOnExit(true);// ww w. ja v a 2 s.c om File targetFolder = ImportProcess.createTargetFolder(temp.getRoot()); assertTrue(targetFolder.exists()); String mimetype = ImportProcess.findMimeType(tiff1); assertNotNull(mimetype); ImportOptions ctx = new ImportOptions(tiff1.getParentFile(), "scanner:scanner1", true, junit, config.getImportConfiguration()); ctx.setTargetFolder(targetFolder); Batch batch = new Batch(); batch.setId(1); batch.setFolder(ibm.relativizeBatchFile(tiff1.getParentFile())); ctx.setBatch(batch); FileSet fileSet = ImportFileScanner.getFileSets(Arrays.asList(tiff1, ocr1, alto1, ac1, uc1)).get(0); ctx.setJhoveContext(jhoveContext); TiffImporter instance = new TiffImporter(ibm); BatchItemObject result = instance.consume(fileSet, ctx); String pid = result.getPid(); assertTrue(pid.startsWith("uuid")); assertEquals(ObjectState.LOADED, result.getState()); File foxml = result.getFile(); assertTrue(foxml.toString(), foxml.exists()); File rootFoxml = new File(foxml.getParent(), ImportBatchManager.ROOT_ITEM_FILENAME); assertTrue(rootFoxml.toString(), rootFoxml.exists()); File raw1 = new File(targetFolder, "img1.full.jpg"); assertTrue(raw1.exists() && raw1.length() > 0); File preview1 = new File(targetFolder, "img1.preview.jpg"); assertTrue(preview1.exists() && preview1.length() > 0); File thumb1 = new File(targetFolder, "img1.thumb.jpg"); assertTrue(thumb1.exists() && thumb1.length() > 0); // validate FOXML SchemaFactory sfactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); URL foxmlXsdUrl = ObjectFactory.class.getResource("/xsd/foxml/foxml1-1.xsd"); assertNotNull(foxmlXsdUrl); Schema foxmlXsd = sfactory.newSchema(foxmlXsdUrl); foxmlXsd.newValidator().validate(new StreamSource(foxml)); // check datastreams with xpath HashMap<String, String> namespaces = new HashMap<String, String>(); namespaces.put("f", "info:fedora/fedora-system:def/foxml#"); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces)); String foxmlSystemId = foxml.toURI().toASCIIString(); XMLAssert.assertXpathExists(streamXPath(ModsStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(DcStreamEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(StringEditor.OCR_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(AltoDatastream.ALTO_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.FULL_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.PREVIEW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.THUMB_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.RAW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(MixEditor.RAW_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(BinaryEditor.NDK_USER_ID), new InputSource(foxmlSystemId)); XMLAssert.assertXpathExists(streamXPath(MixEditor.NDK_ARCHIVAL_ID), new InputSource(foxmlSystemId)); String rootSystemId = rootFoxml.toURI().toASCIIString(); XMLAssert.assertXpathExists(streamXPath(RelationEditor.DATASTREAM_ID), new InputSource(rootSystemId)); EasyMock.verify(toVerify.toArray()); }
From source file:de.fhg.iais.model.aip.util.XmlUtilsTest.java
private static Document parseAndValidate(String xml, URL xsd) { final SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema;// ww w. j av a2 s. co m try { schema = factory.newSchema(xsd); } catch (final SAXException e) { throw new DbcException(e); } // final Document xmlDocument = XmlUtils.parse(xml); final Document xmlDocument = XmlProcessor.buildDocumentFrom(xml); final Validator validator = schema.newValidator(); try { validator.validate(new JDOMSource(xmlDocument)); return xmlDocument; } catch (final SAXException e) { throw new DbcException(e); } catch (final IOException e) { throw new DbcException(e); } }
From source file:com.legstar.cob2xsd.XsdAnnotationEmitter.java
/** * Adds the COXB namespace and associated prefixes to the XML schema. *///from www .ja v a 2 s .c om protected void addNamespaceContext() { NamespaceMap prefixmap = new NamespaceMap(); NamespacePrefixList npl = getXsd().getNamespaceContext(); if (npl == null) { /* We get an NPE if we don't add this. */ prefixmap.add("", XMLConstants.W3C_XML_SCHEMA_NS_URI); } else { for (int i = 0; i < npl.getDeclaredPrefixes().length; i++) { prefixmap.add(npl.getDeclaredPrefixes()[i], npl.getNamespaceURI(npl.getDeclaredPrefixes()[i])); } } prefixmap.add(getCOXBNamespacePrefix(), getCOXBNamespace()); getXsd().setNamespaceContext(prefixmap); }