List of usage examples for org.apache.commons.lang ArrayUtils toString
public static String toString(Object array)
Outputs an array as a String, treating null
as an empty array.
From source file:org.netxilia.spi.impl.storage.db.sql.DefaultConnectionWrapper.java
public <T> List<T> query(String sql, RowMapper<T> rowMapper, Object... params) { PreparedStatement st = null;// w w w. j a v a 2 s .com ResultSet rs = null; if (log.isDebugEnabled()) { log.debug("QUERY:" + sql + " with " + ArrayUtils.toString(params)); } try { st = connection.prepareStatement(sql); for (int i = 0; i < params.length; ++i) { st.setObject(i + 1, params[i]); } rs = st.executeQuery(); return new RowMapperResultSetExtractor<T>(rowMapper).extractData(rs); } catch (SQLException e) { throw new StorageException(e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { // silent } } if (st != null) { try { st.close(); } catch (SQLException e) { // silent } } } }
From source file:org.netxilia.spi.impl.storage.db.sql.DefaultConnectionWrapper.java
public int queryForInt(String sql, Object... params) { PreparedStatement st = null;// w w w .j ava2 s .co m ResultSet rs = null; if (log.isDebugEnabled()) { log.debug("QUERY INT:" + sql + " with " + ArrayUtils.toString(params)); } try { st = connection.prepareStatement(sql); for (int i = 0; i < params.length; ++i) { st.setObject(i + 1, params[i]); } rs = st.executeQuery(); if (rs.next()) { return rs.getInt(1); } return 0; } catch (SQLException e) { throw new StorageException(e); } finally { if (rs != null) { try { rs.close(); } catch (SQLException e) { // silent } } if (st != null) { try { st.close(); } catch (SQLException e) { // silent } } } }
From source file:org.netxilia.spi.impl.storage.db.sql.DefaultConnectionWrapper.java
public int update(String sql, Object... params) { PreparedStatement st = null;/*from w w w . j a v a 2 s .co m*/ long t1 = System.currentTimeMillis(); try { st = connection.prepareStatement(sql); for (int i = 0; i < params.length; ++i) { st.setObject(i + 1, params[i]); } return st.executeUpdate(); } catch (SQLException e) { throw new StorageException(e); } finally { if (st != null) { try { st.close(); } catch (SQLException e) { // silent } } long t2 = System.currentTimeMillis(); if (log.isDebugEnabled()) { log.debug("UPDATE:" + sql + " with " + ArrayUtils.toString(params) + " update:" + (t2 - t1)); } } }
From source file:org.ngrinder.sm.SecurityManagerTest.java
@Test public void testAllowedNetworkAccess() throws UnknownHostException { ArrayUtils.toString(Inet4Address.getAllByName("10.34.64.36")); }
From source file:org.nuxeo.launcher.connect.ConnectBroker.java
/** * @param packages List of packages identified by their ID, name or local filename. * @since 5.7/*w ww.j av a2 s .c om*/ */ public boolean pkgShow(List<String> packages) { boolean cmdOk = true; if (packages == null || packages.isEmpty()) { return cmdOk; } StringBuilder sb = new StringBuilder(); sb.append("****************************************"); for (String pkg : packages) { CommandInfo cmdInfo = cset.newCommandInfo(CommandInfo.CMD_SHOW); cmdInfo.param = pkg; try { PackageInfo packageInfo = newPackageInfo(cmdInfo, findPackage(pkg)); sb.append("\nPackage: " + packageInfo.id); sb.append("\nState: " + packageInfo.state); sb.append("\nVersion: " + packageInfo.version); sb.append("\nName: " + packageInfo.name); sb.append("\nType: " + packageInfo.type); sb.append("\nVisibility: " + packageInfo.visibility); if (packageInfo.state == PackageState.REMOTE && packageInfo.type != PackageType.STUDIO && packageInfo.visibility != PackageVisibility.PUBLIC && !LogicalInstanceIdentifier.isRegistered()) { sb.append(" (registration required)"); } sb.append("\nTarget platforms: " + ArrayUtils.toString(packageInfo.targetPlatforms)); appendIfNotEmpty(sb, "\nVendor: ", packageInfo.vendor); sb.append("\nSupports hot-reload: " + packageInfo.supportsHotReload); sb.append("\nSupported: " + packageInfo.supported); sb.append("\nProduction state: " + packageInfo.productionState); sb.append("\nValidation state: " + packageInfo.validationState); appendIfNotEmpty(sb, "\nProvides: ", packageInfo.provides); appendIfNotEmpty(sb, "\nDepends: ", packageInfo.dependencies); appendIfNotEmpty(sb, "\nConflicts: ", packageInfo.conflicts); appendIfNotEmpty(sb, "\nTitle: ", packageInfo.title); appendIfNotEmpty(sb, "\nDescription: ", packageInfo.description); appendIfNotEmpty(sb, "\nHomepage: ", packageInfo.homePage); appendIfNotEmpty(sb, "\nLicense: ", packageInfo.licenseType); appendIfNotEmpty(sb, "\nLicense URL: ", packageInfo.licenseUrl); sb.append("\n****************************************"); } catch (PackageException e) { cmdOk = false; cmdInfo.exitCode = 1; cmdInfo.newMessage(e); } } log.info(sb.toString()); return cmdOk; }
From source file:org.nuxeo.launcher.connect.ConnectBroker.java
private void appendIfNotEmpty(StringBuilder sb, String label, Object[] array) { if (ArrayUtils.isNotEmpty(array)) { sb.append(label + ArrayUtils.toString(array)); }// www . j a v a2s . c o m }
From source file:org.nuxeo.launcher.NuxeoLauncher.java
private void extractCommandAndParams(String[] args) { if (args.length > 0) { command = args[0];/*from www . j a v a2s . c o m*/ log.debug("Launcher command: " + command); // Command parameters if (args.length > 1) { params = Arrays.copyOfRange(args, 1, args.length); if (log.isDebugEnabled()) { log.debug("Command parameters: " + ArrayUtils.toString(params)); } } else { params = new String[0]; } } else { command = null; } }
From source file:org.olat.core.commons.contextHelp.ContextHelpMainController.java
/** * Constructor for the context help display. * /*from w ww . ja v a 2 s. c o m*/ * @param ureq * @param control */ public ContextHelpMainController(UserRequest ureq, WindowControl control) { super(ureq, control); String[] uriParts = ureq.getNonParsedUri().split("/"); String lang = null; // get lang and set locale for help page accordingly lang = uriParts[0]; Locale newLocale = I18nManager.getInstance().getLocaleOrNull(lang); if (newLocale == null || !I18nModule.getEnabledLanguageKeys().contains(newLocale.toString())) { newLocale = I18nModule.getDefaultLocale(); } if (!getLocale().toString().equals(newLocale.toString())) { setLocale(newLocale, true); } // Create bread crumb navigation breadCrumbLayoutCtr = new BreadCrumbController(ureq, control); listenTo(breadCrumbLayoutCtr); // Add translation tool start controller to bread crumb startCtr = new ContextHelpTOCCrumbController(ureq, control, newLocale); listenTo(startCtr); breadCrumbLayoutCtr.activateFirstCrumbController(startCtr); // Our view is generated by the main and the bread crumb layouer mainLayoutCtr = new LayoutMain3ColsController(ureq, getWindowControl(), null, null, breadCrumbLayoutCtr.getInitialComponent(), null); listenTo(mainLayoutCtr); putInitialPanel(mainLayoutCtr.getInitialComponent()); activatePageFromURL(uriParts, ureq, startCtr); // Register for events on this user session. Identity is set to null, but // event bus is still user-session only eventBus = ureq.getUserSession().getSingleUserEventCenter(); eventBus.registerFor(this, ureq.getIdentity(), ContextHelpTopNavController.CHANGE_LANG_RESOURCE); // do logging if (ureq.getUserSession().getSessionInfo() != null) { // context help can be called in dmz zone as well - in that case don't call log() - only call log() for logged-in users ThreadLocalUserActivityLogger.log(OlatLoggingAction.CS_HELP, getClass(), CoreLoggingResourceable .wrapNonOlatResource(StringResourceableType.csHelp, "-1", ArrayUtils.toString(uriParts))); } }
From source file:org.olat.ldap.LDAPLoginManagerImpl.java
/** * Creates User in OLAT and ads user to LDAP securityGroup Required Attributes have to be checked before this method. * //from w w w . j av a 2 s. c o m * @param userAttributes Set of LDAP Attribute of User to be created */ @SuppressWarnings("unchecked") public void createAndPersistUser(final Attributes userAttributes) { // Get and Check Config final String[] reqAttrs = LDAPLoginModule.checkReqAttr(userAttributes); if (reqAttrs != null) { logWarn("Can not create and persist user, the following attributes are missing::" + ArrayUtils.toString(reqAttrs), null); return; } final String uid = getAttributeValue(userAttributes .get(LDAPLoginModule.mapOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER))); final String email = getAttributeValue( userAttributes.get(LDAPLoginModule.mapOlatPropertyToLdapAttribute(UserConstants.EMAIL))); // Lookup user if (securityManager.findIdentityByName(uid) != null) { logError("Can't create user with username='" + uid + "', does already exist in OLAT database", null); return; } if (!MailHelper.isValidEmailAddress(email)) { // needed to prevent possibly an AssertException in findIdentityByEmail breaking the sync! logError("Cannot try to lookup user " + uid + " by email with an invalid email::" + email, null); return; } if (userManager.findIdentityByEmail(email) != null) { logError("Can't create user with email='" + email + "', does already exist in OLAT database", null); return; } // Create User (first and lastname is added in next step) final User user = userManager.createUser(null, null, email); // Set User Property's (Iterates over Attributes and gets OLAT Property out // of olatexconfig.xml) final NamingEnumeration<Attribute> neAttr = (NamingEnumeration<Attribute>) userAttributes.getAll(); try { while (neAttr.hasMore()) { final Attribute attr = neAttr.next(); final String olatProperty = mapLdapAttributeToOlatProperty(attr.getID()); if (attr.get() != uid) { final String ldapValue = getAttributeValue(attr); if (olatProperty == null || ldapValue == null) { continue; } user.setProperty(olatProperty, ldapValue); } } // Add static user properties from the configuration final Map<String, String> staticProperties = LDAPLoginModule.getStaticUserProperties(); if (staticProperties != null && staticProperties.size() > 0) { for (final Entry<String, String> staticProperty : staticProperties.entrySet()) { user.setProperty(staticProperty.getKey(), staticProperty.getValue()); } } } catch (final NamingException e) { logError("NamingException when trying to create and persist LDAP user with username::" + uid, e); return; } catch (final Exception e) { // catch any exception here to properly log error logError("Unknown exception when trying to create and persist LDAP user with username::" + uid, e); return; } // Create Identity final Identity identity = securityManager.createAndPersistIdentityAndUser(uid, user, LDAPAuthenticationController.PROVIDER_LDAP, uid, null); // Add to SecurityGroup LDAP SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP); securityManager.addIdentityToSecurityGroup(identity, secGroup); // Add to SecurityGroup OLATUSERS secGroup = securityManager.findSecurityGroupByName(Constants.GROUP_OLATUSERS); securityManager.addIdentityToSecurityGroup(identity, secGroup); logInfo("Created LDAP user username::" + uid); }
From source file:org.olat.ldap.LDAPLoginManagerImpl.java
private void doBatchSyncNewAndModifiedUsers(final LdapContext ctx, final String sinceSentence, final LDAPError errors) { // Get new and modified users from LDAP int count = 0; final List<Attributes> ldapUserList = getUserAttributesModifiedSince(lastSyncDate, ctx); // Check for new and modified users final List<Attributes> newLdapUserList = new ArrayList<Attributes>(); final Map<Identity, Map<String, String>> changedMapIdentityMap = new HashMap<Identity, Map<String, String>>(); for (final Attributes userAttrs : ldapUserList) { final String user = getAttributeValue(userAttrs .get(LDAPLoginModule.mapOlatPropertyToLdapAttribute(LDAPConstants.LDAP_USER_IDENTIFYER))); final Identity identity = findIdentyByLdapAuthentication(user, errors); if (identity != null) { final Map<String, String> changedAttrMap = prepareUserPropertyForSync(userAttrs, identity); if (changedAttrMap != null) { changedMapIdentityMap.put(identity, changedAttrMap); }//from w w w .j a v a 2 s .c o m } else if (errors.isEmpty()) { final String[] reqAttrs = LDAPLoginModule.checkReqAttr(userAttrs); if (reqAttrs == null) { newLdapUserList.add(userAttrs); } else { logWarn("Error in LDAP batch sync: can't create user with username::" + user + " : missing required attributes::" + ArrayUtils.toString(reqAttrs), null); } } else { logWarn(errors.get(), null); } if (++count % 20 == 0) { DBFactory.getInstance().intermediateCommit(); } } // sync existing users if (changedMapIdentityMap == null || changedMapIdentityMap.isEmpty()) { logInfo("LDAP batch sync: no users to sync" + sinceSentence); } else { for (final Identity ident : changedMapIdentityMap.keySet()) { syncUser(changedMapIdentityMap.get(ident), ident); // REVIEW Identity are not saved??? if (++count % 20 == 0) { DBFactory.getInstance().intermediateCommit(); } } logInfo("LDAP batch sync: " + changedMapIdentityMap.size() + " users synced" + sinceSentence); } // create new users if (newLdapUserList.isEmpty()) { logInfo("LDAP batch sync: no users to create" + sinceSentence); } else { for (final Attributes userAttrs : newLdapUserList) { createAndPersistUser(userAttrs); if (++count % 20 == 0) { DBFactory.getInstance().intermediateCommit(); } } logInfo("LDAP batch sync: " + newLdapUserList.size() + " users created" + sinceSentence); } }