List of usage examples for java.util Hashtable isEmpty
public synchronized boolean isEmpty()
From source file:it.greenvulcano.util.txt.TextUtils.java
/** * @param input//from w ww. j a va 2 s .c o m * @param phPrefix * @param phSuffix * @param phValues * @return the string with placeholders replaced * */ public static String replacePlaceholder(String input, String phPrefix, String phSuffix, Hashtable<String, String> phValues) { if (input == null) { return null; } if (input.equals("")) { return ""; } if (phValues == null) { return input; } if (phValues.isEmpty()) { return input; } if ((phPrefix == null) || (phSuffix == null)) { return input; } if ((phPrefix.equals("")) || (phSuffix.equals(""))) { return input; } int phPlen = phPrefix.length(); int phSlen = phSuffix.length(); int startNextToken = 0; int endNextToken = 0; int maxPosition = input.length(); StringBuilder buf = new StringBuilder(""); while (startNextToken < maxPosition) { endNextToken = input.indexOf(phPrefix, startNextToken); if (endNextToken != -1) { String currToken = input.substring(startNextToken, endNextToken); int endPH = input.indexOf(phSuffix, endNextToken + phPlen); String phName = input.substring(endNextToken + phPlen, endPH); String replacement = phPrefix + phName + phSuffix; Object phValue = phValues.get(phName); if (phValue != null) { replacement = StringEscapeUtils.unescapeJava(phValue.toString()); } if (currToken.length() > 0) { buf.append(currToken).append(replacement); } else { buf.append(replacement); } startNextToken = endPH + phSlen; } else { String currToken = input.substring(startNextToken); buf.append(currToken); startNextToken = maxPosition; } } return buf.toString(); }
From source file:org.wso2.carbon.rssmanager.core.util.RSSManagerUtil.java
/** * Do jndi look up of data source/*from w w w . j a v a 2 s .co m*/ * * @param dataSourceName data source name * @param jndiProperties jndi properties * @return DataSource */ public static DataSource lookupDataSource(String dataSourceName, final Hashtable<Object, Object> jndiProperties) { try { if (jndiProperties == null || jndiProperties.isEmpty()) { return (DataSource) InitialContext.doLookup(dataSourceName); } final InitialContext context = new InitialContext(jndiProperties); return (DataSource) context.doLookup(dataSourceName); } catch (Exception e) { throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); } }
From source file:eionet.gdem.utils.Utils.java
/** * Is Null or empty hash table/* w w w.j a v a2 s.c o m*/ * @param h hash table * @return True if Null or empty hash table */ public static boolean isNullHashtable(Hashtable h) { if (h == null) { return true; } else if (h.isEmpty()) { return true; } return false; }
From source file:org.globus.workspace.network.defaults.DefaultAssociationAdapter.java
public String[] getAssociationNames() throws ManageException { final Hashtable associations = this.persistence.currentAssociations(false); if (associations == null || associations.isEmpty()) { return zeroLen; } else {//from w w w .ja v a 2 s .co m final Set keys = associations.keySet(); return (String[]) keys.toArray(new String[keys.size()]); } }
From source file:com.alfaariss.oa.engine.attribute.gather.processor.file.FileGatherer.java
/** * Gathers attributes from file./* w w w . j a v a2 s . com*/ * * First adds the optionaly configured global attributes then updates with * the specific user attributes. * @see com.alfaariss.oa.engine.core.attribute.gather.processor.IProcessor#process(java.lang.String, com.alfaariss.oa.api.attribute.IAttributes) */ public void process(String id, IAttributes attributes) throws AttributeException { if (attributes == null) throw new IllegalArgumentException("Suplied attributes parameter is empty"); try { ConfigurationManager fileConfig = getConfiguration(); Enumeration enumGlobal = _htGlobal.elements(); while (enumGlobal.hasMoreElements()) { FileAttribute fAttr = (FileAttribute) enumGlobal.nextElement(); String sName = fAttr.getName(); List<?> listValues = fAttr.getValues(); String sMappedName = _htMapper.get(sName); if (sMappedName != null) sName = sMappedName; if (_listGather.isEmpty() || _listGather.contains(sName)) { if (listValues.size() > 1) attributes.put(sName, fAttr.getFormat(), listValues); else attributes.put(sName, fAttr.getFormat(), listValues.get(0)); } } Element eUser = fileConfig.getSection(null, "user", "id=" + id); if (eUser != null) { Hashtable htAttributes = getFileAttributes(fileConfig, eUser); if (!htAttributes.isEmpty()) { Enumeration enumAttributes = htAttributes.elements(); while (enumAttributes.hasMoreElements()) { FileAttribute fAttr = (FileAttribute) enumAttributes.nextElement(); String sName = fAttr.getName(); List<?> listValues = fAttr.getValues(); String sMappedName = _htMapper.get(sName); if (sMappedName != null) sName = sMappedName; if (_listGather.isEmpty() || _listGather.contains(sName)) { if (listValues.size() > 1) attributes.put(sName, fAttr.getFormat(), listValues); else attributes.put(sName, fAttr.getFormat(), listValues.get(0)); } } } else _logger.debug("No user specific attributes found"); } else _logger.debug("No user found in attributes file"); } catch (AttributeException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during attribute processing", e); throw new AttributeException(SystemErrors.ERROR_INTERNAL); } }
From source file:org.asimba.engine.attribute.gather.processor.file.AsimbaUsersXmlGatherer.java
public void process(String sUserId, IAttributes oAttributes) throws AttributeException { if (oAttributes == null) throw new IllegalArgumentException("IAttributes was not provided"); try {/* w ww . j a v a 2 s .c o m*/ ConfigurationManager oCM = getConfiguration(); // First, process global attributes Enumeration<FileAttribute> oEnumGlobal = _htGlobal.elements(); while (oEnumGlobal.hasMoreElements()) { FileAttribute fAttr = oEnumGlobal.nextElement(); String sName = fAttr.getName(); List<?> listValues = fAttr.getValues(); String sMappedName = _htMapper.get(sName); if (sMappedName != null) sName = sMappedName; if (_listGather.isEmpty() || _listGather.contains(sName)) { // Ignore multi-value, only return the first value if (listValues.size() > 1) oAttributes.put(sName, fAttr.getFormat(), listValues); else oAttributes.put(sName, fAttr.getFormat(), listValues.get(0)); } } Element elUser = oCM.getSection(null, "user", "id=" + sUserId); if (elUser != null) { Hashtable<String, FileAttribute> htAttributes = getFileAttributes(oCM, elUser); if (!htAttributes.isEmpty()) { Enumeration<FileAttribute> enumAttributes = htAttributes.elements(); while (enumAttributes.hasMoreElements()) { FileAttribute fAttr = enumAttributes.nextElement(); String sName = fAttr.getName(); List<?> listValues = fAttr.getValues(); String sMappedName = _htMapper.get(sName); if (sMappedName != null) sName = sMappedName; if (_listGather.isEmpty() || _listGather.contains(sName)) { // Ignore multi-value, only return the first value if (listValues.size() > 1) oAttributes.put(sName, fAttr.getFormat(), listValues); else oAttributes.put(sName, fAttr.getFormat(), listValues.get(0)); } } } else _oLogger.debug("No user specific attributes found"); } else _oLogger.debug("No user found in attributes file"); } catch (AttributeException e) { throw e; } catch (Exception e) { _oLogger.fatal("Internal error during attribute processing", e); throw new AttributeException(SystemErrors.ERROR_INTERNAL); } }
From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928MigrationTest.java
/** * DOCUMENT ME!/*from www . jav a 2 s. c o m*/ * * @throws Exception DOCUMENT ME! */ public void testMissingField() throws Exception { MigrationManager um = MigrationManager.getInstance(); Enumeration enumeration = um.start(FR2422928.class, null); try { while (enumeration.hasMoreElements()) { Hashtable data = (Hashtable) enumeration.nextElement(); assertFalse("Should not be empty!", data.isEmpty()); assertEquals(new Long(id), (Long) data.get("id")); } } finally { um.finish(FR2422928.class); } }
From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928MigrationTest.java
/** * DOCUMENT ME!/*w w w . j a va 2 s . c o m*/ * * @throws Exception DOCUMENT ME! */ public void testNewField() throws Exception { MigrationManager um = MigrationManager.getInstance(); Enumeration enumeration = um.start(FR2422928.class, null); try { while (enumeration.hasMoreElements()) { Hashtable data = (Hashtable) enumeration.nextElement(); assertFalse("Should not be empty!", data.isEmpty()); assertNull(data.get("node")); } } finally { um.finish(FR2422928.class); } }
From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928MigrationTest.java
/** * DOCUMENT ME!//from w ww . j av a 2 s . c om * * @throws Exception DOCUMENT ME! */ public void testRemaingField() throws Exception { MigrationManager um = MigrationManager.getInstance(); Enumeration enumeration = um.start(FR2422928.class, null); try { while (enumeration.hasMoreElements()) { Hashtable data = (Hashtable) enumeration.nextElement(); assertFalse("Should not be empty!", data.isEmpty()); assertEquals(name, (String) data.get("name")); assertEquals(checkpoint, data.get("checkpoint")); } } finally { um.finish(FR2422928.class); } }
From source file:net.sourceforge.floggy.persistence.fr2422928.FR2422928MigrationTest.java
/** * DOCUMENT ME!// www . ja va 2 s . c om * * @throws Exception DOCUMENT ME! */ public void testAfterUpddate() throws Exception { MigrationManager um = MigrationManager.getInstance(); Enumeration enumeration = um.start(FR2422928.class, null); PersistableMetadata metadata = PersistableMetadataManager.getRMSBasedMetadata(FR2422928.class.getName()); assertEquals(PersistableMetadataManager.VERSION_1_3_0, metadata.getRecordStoreVersion()); try { while (enumeration.hasMoreElements()) { Hashtable data = (Hashtable) enumeration.nextElement(); assertFalse("Should not be empty!", data.isEmpty()); assertEquals(name, data.get("name")); assertEquals(checkpoint, data.get("checkpoint")); FR2422928 persistable = new FR2422928(); persistable.setName((String) data.get("name")); persistable.setCheckpoint((Calendar) data.get("checkpoint")); enumeration.update(persistable); } } finally { um.finish(FR2422928.class); } metadata = PersistableMetadataManager.getRMSBasedMetadata(FR2422928.class.getName()); assertEquals(PersistableMetadataManager.getBytecodeVersion(), metadata.getRecordStoreVersion()); try { ObjectSet os = manager.find(FR2422928.class, null, null); assertEquals(1, os.size()); FR2422928 persistable = (FR2422928) os.get(0); assertEquals(name, persistable.getName()); assertEquals(checkpoint, persistable.getCheckpoint()); } catch (Exception ex) { fail(ex.getMessage()); } }