List of usage examples for java.util Properties isEmpty
@Override public boolean isEmpty()
From source file:org.apache.sqoop.mapreduce.hcat.SqoopHCatImportHelper.java
public SqoopHCatImportHelper(Configuration conf) throws IOException, InterruptedException { String inputJobInfoStr = conf.get(HCatConstants.HCAT_KEY_JOB_INFO); jobInfo = (InputJobInfo) HCatUtil.deserialize(inputJobInfoStr); dataColsSchema = jobInfo.getTableInfo().getDataColumns(); partitionSchema = jobInfo.getTableInfo().getPartitionColumns(); StringBuilder storerInfoStr = new StringBuilder(1024); StorerInfo storerInfo = jobInfo.getTableInfo().getStorerInfo(); storerInfoStr.append("HCatalog Storer Info : ").append("\n\tHandler = ") .append(storerInfo.getStorageHandlerClass()).append("\n\tInput format class = ") .append(storerInfo.getIfClass()).append("\n\tOutput format class = ") .append(storerInfo.getOfClass()).append("\n\tSerde class = ").append(storerInfo.getSerdeClass()); Properties storerProperties = storerInfo.getProperties(); if (!storerProperties.isEmpty()) { storerInfoStr.append("\nStorer properties "); for (Map.Entry<Object, Object> entry : storerProperties.entrySet()) { String key = (String) entry.getKey(); Object val = entry.getValue(); storerInfoStr.append("\n\t").append(key).append('=').append(val); }//from w w w. j ava 2 s. c o m } storerInfoStr.append("\n"); LOG.info(storerInfoStr); hCatFullTableSchema = new HCatSchema(dataColsSchema.getFields()); for (HCatFieldSchema hfs : partitionSchema.getFields()) { hCatFullTableSchema.append(hfs); } fieldCount = hCatFullTableSchema.size(); lobLoader = new LargeObjectLoader(conf, new Path(jobInfo.getTableInfo().getTableLocation())); bigDecimalFormatString = conf.getBoolean(ImportJobBase.PROPERTY_BIGDECIMAL_FORMAT, ImportJobBase.PROPERTY_BIGDECIMAL_FORMAT_DEFAULT); debugHCatImportMapper = conf.getBoolean(SqoopHCatUtilities.DEBUG_HCAT_IMPORT_MAPPER_PROP, false); IntWritable[] delimChars = DefaultStringifier.loadArray(conf, SqoopHCatUtilities.HIVE_DELIMITERS_TO_REPLACE_PROP, IntWritable.class); hiveDelimiters = new DelimiterSet((char) delimChars[0].get(), (char) delimChars[1].get(), (char) delimChars[2].get(), (char) delimChars[3].get(), delimChars[4].get() == 1 ? true : false); hiveDelimsReplacement = conf.get(SqoopHCatUtilities.HIVE_DELIMITERS_REPLACEMENT_PROP); if (hiveDelimsReplacement == null) { hiveDelimsReplacement = ""; } doHiveDelimsReplacement = Boolean .valueOf(conf.get(SqoopHCatUtilities.HIVE_DELIMITERS_REPLACEMENT_ENABLED_PROP)); IntWritable[] fPos = DefaultStringifier.loadArray(conf, SqoopHCatUtilities.HCAT_FIELD_POSITIONS_PROP, IntWritable.class); hCatFieldPositions = new int[fPos.length]; for (int i = 0; i < fPos.length; ++i) { hCatFieldPositions[i] = fPos[i].get(); } LOG.debug("Hive delims replacement enabled : " + doHiveDelimsReplacement); LOG.debug("Hive Delimiters : " + hiveDelimiters.toString()); LOG.debug("Hive delimiters replacement : " + hiveDelimsReplacement); staticPartitionKeys = conf.getStrings(SqoopHCatUtilities.HCAT_STATIC_PARTITION_KEY_PROP); String partKeysString = staticPartitionKeys == null ? "" : Arrays.toString(staticPartitionKeys); LOG.debug("Static partition key used : " + partKeysString); }
From source file:net.ymate.platform.commons.i18n.I18N.java
/** * @param resourceName ???//from ww w . j ava2 s .com * @param key * @param defaultValue * @return ????key */ public static String load(String resourceName, String key, String defaultValue) { Map<String, Properties> _cache = __RESOURCES_CAHCES.get(current()); Properties _prop = _cache != null ? _cache.get(resourceName) : null; if (_prop == null) { if (__EVENT_HANDLER != null) { try { List<String> _localeResourceNames = resourceNames(current(), resourceName); InputStream _inputStream = null; for (String _localeResourceName : _localeResourceNames) { _inputStream = __EVENT_HANDLER.onLoadProperties(_localeResourceName); if (_inputStream != null) { break; } } if (_inputStream == null) { for (String _localeResourceName : _localeResourceNames) { _inputStream = I18N.class.getClassLoader().getResourceAsStream(_localeResourceName); if (_inputStream != null) { break; } } } if (_inputStream != null) { _prop = new Properties(); _prop.load(_inputStream); } if (_prop != null && !_prop.isEmpty()) { if (_cache == null) { __RESOURCES_CAHCES.put(current(), new ConcurrentHashMap<String, Properties>()); } __RESOURCES_CAHCES.get(current()).put(resourceName, _prop); } } catch (IOException e) { _LOG.warn("", RuntimeUtils.unwrapThrow(e)); } } } String _returnValue = null; if (_prop != null) { _returnValue = _prop.getProperty(key, defaultValue); } return StringUtils.defaultIfEmpty(_returnValue, defaultValue); }
From source file:org.pentaho.platform.plugin.services.importer.LocaleImportHandler.java
/** * return locale specific properties from resource bundle * * @param locale/*from ww w.j av a2s . c om*/ * @return */ private Properties buildLocaleProperties(RepositoryFileImportBundle locale, Properties localePropertiesFromIndex) { Properties localeProperties = new Properties(); PropertyResourceBundle rb = null; String comment = locale.getComment(); String fileTitle = locale.getName(); if (!localePropertiesFromIndex.isEmpty()) { // for old style index.xml as locale comment = localePropertiesFromIndex.getProperty(DESC_PROPERTY_NAME); fileTitle = localePropertiesFromIndex.getProperty(TITLE_PROPERTY_NAME); } else { try { byte[] bytes = IOUtils.toByteArray(locale.getInputStream()); java.io.InputStream bundleInputStream = new ByteArrayInputStream(bytes); rb = new PropertyResourceBundle(bundleInputStream); } catch (Exception returnEmptyIfError) { getLogger().error(returnEmptyIfError.getMessage()); return localeProperties; } if (rb != null) { // this is the 4.8 style - name and description // First try file desc. If no file desc, try for a directory desc, else try fallback comment = rb.containsKey(DESC_PROPERTY_NAME) ? rb.getString(DESC_PROPERTY_NAME) : rb.containsKey(FILE_DESCRIPTION) ? rb.getString(FILE_DESCRIPTION) : rb.containsKey(DIRECTORY_DESCRIPTION) ? rb.getString(DIRECTORY_DESCRIPTION) : comment; // First try name. If no name, try title. If no title, try for a directory name, else use filename. fileTitle = rb.containsKey(TITLE_PROPERTY_NAME) ? rb.getString(TITLE_PROPERTY_NAME) : rb.containsKey("title") ? rb.getString("title") : rb.containsKey(FILE_TITLE) ? rb.getString(FILE_TITLE) : rb.containsKey(DIRECTORY_NAME) ? rb.getString(DIRECTORY_NAME) : fileTitle; } } // this is the new .locale Jcr property names localeProperties.setProperty(FILE_DESCRIPTION, comment != null ? comment : StringUtils.EMPTY); localeProperties.setProperty(FILE_TITLE, fileTitle != null ? fileTitle : StringUtils.EMPTY); return localeProperties; }
From source file:com.redhat.rcm.maven.plugin.buildmetadata.BuildReportRenderer.java
private void renderNonStandardProperties(final Properties buildMetaDataProperties) { final Properties nonStandardProperties = Constant.calcNonStandardProperties(buildMetaDataProperties, properties);/*from w w w . j av a 2 s .c o m*/ if (!nonStandardProperties.isEmpty()) { sink.sectionTitle2(); sink.text(messages.getString(Constant.SECTION_BUILD_MISC)); sink.sectionTitle2_(); renderTableStart(); for (final Enumeration<Object> en = nonStandardProperties.keys(); en.hasMoreElements();) { final String key = String.valueOf(en.nextElement()); if (Constant.isIntendedForMiscSection(key)) { renderCell(nonStandardProperties, key); } } renderTableEnd(); } }
From source file:org.nuxeo.theme.themes.ThemeSerializer.java
private void serializeFormat(final Format format, final org.w3c.dom.Element domParent) { final String typeName = format.getFormatType().getTypeName(); final org.w3c.dom.Element domElement = doc.createElement(typeName); final String description = format.getDescription(); if (description != null) { domParent.appendChild(doc.createComment(String.format(" %s ", description))); }/* w ww . ja va 2s. c o m*/ StringBuilder s = new StringBuilder(); Iterator<Element> iter = ElementFormatter.getElementsFor(format).iterator(); boolean hasElement = iter.hasNext(); while (iter.hasNext()) { Element element = iter.next(); s.append(element.computeXPath()); if (iter.hasNext()) { s.append("|"); } } if (hasElement) { domElement.setAttribute("element", s.toString()); } // widgets if ("widget".equals(typeName)) { // view name String viewName = format.getName(); org.w3c.dom.Element domView = doc.createElement("view"); domView.appendChild(doc.createTextNode(viewName)); domElement.appendChild(domView); // properties Properties properties = format.getProperties(); Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if ("view".equals(name)) { continue; } String value = properties.getProperty(name); org.w3c.dom.Element domAttr = doc.createElement(name); domAttr.appendChild(doc.createTextNode(Utils.cleanUp(value))); domElement.appendChild(domAttr); } } // layout else if ("layout".equals(typeName)) { Properties properties = format.getProperties(); Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); String value = properties.getProperty(name); org.w3c.dom.Element domView = doc.createElement(name); domView.appendChild(doc.createTextNode(Utils.cleanUp(value))); domElement.appendChild(domView); } } // style else if ("style".equals(typeName)) { Style style = (Style) format; if (style.isExternal()) { return; } String styleName = style.getName(); Style ancestor = (Style) ThemeManager.getAncestorFormatOf(style); if (styleName != null) { domElement.setAttribute("name", styleName); } if (ancestor != null) { domElement.setAttribute("inherit", ancestor.getName()); } if (style.isRemote()) { domElement.setAttribute("remote", "true"); } if ((!style.isRemote() || style.isCustomized())) { for (String viewName : style.getSelectorViewNames()) { for (String path : style.getPathsForView(viewName)) { Properties styleProperties = style.getPropertiesFor(viewName, path); if (styleProperties.isEmpty()) { continue; } org.w3c.dom.Element domSelector = doc.createElement("selector"); path = Utils.cleanUp(path); domSelector.setAttribute("path", path); if (!"*".equals(viewName)) { domSelector.setAttribute("view", viewName); } for (Map.Entry<Object, Object> entry : styleProperties.entrySet()) { org.w3c.dom.Element domProperty = doc.createElement((String) entry.getKey()); String value = (String) entry.getValue(); String presetName = PresetManager.extractPresetName(null, value); if (presetName != null) { domProperty.setAttribute("preset", presetName); } else { domProperty.appendChild(doc.createTextNode(Utils.cleanUp(value))); } domSelector.appendChild(domProperty); } // Set selector description String selectorDescription = style.getSelectorDescription(path, viewName); if (selectorDescription != null) { domElement.appendChild(doc.createComment(String.format(" %s ", selectorDescription))); } domElement.appendChild(domSelector); } } } } domParent.appendChild(domElement); }
From source file:com.ottogroup.bi.spqr.operator.twitter.source.TwitterStreamSource.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *//*from w ww . ja v a 2 s . co m*/ public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { if (properties == null || properties.isEmpty()) throw new RequiredInputMissingException("Missing required configuration"); ////////////////////////////////////////////////////////// // extract required configurational data this.consumerKey = properties.getProperty(CFG_TWITTER_CONSUMER_KEY); this.consumerSecret = properties.getProperty(CFG_TWITTER_CONSUMER_SECRET); this.tokenKey = properties.getProperty(CFG_TWITTER_TOKEN_KEY); this.tokenSecret = properties.getProperty(CFG_TWITTER_TOKEN_SECRET); String inSearchTerms = properties.getProperty(CFG_TWITTER_TWEET_SEARCH_TERMS); String[] splittedSearchTerms = (inSearchTerms != null ? inSearchTerms.split(",") : null); if (splittedSearchTerms != null) { for (String sst : splittedSearchTerms) { this.searchTerms.add(StringUtils.trim(sst)); } } String inLanguages = properties.getProperty(CFG_TWITTER_TWEET_LANGUAGES); String[] splittedLanguages = (inLanguages != null ? inLanguages.split(",") : null); if (splittedLanguages != null) { for (String s : splittedLanguages) { this.languages.add(StringUtils.trim(s)); } } String inProfiles = properties.getProperty(CFG_TWITTER_PROFILES); String[] splittedProfiles = (inProfiles != null ? inProfiles.split(",") : null); if (splittedProfiles != null) { for (String sp : splittedProfiles) { if (StringUtils.isNotBlank(sp)) { try { this.profiles.add(Long.parseLong(sp.trim())); } catch (Exception e) { logger.error("Failed to parse profile identifier from input '" + sp + "'"); } } } } // ////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // validate provided input before attempting to establish connection with stream.twitter.com if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required component identifier"); if (StringUtils.isBlank(this.consumerKey)) throw new RequiredInputMissingException( "Missing required consumer key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.consumerSecret)) throw new RequiredInputMissingException( "Missing required consumer secrect to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenKey)) throw new RequiredInputMissingException( "Missing required token key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenSecret)) throw new RequiredInputMissingException( "Missing required token secret to establish connection with stream.twitter.com"); boolean isFilterTermsEmpty = (this.searchTerms == null || this.searchTerms.isEmpty()); boolean isLanguagesEmpty = (this.languages == null || this.languages.isEmpty()); boolean isUserAccountEmpty = (this.profiles == null || this.profiles.isEmpty()); boolean isLocationsEmpty = (this.locations == null || this.locations.isEmpty()); if (isFilterTermsEmpty && isLanguagesEmpty && isUserAccountEmpty && isLocationsEmpty) throw new RequiredInputMissingException( "Mishandle sing information what to filter twitter stream for: terms, languages, user accounts or locations"); // //////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // establish connection with stream.twitter.com Authentication auth = new OAuth1(this.consumerKey, this.consumerSecret, this.tokenKey, this.tokenSecret); StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint(); if (!isFilterTermsEmpty) filterEndpoint.trackTerms(searchTerms); if (!isLanguagesEmpty) filterEndpoint.languages(languages); if (!isUserAccountEmpty) filterEndpoint.followings(profiles); if (!isLocationsEmpty) filterEndpoint.locations(locations); if (this.twitterClient == null) { this.twitterClient = new ClientBuilder().name(id).hosts(Constants.STREAM_HOST).endpoint(filterEndpoint) .authentication(auth).processor(new StringDelimitedProcessor(streamMessageQueue)) .eventMessageQueue(eventMessageQueue).build(); this.twitterClient.connect(); } // ////////////////////////////////////////////////////////// this.running = true; if (logger.isDebugEnabled()) logger.debug("twitter stream consumer initialized [id=" + id + "]"); }
From source file:net.ymate.platform.configuration.provider.impl.JConfigProvider.java
public List<String> getList(String key) { List<String> valueList = new ArrayList<String>(); String[] keys = StringUtils.split(key, IConfiguration.CFG_KEY_SEPERATE); int keysSize = keys.length; Properties properties = null; if (keysSize == 1) { properties = config.getProperties(); } else if (keysSize == 2) { properties = config.getProperties(keys[0]); }// www .java 2 s .c om if (properties != null && !properties.isEmpty()) { for (Object name : properties.keySet()) { if (name != null && name.toString().startsWith(keysSize == 1 ? keys[0] : keys[1])) { // key Object value = properties.get(name); valueList.add(value == null ? "" : value.toString()); } } } return valueList; }
From source file:org.apache.synapse.commons.datasource.JNDIBasedDataSourceRepository.java
private InitialContext createInitialContext(Properties jndiEnv) { if (jndiEnv == null || jndiEnv.isEmpty()) { return null; }//w ww.java 2 s . c o m try { if (log.isDebugEnabled()) { log.debug("Initiating a Naming context with JNDI " + "environment jndiProperties : " + jndiEnv); } return new InitialContext(jndiEnv); } catch (NamingException e) { throw new SynapseCommonsException( "Error creating a InitialContext" + " with JNDI env jndiProperties : " + jndiEnv, log); } }
From source file:org.apache.geode.internal.util.CollectionUtilsJUnitTest.java
@Test public void testCreateEmptyProperties() { Properties properties = CollectionUtils.createProperties(null); assertNotNull(properties);/*from w ww.ja va 2 s. c o m*/ assertTrue(properties.isEmpty()); }
From source file:org.tolven.assembler.tomcatserver.TomcatServerXMLAssembler.java
protected void addConnectorTemplate(Extension connectorExtension, File webserverCredentialDir, File webserverDeploymentDir, XMLStreamWriter xmlStreamWriter) throws XMLStreamException, IOException { Properties props = getConnectorProperties(connectorExtension, webserverCredentialDir, webserverDeploymentDir);//from www . j a v a 2 s .c o m if (!props.isEmpty()) { List<Object> objs = new ArrayList<Object>(); objs.addAll(props.keySet()); Comparator<Object> comparator = new Comparator<Object>() { public int compare(Object obj1, Object obj2) { return (obj1.toString().compareTo(obj2.toString())); }; }; Collections.sort(objs, comparator); xmlStreamWriter.writeStartElement("Connector"); for (Object obj : objs) { String key = (String) obj; xmlStreamWriter.writeAttribute(key, props.getProperty(key)); } xmlStreamWriter.writeEndElement(); } }