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:org.apache.nifi.authorization.FlowParser.java
public FlowParser() throws SAXException { schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); flowSchema = schemaFactory.newSchema(FileAuthorizer.class.getResource(FLOW_XSD)); }
From source file:org.apache.nifi.controller.service.ControllerServiceLoader.java
public List<ControllerServiceNode> loadControllerServices(final ControllerServiceProvider provider) throws IOException { final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); InputStream fis = null;//from w w w .ja va 2 s. c o m BufferedInputStream bis = null; documentBuilderFactory.setNamespaceAware(true); final List<ControllerServiceNode> services = new ArrayList<>(); try { final URL configurationResource = this.getClass().getResource("/ControllerServiceConfiguration.xsd"); if (configurationResource == null) { throw new NullPointerException("Unable to load XML Schema for ControllerServiceConfiguration"); } final Schema schema = schemaFactory.newSchema(configurationResource); documentBuilderFactory.setSchema(schema); final DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder(); builder.setErrorHandler(new org.xml.sax.ErrorHandler() { @Override public void fatalError(final SAXParseException err) throws SAXException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void error(final SAXParseException err) throws SAXParseException { logger.error("Config file line " + err.getLineNumber() + ", col " + err.getColumnNumber() + ", uri " + err.getSystemId() + " :message: " + err.getMessage()); if (logger.isDebugEnabled()) { logger.error("Error Stack Dump", err); } throw err; } @Override public void warning(final SAXParseException err) throws SAXParseException { logger.warn(" Config file line " + err.getLineNumber() + ", uri " + err.getSystemId() + " : message : " + err.getMessage()); if (logger.isDebugEnabled()) { logger.warn("Warning stack dump", err); } throw err; } }); //if controllerService.xml does not exist, create an empty file... fis = Files.newInputStream(this.serviceConfigXmlPath, StandardOpenOption.READ); bis = new BufferedInputStream(fis); if (Files.size(this.serviceConfigXmlPath) > 0) { final Document document = builder.parse(bis); final NodeList servicesNodes = document.getElementsByTagName("services"); final Element servicesElement = (Element) servicesNodes.item(0); final List<Element> serviceNodes = DomUtils.getChildElementsByTagName(servicesElement, "service"); for (final Element serviceElement : serviceNodes) { //get properties for the specific controller task - id, name, class, //and schedulingPeriod must be set final String serviceId = DomUtils.getChild(serviceElement, "identifier").getTextContent() .trim(); final String serviceClass = DomUtils.getChild(serviceElement, "class").getTextContent().trim(); //set the class to be used for the configured controller task final ControllerServiceNode serviceNode = provider.createControllerService(serviceClass, serviceId, false); //optional task-specific properties for (final Element optionalProperty : DomUtils.getChildElementsByTagName(serviceElement, "property")) { final String name = optionalProperty.getAttribute("name").trim(); final String value = optionalProperty.getTextContent().trim(); serviceNode.setProperty(name, value); } services.add(serviceNode); provider.enableControllerService(serviceNode); } } } catch (SAXException | ParserConfigurationException sxe) { throw new IOException(sxe); } finally { FileUtils.closeQuietly(fis); FileUtils.closeQuietly(bis); } return services; }
From source file:org.apache.nifi.controller.StandardFlowSynchronizer.java
private static Document parseFlowBytes(final byte[] flow) throws FlowSerializationException { // create document by parsing proposed flow bytes try {/*from www . j a v a 2s .c o m*/ // create validating document builder final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(FLOW_XSD_RESOURCE); final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); docFactory.setSchema(schema); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // parse flow return (flow == null || flow.length == 0) ? null : docBuilder.parse(new ByteArrayInputStream(flow)); } catch (final SAXException | ParserConfigurationException | IOException ex) { throw new FlowSerializationException(ex); } }
From source file:org.apache.nifi.fingerprint.FingerprintFactory.java
public FingerprintFactory(final StringEncryptor encryptor) { this.encryptor = encryptor; final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema; try {/* w w w . j a va 2 s . co m*/ schema = schemaFactory.newSchema(FingerprintFactory.class.getResource(FLOW_CONFIG_XSD)); } catch (final Exception e) { throw new RuntimeException("Failed to parse schema for file flow configuration.", e); } try { documentBuilderFactory.setSchema(schema); flowConfigDocBuilder = documentBuilderFactory.newDocumentBuilder(); } catch (final Exception e) { throw new RuntimeException("Failed to create document builder for flow configuration.", e); } }
From source file:org.apache.nifi.fingerprint.FingerprintFactoryTest.java
private DocumentBuilder getValidatingDocumentBuilder() { final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema; try {/*from w w w . j a v a 2 s . c om*/ schema = schemaFactory.newSchema(FingerprintFactory.class.getResource(FLOW_CONFIG_XSD)); } catch (final Exception e) { throw new RuntimeException("Failed to parse schema for file flow configuration.", e); } try { documentBuilderFactory.setSchema(schema); DocumentBuilder docBuilder = documentBuilderFactory.newDocumentBuilder(); docBuilder.setErrorHandler(new ErrorHandler() { @Override public void warning(SAXParseException e) throws SAXException { throw e; } @Override public void error(SAXParseException e) throws SAXException { throw e; } @Override public void fatalError(SAXParseException e) throws SAXException { throw e; } }); return docBuilder; } catch (final Exception e) { throw new RuntimeException("Failed to create document builder for flow configuration.", e); } }
From source file:org.apache.nifi.registry.security.authentication.IdentityProviderFactory.java
private IdentityProviders loadLoginIdentityProvidersConfiguration() throws Exception { final File loginIdentityProvidersConfigurationFile = properties.getIdentityProviderConfigurationFile(); // load the users from the specified file if (loginIdentityProvidersConfigurationFile.exists()) { try {/*from ww w . j a va 2 s. co m*/ // find the schema final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory .newSchema(IdentityProviders.class.getResource(LOGIN_IDENTITY_PROVIDERS_XSD)); // attempt to unmarshal XMLStreamReader xsr = XmlUtils .createSafeReader(new StreamSource(loginIdentityProvidersConfigurationFile)); final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(schema); final JAXBElement<IdentityProviders> element = unmarshaller.unmarshal(xsr, IdentityProviders.class); return element.getValue(); } catch (SAXException | JAXBException e) { throw new Exception("Unable to load the login identity provider configuration file at: " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } } else { throw new Exception("Unable to find the login identity provider configuration file at " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } }
From source file:org.apache.nifi.registry.security.authorization.AuthorizerFactory.java
private Authorizers loadAuthorizersConfiguration() throws Exception { final File authorizersConfigurationFile = properties.getAuthorizersConfigurationFile(); // load the authorizers from the specified file if (authorizersConfigurationFile.exists()) { try {//from ww w .j ava 2 s.c o m // find the schema final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory.newSchema(Authorizers.class.getResource(AUTHORIZERS_XSD)); // attempt to unmarshal final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(schema); final JAXBElement<Authorizers> element = unmarshaller.unmarshal( XmlUtils.createSafeReader(new StreamSource(authorizersConfigurationFile)), Authorizers.class); return element.getValue(); } catch (XMLStreamException | SAXException | JAXBException e) { throw new Exception("Unable to load the authorizer configuration file at: " + authorizersConfigurationFile.getAbsolutePath(), e); } } else { throw new Exception("Unable to find the authorizer configuration file at " + authorizersConfigurationFile.getAbsolutePath()); } }
From source file:org.apache.nifi.registry.security.authorization.file.FileAccessPolicyProvider.java
@Override public void initialize(AccessPolicyProviderInitializationContext initializationContext) throws SecurityProviderCreationException { userGroupProviderLookup = initializationContext.getUserGroupProviderLookup(); try {// ww w . java 2s. c om final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); authorizationsSchema = schemaFactory.newSchema(FileAuthorizer.class.getResource(AUTHORIZATIONS_XSD)); } catch (Exception e) { throw new SecurityProviderCreationException(e); } }
From source file:org.apache.nifi.registry.security.authorization.file.FileUserGroupProvider.java
@Override public void initialize(UserGroupProviderInitializationContext initializationContext) throws SecurityProviderCreationException { try {//from w w w .j av a 2s . co m final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); tenantsSchema = schemaFactory.newSchema(FileAuthorizer.class.getResource(TENANTS_XSD)); //usersSchema = schemaFactory.newSchema(FileAuthorizer.class.getResource(USERS_XSD)); } catch (Exception e) { throw new SecurityProviderCreationException(e); } }
From source file:org.apache.nifi.web.security.spring.LoginIdentityProviderFactoryBean.java
private LoginIdentityProviders loadLoginIdentityProvidersConfiguration() throws Exception { final File loginIdentityProvidersConfigurationFile = properties.getLoginIdentityProviderConfigurationFile(); // load the users from the specified file if (loginIdentityProvidersConfigurationFile.exists()) { try {//from w w w . ja v a 2s . c o m // find the schema final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); final Schema schema = schemaFactory .newSchema(LoginIdentityProviders.class.getResource(LOGIN_IDENTITY_PROVIDERS_XSD)); // attempt to unmarshal final Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller(); unmarshaller.setSchema(schema); final JAXBElement<LoginIdentityProviders> element = unmarshaller.unmarshal( new StreamSource(loginIdentityProvidersConfigurationFile), LoginIdentityProviders.class); return element.getValue(); } catch (SAXException | JAXBException e) { throw new Exception("Unable to load the login identity provider configuration file at: " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } } else { throw new Exception("Unable to find the login identity provider configuration file at " + loginIdentityProvidersConfigurationFile.getAbsolutePath()); } }