List of usage examples for java.util Properties size
@Override public int size()
From source file:org.alfresco.reporting.action.executer.ReportContainerExecuter.java
/** * Execute the single report//from w w w .j a v a 2s.c o m * * @param reportRef * the actual report * @param targetDocumentRef * the new documnt to store the report into * @param outputType * the type of report to generate (pdf or Excel) */ private void executeReportExecuter(final ReportTemplate report, final NodeRef targetDocumentRef, final Properties keyValues) { if (logger.isDebugEnabled()) { logger.debug("enter executeReportExecuter"); logger.debug(" reportRef : " + report.getNodeRef()); logger.debug(" reportName : " + report.getName()); logger.debug(" targetDocumentRef: " + targetDocumentRef); logger.debug(" outputType : " + report.getOutputFormat()); logger.debug(" parameters : " + keyValues); } Action action = actionService.createAction(ReportExecuter.NAME); action.setParameterValue(ReportExecuter.OUTPUT_TYPE, report.getOutputFormat()); action.setParameterValue(ReportExecuter.TARGET_DOCUMENT, targetDocumentRef); if (keyValues.size() > 0) { action.setParameterValue(ReportExecuter.SEPARATOR, Constants.SEPARATOR); Enumeration keys = keyValues.keys(); // Properties namespaces = // reportingHelper.getNameSpacesShortToLong(); /* * Collection<String> nameSpaceKeys = namespaceService.getURIs(); * for (String myKey:nameSpaceKeys){ String myValue = * namespaceService.getNamespaceURI(myKey); logger.debug( * "Found value: "+ myValue+" namespacekey: " + myKey); } */ int i = 0; while (keys.hasMoreElements()) { i++; String key = (String) keys.nextElement(); String pushString = key + Constants.SEPARATOR + keyValues.getProperty(key, ""); if (logger.isDebugEnabled()) logger.debug("Setting report parameter " + key + " = " + keyValues.getProperty(key, "")); if (i == 1) action.setParameterValue(ReportExecuter.PARAM_1, pushString); if (i == 2) action.setParameterValue(ReportExecuter.PARAM_2, pushString); if (i == 3) action.setParameterValue(ReportExecuter.PARAM_3, pushString); if (i == 4) action.setParameterValue(ReportExecuter.PARAM_4, pushString); } // end while key.hasMoreElements } actionService.executeAction(action, report.getNodeRef()); if (logger.isDebugEnabled()) logger.debug("Exit executeReportExecuter"); }
From source file:org.apache.directory.fortress.core.ldap.ApacheDsDataProvider.java
/** * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap modification set in preparation for ldap add. * * @param props contains {@link java.util.Properties} targeted for adding to ldap. * @param entry contains ldap entry to push attrs into. * @param attrName contains the name of the ldap attribute to be added. * @param separator contains the char value used to separate name and value in ldap raw format. * @throws LdapException//w w w.j a v a 2 s . com */ protected void loadProperties(Properties props, Entry entry, String attrName, char separator) throws LdapException { if (props != null && props.size() > 0) { Attribute attr = null; for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { // This LDAP attr is stored as a name-value pair separated by a ':'. String key = (String) e.nextElement(); String val = props.getProperty(key); String prop = key + separator + val; if (attr == null) { attr = new DefaultAttribute(attrName); } else { attr.add(prop); } } if (attr != null) { entry.add(attr); } } }
From source file:org.jahia.services.usermanager.ldap.LDAPUserGroupProvider.java
@Override public List<String> searchUsers(final Properties searchCriteria, long offset, long limit) { if (searchCriteria.containsKey("username") && searchCriteria.size() == 1 && !searchCriteria.getProperty("username").contains("*")) { try {/*from ww w. j a v a 2 s . c o m*/ JahiaUser user = getUser((String) searchCriteria.get("username")); return Arrays.asList(user.getUsername()); } catch (UserNotFoundException e) { return Collections.emptyList(); } } final ContainerCriteria query = buildUserQuery(searchCriteria); if (query == null) { return Collections.emptyList(); } final UsersNameClassPairCallbackHandler searchNameClassPairCallbackHandler = new UsersNameClassPairCallbackHandler(); long currentTimeMillis = System.currentTimeMillis(); ldapTemplateWrapper.execute(new BaseLdapActionCallback<Object>(externalUserGroupService, key) { @Override public Object doInLdap(LdapTemplate ldapTemplate) { ldapTemplate.search(query, searchNameClassPairCallbackHandler); return null; } }); logger.debug("Search users for {} in {} ms", searchCriteria, System.currentTimeMillis() - currentTimeMillis); ArrayList<String> l = new ArrayList<String>(searchNameClassPairCallbackHandler.getNames()); return l.subList(Math.min((int) offset, l.size()), limit < 0 ? l.size() : Math.min((int) (offset + limit), l.size())); }
From source file:org.apache.directory.fortress.core.ldap.ApacheDsDataProvider.java
/** * Given a collection of {@link java.util.Properties}, convert to raw data name-value format and load into ldap * modification set in preparation for ldap modify. * * @param props contains {@link java.util.Properties} targeted for updating in ldap. * @param mods ldap modification set containing name-value pairs in raw ldap format. * @param attrName contains the name of the ldap attribute to be updated. * @param replace boolean variable, if set to true use {@link ModificationOperation#REPLACE_ATTRIBUTE} else {@link * ModificationOperation#ADD_ATTRIBUTE}. * @param separator contains the char value used to separate name and value in ldap raw format. *///from www . ja v a 2 s . c om protected void loadProperties(Properties props, List<Modification> mods, String attrName, boolean replace, char separator) { if (props != null && props.size() > 0) { if (replace) { mods.add(new DefaultModification(ModificationOperation.REPLACE_ATTRIBUTE, attrName)); } for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String val = props.getProperty(key); // This LDAP attr is stored as a name-value pair separated by a ':'. mods.add(new DefaultModification(ModificationOperation.ADD_ATTRIBUTE, attrName, key + separator + val)); } } }
From source file:com.legstar.mq.client.AbstractCicsMQ.java
/** * Given the endpoint parameters, setup a JNDI context to lookup JMS * resources./*from w w w . j a v a 2s . c om*/ * * @param cicsMQEndpoint the endpoint paramers * @return the JNDI context * @throws CicsMQConnectionException if JNDI context cannot be created */ protected Context createJndiContext(final CicsMQEndpoint cicsMQEndpoint) throws CicsMQConnectionException { try { Properties env = new Properties(); if (cicsMQEndpoint.getInitialContextFactory() != null && cicsMQEndpoint.getInitialContextFactory().length() > 0) { env.put(Context.INITIAL_CONTEXT_FACTORY, cicsMQEndpoint.getInitialContextFactory()); } if (cicsMQEndpoint.getJndiProviderURL() != null && cicsMQEndpoint.getJndiProviderURL().length() > 0) { env.put(Context.PROVIDER_URL, cicsMQEndpoint.getJndiProviderURL()); } if (cicsMQEndpoint.getJndiUrlPkgPrefixes() != null && cicsMQEndpoint.getJndiUrlPkgPrefixes().length() > 0) { env.put(Context.URL_PKG_PREFIXES, cicsMQEndpoint.getJndiUrlPkgPrefixes()); } if (cicsMQEndpoint.getJndiProperties() != null) { env.putAll(getProperties(cicsMQEndpoint.getJndiProperties())); } if (env.size() > 0) { return new InitialContext(env); } else { return new InitialContext(); } } catch (NamingException e) { throw new CicsMQConnectionException(e); } }
From source file:org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.java
protected Transformer addStylesheet(Source source, URIResolver resolver, Map parameters, Properties outputProperties) throws TransformerConfigurationException { if (tFactory == null) createTransformerFactory();// w w w . j av a 2 s .co m TransformerHandler newTh = tFactory.newTransformerHandler(source); Transformer transformer = newTh.getTransformer(); if (resolver != null) transformer.setURIResolver(resolver); if (parameters != null) { for (Iterator iter = parameters.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); String name = (String) entry.getKey(); Object value = entry.getValue(); log.info(Messages.getString("JAXPSAXProcessorInvoker.2") + name //$NON-NLS-1$ + Messages.getString("JAXPSAXProcessorInvoker.3") + value); //$NON-NLS-1$ transformer.setParameter(name, value); } } if (outputProperties != null) { StringBuffer sb = new StringBuffer(); for (Iterator iter = outputProperties.entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); sb.append(entry.getKey()).append("=").append(entry.getValue()).append(" "); //$NON-NLS-1$ //$NON-NLS-2$ } if (outputProperties.size() > 0) { log.info(Messages.getString("JAXPSAXProcessorInvoker.6") + sb.toString()); //$NON-NLS-1$ transformer.setOutputProperties(outputProperties); } } if (th != null) th.setResult(new SAXResult(newTh)); else { reader.setContentHandler(newTh); try { reader.setProperty("http://xml.org/sax/properties/lexical-handler", newTh); //$NON-NLS-1$ } catch (SAXNotRecognizedException ex) { log.warn(Messages.getString("JAXPSAXProcessorInvoker_4")); //$NON-NLS-1$ } catch (SAXNotSupportedException e) { log.warn(Messages.getString("JAXPSAXProcessorInvoker_5")); //$NON-NLS-1$ } } th = newTh; return th.getTransformer(); }
From source file:org.apache.struts.util.PropertyMessageResources.java
/** * Load the messages associated with the specified Locale key. For this * implementation, the <code>config</code> property should contain a fully * qualified package and resource name, separated by periods, of a series * of property resources to be loaded from the class loader that created * this PropertyMessageResources instance. This is exactly the same name * format you would use when utilizing the <code>java.util.PropertyResourceBundle</code> * class.//www . j a v a 2 s . c o m * * @param localeKey Locale key for the messages to be retrieved */ protected synchronized void loadLocale(String localeKey) { if (log.isTraceEnabled()) { log.trace("loadLocale(" + localeKey + ")"); } // Have we already attempted to load messages for this locale? if (locales.get(localeKey) != null) { return; } locales.put(localeKey, localeKey); // Set up to load the property resource for this locale key, if we can String name = config.replace('.', '/'); if (localeKey.length() > 0) { name += ("_" + localeKey); } name += ".properties"; InputStream is = null; Properties props = new Properties(); // Load the specified property resource if (log.isTraceEnabled()) { log.trace(" Loading resource '" + name + "'"); } ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } is = classLoader.getResourceAsStream(name); if (is != null) { try { props.load(is); } catch (IOException e) { log.error("loadLocale()", e); } finally { try { is.close(); } catch (IOException e) { log.error("loadLocale()", e); } } if (log.isTraceEnabled()) { log.trace(" Loading resource completed"); } } else { if (log.isWarnEnabled()) { log.warn(" Resource " + name + " Not Found."); } } // Copy the corresponding values into our cache if (props.size() < 1) { return; } synchronized (messages) { Iterator names = props.keySet().iterator(); while (names.hasNext()) { String key = (String) names.next(); if (log.isTraceEnabled()) { log.trace(" Saving message key '" + messageKey(localeKey, key)); } messages.put(messageKey(localeKey, key), props.getProperty(key)); } } }
From source file:SftpClientFactory.java
/** * Creates a new connection to the server. * @param hostname The name of the host to connect to. * @param port The port to use./*from w ww . j a va2s.c o m*/ * @param username The user's id. * @param password The user's password. * @param fileSystemOptions The FileSystem options. * @return A Session. * @throws FileSystemException if an error occurs. */ public static Session createConnection(String hostname, int port, char[] username, char[] password, FileSystemOptions fileSystemOptions) throws FileSystemException { JSch jsch = new JSch(); File sshDir = null; // new style - user passed File knownHostsFile = SftpFileSystemConfigBuilder.getInstance().getKnownHosts(fileSystemOptions); File[] identities = SftpFileSystemConfigBuilder.getInstance().getIdentities(fileSystemOptions); if (knownHostsFile != null) { try { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); } catch (JSchException e) { throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e); } } else { sshDir = findSshDir(); // Load the known hosts file knownHostsFile = new File(sshDir, "known_hosts"); if (knownHostsFile.isFile() && knownHostsFile.canRead()) { try { jsch.setKnownHosts(knownHostsFile.getAbsolutePath()); } catch (JSchException e) { throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e); } } } if (identities != null) { for (int iterIdentities = 0; iterIdentities < identities.length; iterIdentities++) { final File privateKeyFile = identities[iterIdentities]; try { jsch.addIdentity(privateKeyFile.getAbsolutePath()); } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e); } } } else { if (sshDir == null) { sshDir = findSshDir(); } // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { try { jsch.addIdentity(privateKeyFile.getAbsolutePath()); } catch (final JSchException e) { throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e); } } } Session session; try { session = jsch.getSession(new String(username), hostname, port); if (password != null) { session.setPassword(new String(password)); } Integer timeout = SftpFileSystemConfigBuilder.getInstance().getTimeout(fileSystemOptions); if (timeout != null) { session.setTimeout(timeout.intValue()); } UserInfo userInfo = SftpFileSystemConfigBuilder.getInstance().getUserInfo(fileSystemOptions); if (userInfo != null) { session.setUserInfo(userInfo); } Properties config = new Properties(); //set StrictHostKeyChecking property String strictHostKeyChecking = SftpFileSystemConfigBuilder.getInstance() .getStrictHostKeyChecking(fileSystemOptions); if (strictHostKeyChecking != null) { config.setProperty("StrictHostKeyChecking", strictHostKeyChecking); } //set PreferredAuthentications property String preferredAuthentications = SftpFileSystemConfigBuilder.getInstance() .getPreferredAuthentications(fileSystemOptions); if (preferredAuthentications != null) { config.setProperty("PreferredAuthentications", preferredAuthentications); } //set compression property String compression = SftpFileSystemConfigBuilder.getInstance().getCompression(fileSystemOptions); if (compression != null) { config.setProperty("compression.s2c", compression); config.setProperty("compression.c2s", compression); } String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions); if (proxyHost != null) { int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions); SftpFileSystemConfigBuilder.ProxyType proxyType = SftpFileSystemConfigBuilder.getInstance() .getProxyType(fileSystemOptions); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { if (proxyPort != 0) { proxy = new ProxyHTTP(proxyHost, proxyPort); } else { proxy = new ProxyHTTP(proxyHost); } } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { if (proxyPort != 0) { proxy = new ProxySOCKS5(proxyHost, proxyPort); } else { proxy = new ProxySOCKS5(proxyHost); } } if (proxy != null) { session.setProxy(proxy); } } //set properties for the session if (config.size() > 0) { session.setConfig(config); } session.setDaemonThread(true); session.connect(); } catch (final Exception exc) { throw new FileSystemException("vfs.provider.sftp/connect.error", new Object[] { hostname }, exc); } return session; }
From source file:org.opencastproject.capture.impl.CaptureAgentImpl.java
/** * {@inheritDoc}//from w w w . ja va 2 s . c om * * @see org.opencastproject.capture.api.CaptureAgent#getDefaultAgentPropertiesAsString() */ @Deprecated public String getDefaultAgentPropertiesAsString() { Properties p = configService.getAllProperties(); StringBuffer result = new StringBuffer(); String[] lines = new String[p.size()]; int i = 0; for (Object k : p.keySet()) { String key = (String) k; lines[i++] = key + "=" + p.getProperty(key) + "\n"; } Arrays.sort(lines); for (String s : lines) { result.append(s); } return result.toString(); }
From source file:org.lockss.hasher.TestBlockHasher.java
License:asdf
public void testOneContentThreeVersionsLocalHashGood(int stepSize) throws Exception { enableLocalHash("SHA-1", "SHA-1"); CaptureBlocksEventHandler blockHandler = new CaptureBlocksEventHandler(); MockArchivalUnit mau = setupContentTree(); MockCachedUrlSet cus = (MockCachedUrlSet) mau.getAuCachedUrlSet(); // Adding versions, from least recent to most recent. addVersionAndChecksum(mau, urls[2], "aaaa", "SHA-1:70c881d4a26984ddce795f6f71817c9cf4480e79"); addVersionAndChecksum(mau, urls[2], "bb", "SHA-1:9a900f538965a426994e1e90600920aff0b4e8d2"); addVersionAndChecksum(mau, urls[2], "ccc", "SHA-1:f36b4825e5db2cf7dd2d2593b3f5c24c0311d8b2"); if (log.isDebug3()) { for (CachedUrl cu : cus.getCuIterable()) { CachedUrl[] vers = cu.getCuVersions(); log.debug3(cu.getUrl() + " has " + vers.length + " versions."); for (int i = 0; i < vers.length; i++) { Properties vProps = vers[i].getProperties(); log.debug3("Version: " + i + " has " + vProps.size() + " entries"); for (Iterator it2 = vProps.keySet().iterator(); it2.hasNext();) { String key = (String) it2.next(); log.debug("Version: " + i + " key: " + key + " val: " + vProps.get(key)); }/*from w w w . j av a 2 s. c om*/ } } } MessageDigest[] digs = { dig }; byte[][] inits = { null }; BlockHasher hasher = new MyBlockHasher(cus, digs, inits, blockHandler); hasher.setFiltered(false); // 9 bytes total for all three versions. assertEquals(9, hashToEnd(hasher, stepSize)); assertTrue(hasher.finished()); List blocks = blockHandler.getBlocks(); assertEquals(1, blocks.size()); HashBlock b = (HashBlock) blocks.get(0); assertEquals(3, b.size()); HashBlock.Version[] versions = b.getVersions(); assertEqualBytes(bytes("ccc"), versions[0].getHashes()); assertEqualBytes(bytes("bb"), versions[1].getHashes()); assertEqualBytes(bytes("aaaa"), versions[2].getHashes()); LocalHashResult lhr = hasher.getLocalHashResult(); assertEquals(3, lhr.getMatchingVersions()); assertEquals(0, lhr.getNewlySuspectVersions()); assertEquals(0, lhr.getNewlyHashedVersions()); assertEquals(1, lhr.getMatchingUrls()); assertEquals(0, lhr.getNewlySuspectUrls()); assertEquals(0, lhr.getNewlyHashedUrls()); }