/** * Returns user properties from path under ${catalina.home}. The user Properties must comply with standard properties rules. * * @param propertiesPath * the path to user property * @return Properties {@Link Properties} * @throws PropertyException * */ // TODO: resolve dependencies to catalina.home - make more generic public static Properties loadProperties(final String propertiesPath) throws PropertyException { if (propertiesPath == null || propertiesPath.length() == 0) { throw new PropertyException("propertiesPath may not be empty or null"); } final String catalinaHome = System.getProperty("catalina.home", System.getProperty("user.dir")); String propPath = propertiesPath.replace("\\", "/").replaceAll("/+", "/"); if (propPath.indexOf("/") == -1) { propPath = "/" + propPath; } final String propertyPath = catalinaHome + propPath; final Properties properties = new Properties(); try (FileInputStream fi = new FileInputStream(new File(propertyPath));) { properties.load(fi); } catch (final IOException e) { throw new PropertyException("properties not found at this location"); } return properties; }
/** * Return runtime properties of given {@code runtimeProperties}. Looks first, if application is running on a dev machine and returns in this case the * properties from the resource context. Otherwise a lookup in properties folder in webapps context is fullfilled. * * @param runtimeProperties * @return properties {@link Properties} * @throws PropertyException */ public static Properties getRuntimeProperties(final String runtimeProperties) throws PropertyException { if (runtimeProperties == null || runtimeProperties.length() == 0) { throw new PropertyException("path may not be empty or null"); } final Properties properties = new Properties(); final String fileType = runtimeProperties.substring(runtimeProperties.lastIndexOf(".") + 1, runtimeProperties.length()); final File propFile = readFile(runtimeProperties); try (FileInputStream fi = new FileInputStream(propFile);) { if ("xml".equals(fileType)) { properties.loadFromXML(fi); } else { properties.load(fi); } } catch (final IOException e) { System.err.println(ProjectProperty.class.getSimpleName() + " IOException for " + runtimeProperties + " " + e.getMessage()); } return properties; }
/** * read dbSourceName from ZK and set into DataSourceInfo * * @param dsInfo (in) * @return * @throws Exception */ public void loadDsNameAndOffset(DataSourceInfo dsInfo) throws Exception { // read dbSourceName String path = topologyRoot + "/" + Constants.DISPATCHER_RAW_TOPICS_PROPERTIES; Properties raw_topics = zkService.getProperties(path); String dbSourceName = raw_topics.getProperty(Constants.DISPATCHER_DBSOURCE_NAME); if (dbSourceName == null) { throw new PropertyException("配置参数文件内容不能为空! " + Constants.DISPATCHER_DBSOURCE_NAME); } String dataTopicOffset = raw_topics.getProperty(Constants.DISPATCHER_OFFSET); if (dataTopicOffset == null) { throw new PropertyException("配置参数文件内容不能为空! " + Constants.DISPATCHER_OFFSET); } dsInfo.setDbSourceName(dbSourceName); dsInfo.setDataTopicOffset(dataTopicOffset); }
public InfluxSink() throws IOException, PropertyException { Properties configProps = ConfUtils.getProps(CONFIG_PROPERTIES); String dbURL = configProps.getProperty(Constants.InfluxDB.DB_URL); String dbName = configProps.getProperty(Constants.InfluxDB.DB_NAME); tableName = configProps.getProperty(Constants.InfluxDB.TABLE_NAME); if (dbURL == null) { throw new PropertyException("配置参数文件内容不能为空! " + Constants.InfluxDB.DB_URL); } if (dbName == null) { throw new PropertyException("配置参数文件内容不能为空! " + Constants.InfluxDB.DB_NAME); } if (tableName == null) { throw new PropertyException("配置参数文件内容不能为空! " + Constants.InfluxDB.TABLE_NAME); } postURL = String.format("%s/write?db=%s", dbURL, dbName); initPost(); }
@Override public void setProperty(String name, Object value) throws PropertyException { if(name.equals(FACTORY)) { coordinator.setFactories(value); return; } if(name.equals(IDResolver.class.getName())) { idResolver = (IDResolver)value; return; } if(name.equals(ClassResolver.class.getName())) { coordinator.classResolver = (ClassResolver)value; return; } if(name.equals(ClassLoader.class.getName())) { coordinator.classLoader = (ClassLoader)value; return; } super.setProperty(name, value); }
@Override public Object getProperty(String name) throws PropertyException { if( INDENT_STRING.equals(name) ) return indent; if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name) ) return escapeHandler; if( PREFIX_MAPPER.equals(name) ) return prefixMapper; if( XMLDECLARATION.equals(name) ) return !isFragment(); if( XML_HEADERS.equals(name) ) return header; if( C14N.equals(name) ) return c14nSupport; if ( OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) return serializer.getObjectIdentityCycleDetection(); return super.getProperty(name); }
/** * Default implementation of the getProperty method handles * the four defined properties in Marshaller. If a provider * needs to support additional provider specific properties, * it should override this method in a derived class. */ public Object getProperty( String name ) throws PropertyException { if( name == null ) { throw new IllegalArgumentException( Messages.format( Messages.MUST_NOT_BE_NULL, "name" ) ); } // recognize and handle four pre-defined properties. if( JAXB_ENCODING.equals(name) ) return getEncoding(); if( JAXB_FORMATTED_OUTPUT.equals(name) ) return isFormattedOutput()?Boolean.TRUE:Boolean.FALSE; if( JAXB_NO_NAMESPACE_SCHEMA_LOCATION.equals(name) ) return getNoNSSchemaLocation(); if( JAXB_SCHEMA_LOCATION.equals(name) ) return getSchemaLocation(); if( JAXB_FRAGMENT.equals(name) ) return isFragment()?Boolean.TRUE:Boolean.FALSE; throw new PropertyException(name); }
public static void marshallData(IndoorFeaturesType ifs) throws JAXBException { File file = new File("indoorExample.xml"); JAXBContext jaxbContext = JAXBContext.newInstance(IndoorFeaturesType.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); try { jaxbMarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new IndoorGMLNamespaceMapper()); } catch (PropertyException e) { // In case another JAXB implementation is used e.printStackTrace(); } // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(ifs, file); jaxbMarshaller.marshal(ifs, System.out); }
public static void marshallData(FeatureCollectionType ifs) throws JAXBException { File file = new File("gmltest.gml"); JAXBContext jaxbContext = JAXBContext.newInstance(FeatureCollectionType.class, CustomPointFeatureMember.class, CustomLineFeatureMember.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); try { jaxbMarshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new GMLNamespaceMapper()); } catch (PropertyException e) { // In case another JAXB implementation is used e.printStackTrace(); } // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); net.opengis.gml.v_3_2_1.ObjectFactory gmlObjfact = new net.opengis.gml.v_3_2_1.ObjectFactory(); JAXBElement<?> elem = gmlObjfact.createFeatureCollection(ifs); jaxbMarshaller.marshal(elem, file); jaxbMarshaller.marshal(elem, System.out); }
private static void storeMethod(String unisonXMLFile, TremoloType tt, String ksPath, KeyStore ks) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, JAXBException, PropertyException { logger.info("Storing the keystore"); ks.store(new FileOutputStream(ksPath), tt.getKeyStorePassword().toCharArray()); logger.info("Saving the unison xml file"); JAXBContext jc = JAXBContext.newInstance("com.tremolosecurity.config.xml"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); OutputStream os = new FileOutputStream(unisonXMLFile); JAXBElement<TremoloType> root = new JAXBElement<TremoloType>(new QName("http://www.tremolosecurity.com/tremoloConfig","tremoloConfig","tns"),TremoloType.class,tt); marshaller.marshal(root, os); os.flush(); os.close(); }
@Override public <T> Marshaller buildMarshaller(T src, @Nullable Map<String, Object> marshallerProps) throws JAXBException { Marshaller marshaller = this.findTypeMetadata(src.getClass()).getContext().getContext().createMarshaller(); Map<String, Object> mergedMarshallerProps = new HashMap<>(this.defaultMarshallerProps); if (!MapUtils.isEmpty(marshallerProps)) { mergedMarshallerProps.putAll(marshallerProps); } Object marshallerPropValue; for (String marshallerPropName : mergedMarshallerProps.keySet()) { marshallerPropValue = mergedMarshallerProps.get(marshallerPropName); try { marshaller.setProperty(marshallerPropName, marshallerPropValue); } catch (PropertyException e) { throw new JAXBException(String.format("Unable to set JAXB marshaller property (name=%s) value: %s", marshallerPropName, marshallerPropValue), e); } } return marshaller; }
@Override public <T> Unmarshaller buildUnmarshaller(Class<T> resultClass, @Nullable Map<String, Object> unmarshallerProps) throws JAXBException { Unmarshaller unmarshaller = this.findTypeMetadata(resultClass).getContext().getContext().createUnmarshaller(); Map<String, Object> mergedUnmarshallerProps = new HashMap<>(this.defaultUnmarshallerProps); if (!MapUtils.isEmpty(unmarshallerProps)) { mergedUnmarshallerProps.putAll(unmarshallerProps); } Object unmarshallerPropValue; for (String unmarshallerPropName : mergedUnmarshallerProps.keySet()) { unmarshallerPropValue = mergedUnmarshallerProps.get(unmarshallerPropName); try { unmarshaller.setProperty(unmarshallerPropName, unmarshallerPropValue); } catch (PropertyException e) { throw new JAXBException( String.format("Unable to set JAXB unmarshaller property (name=%s) value: %s", unmarshallerPropName, unmarshallerPropValue), e); } } return unmarshaller; }
public ProcessModel unmarshalProcessModel(File procSchmInFile) throws JAXBException, PropertyException, FileNotFoundException, IOException { String pkgName = ProcessModel.class.getCanonicalName().toString(); pkgName = pkgName.substring(0, pkgName.lastIndexOf('.')); JAXBContext jaxbCtx = JAXBContext.newInstance(pkgName); Unmarshaller unmarsh = jaxbCtx.createUnmarshaller(); unmarsh.setEventHandler( new ValidationEventHandler() { public boolean handleEvent(ValidationEvent event) { throw new RuntimeException(event.getMessage(), event.getLinkedException()); } }); ProcessModel proMod = (ProcessModel) unmarsh.unmarshal(procSchmInFile); MetaConstraintUtils.createHierarchicalLinks(proMod.getAllConstraints()); return proMod; }
public void marshalProcessModel(ProcessModel processModel, File procSchmOutFile) throws JAXBException, PropertyException, FileNotFoundException, IOException { String pkgName = processModel.getClass().getCanonicalName().toString(); pkgName = pkgName.substring(0, pkgName.lastIndexOf('.')); JAXBContext jaxbCtx = JAXBContext.newInstance(pkgName); Marshaller marsh = jaxbCtx.createMarshaller(); marsh.setProperty("jaxb.formatted.output", true); StringWriter strixWriter = new StringWriter(); marsh.marshal(processModel, strixWriter); strixWriter.flush(); StringBuffer strixBuffer = strixWriter.getBuffer(); // OINK // strixBuffer.replace( // strixBuffer.indexOf(">", strixBuffer.indexOf("?>") + 3), // strixBuffer.indexOf(">", strixBuffer.indexOf("?>") + 3), // " xmlns=\"" + ProcessModel.MINERFUL_XMLNS + "\""); FileWriter strixFileWriter = new FileWriter(procSchmOutFile); strixFileWriter.write(strixBuffer.toString()); strixFileWriter.flush(); strixFileWriter.close(); }
public static void setNamespaceWrapper(final Map<String, String> nspref, Marshaller marshaller) throws PropertyException { Object mapper = null; if (marshaller.getClass().getName().contains(".internal.")) { mapper = createNamespaceWrapper(nspref); if (mapper == null) { LOG.log(Level.INFO, "Could not create namespace mapper for JDK internal" + " JAXB implementation."); } else { marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", mapper); } } else { try { Class<?> cls = Class.forName("org.apache.cxf.jaxb.NamespaceMapper"); mapper = cls.getConstructor(Map.class).newInstance(nspref); } catch (Exception ex) { LOG.log(Level.INFO, "Could not create NamespaceMapper", ex); } marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper); } }
public void setProperty(String name, Object value) throws PropertyException { if(name.equals(FACTORY)) { coordinator.setFactories(value); return; } if(name.equals(IDResolver.class.getName())) { idResolver = (IDResolver)value; return; } if(name.equals(ClassResolver.class.getName())) { coordinator.classResolver = (ClassResolver)value; return; } if(name.equals(ClassLoader.class.getName())) { coordinator.classLoader = (ClassLoader)value; return; } super.setProperty(name, value); }
public Object getProperty(String name) throws PropertyException { if( INDENT_STRING.equals(name) ) return indent; if( ENCODING_HANDLER.equals(name) || ENCODING_HANDLER2.equals(name) ) return escapeHandler; if( PREFIX_MAPPER.equals(name) ) return prefixMapper; if( XMLDECLARATION.equals(name) ) return !isFragment(); if( XML_HEADERS.equals(name) ) return header; if( C14N.equals(name) ) return c14nSupport; if ( OBJECT_IDENTITY_CYCLE_DETECTION.equals(name)) return serializer.getObjectIdentityCycleDetection(); ; return super.getProperty(name); }
public static void transform(LegoList ll, OutputStream target, Transformer transformer, boolean tidyHtml ) throws IOException, TransformerException, PropertyException, JAXBException { String legoListAsXML = toXML(ll); if (transformer != null) { ByteArrayInputStream bais = new ByteArrayInputStream(legoListAsXML.getBytes()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); transformer.transform(new StreamSource(bais), new StreamResult(baos)); if (tidyHtml) { getTidy().parse(new ByteArrayInputStream(baos.toByteArray()), target); } else { target.write(baos.toByteArray()); } } else { target.write(legoListAsXML.getBytes()); } }
public static void transform(Lego l, OutputStream target, Transformer transformer, boolean tidyHtml ) throws IOException, TransformerException, PropertyException, JAXBException { String legoAsXML = toXML(l); if (transformer != null) { ByteArrayInputStream bais = new ByteArrayInputStream(legoAsXML.getBytes()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); transformer.transform(new StreamSource(bais), new StreamResult(baos)); if (tidyHtml) { getTidy().parse(new ByteArrayInputStream(baos.toByteArray()), target); } else { target.write(baos.toByteArray()); } } else { target.write(legoAsXML.getBytes()); } }
public static final ShortLinkRepository newShortLinkRepository(PropertyResolver props) throws PropertyException { final String repoType; boolean enabled; enabled = props.getProperty("shortlink.enabled", Boolean.class, true); if(!enabled) { log.info("Shortlinking disabled in config"); return new NoOpRepository(); } repoType = props.getProperty("shortlink.backend", String.class, "HDFS"); if ("HDFS".equals(repoType)) { return new HDFSShortLinkRepository(props); } if ("S3".equals(repoType)) { return new S3ShortLinkRepository(props); } throw new PropertyException("Unknown cache type (property: shortlink.backend): " + repoType); }
public static final QueryCache newQueryCache(PropertyResolver props) throws PropertyException { final String cacheType; boolean enabled; enabled = props.getProperty("query.cache.enabled", Boolean.class, true); if(!enabled) { log.info("Query caching disabled in config"); return new NoOpQueryCache(); } cacheType = props.getProperty("query.cache.backend", String.class, "HDFS"); if ("HDFS".equals(cacheType)) { return new HDFSQueryCache(props); } if ("S3".equals(cacheType)) { return new S3QueryCache(props); } throw new PropertyException("Unknown cache type (property: query.cache.backend): " + cacheType); }
/** * Marshall object. * * @param propertyName the property name * @param newPropertyValue the new property value * @param jaxbContext the jaxb context * @param confFile the conf file * @param configuration the configuration * @return true, if successful * @throws JAXBException the jAXB exception * @throws PropertyException the property exception */ private static boolean marshallObject(String propertyName, String newPropertyValue, JAXBContext jaxbContext, File confFile, Configuration configuration) throws JAXBException, PropertyException { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // create Property Object Property property = new Property(); property.setName(propertyName); property.setValue(newPropertyValue); // add to parent configuration.getProperty().add(property); // update file marshaller.marshal(configuration, confFile); return true; }