List of usage examples for org.apache.commons.lang3 StringUtils strip
public static String strip(String str, final String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:org.talend.components.salesforce.runtime.SalesforceSourceOrSink.java
protected ConnectionHolder connect(RuntimeContainer container) throws IOException { enableTLSv11AndTLSv12ForJava7();/*from w w w. j a va 2 s . c o m*/ final ConnectionHolder ch = new ConnectionHolder(); SalesforceConnectionProperties connProps = properties.getConnectionProperties(); String refComponentId = connProps.getReferencedComponentId(); Object sharedConn = null; // Using another component's connection if (refComponentId != null) { // In a runtime container if (container != null) { sharedConn = container.getComponentData(refComponentId, KEY_CONNECTION); if (sharedConn != null) { if (sharedConn instanceof PartnerConnection) { ch.connection = (PartnerConnection) sharedConn; } else if (sharedConn instanceof BulkConnection) { ch.bulkConnection = (BulkConnection) sharedConn; } return ch; } throw new IOException("Referenced component: " + refComponentId + " not connected"); } // Design time connProps = connProps.getReferencedConnectionProperties(); } // FIXME add back reffed connection ConnectorConfig config = new ConnectorConfig(); config.setUsername(StringUtils.strip(connProps.userPassword.userId.getStringValue(), "\"")); String password = StringUtils.strip(connProps.userPassword.password.getStringValue(), "\""); String securityKey = StringUtils.strip(connProps.userPassword.securityKey.getStringValue(), "\""); if (!StringUtils.isEmpty(securityKey)) { password = password + securityKey; } config.setPassword(password); setProxy(config); // Notes on how to test this // http://thysmichels.com/2014/02/15/salesforce-wsc-partner-connection-session-renew-when-session-timeout/ config.setSessionRenewer(new SessionRenewer() { @Override public SessionRenewalHeader renewSession(ConnectorConfig connectorConfig) throws ConnectionException { SessionRenewalHeader header = new SessionRenewalHeader(); // FIXME - session id need to be null for trigger the login? // connectorConfig.setSessionId(null); doConnection(connectorConfig); SessionHeader_element h = ch.connection.getSessionHeader(); // FIXME - one or the other, I have seen both // header.name = new QName("urn:partner.soap.sforce.com", "X-SFDC-Session"); header.name = new QName("urn:partner.soap.sforce.com", "SessionHeader"); header.headerElement = h.getSessionId(); return header; } }); if (connProps.timeout.getValue() > 0) { config.setConnectionTimeout(connProps.timeout.getValue()); } config.setCompression(connProps.needCompression.getValue()); if (false) { config.setTraceMessage(true); } config.setUseChunkedPost(connProps.httpChunked.getValue()); config.setValidateSchema(false); try { ch.connection = doConnection(config); if (ch.connection != null) { String clientId = connProps.clientId.getStringValue(); if (clientId != null) { // Need the test. ch.connection.setCallOptions(clientId, null); } } if (connProps.bulkConnection.getValue()) { ch.bulkConnection = connectBulk(ch.connection.getConfig()); sharedConn = ch.bulkConnection; } else { sharedConn = ch.connection; } if (container != null) { container.setComponentData(container.getCurrentComponentId(), KEY_CONNECTION, sharedConn); } return ch; } catch (ConnectionException e) { throw new IOException(e); } }
From source file:org.talend.components.salesforce.runtime.SalesforceSourceOrSinkTestIT.java
@Test(expected = ConnectionException.class) public void testSalesForcePasswordExpired() throws ConnectionException { SalesforceSourceOrSink salesforceSourceOrSink = new SalesforceSourceOrSink(); TSalesforceInputProperties properties = (TSalesforceInputProperties) new TSalesforceInputProperties(null) .init();//from w w w .ja va2 s .co m salesforceSourceOrSink.initialize(null, properties); ConnectorConfig config = new ConnectorConfig(); config.setUsername(StringUtils.strip(USER_ID_EXPIRED, "\"")); String password = StringUtils.strip(PASSWORD_EXPIRED, "\""); String securityKey = StringUtils.strip(SECURITY_KEY_EXPIRED, "\""); if (StringUtils.isNotEmpty(securityKey)) { password = password + securityKey; } config.setPassword(password); PartnerConnection connection = null; try { connection = salesforceSourceOrSink.doConnection(config, true); } catch (LoginFault ex) { Assert.fail("Must be an exception related to expired password, not the Login Fault."); } finally { if (null != connection) { connection.logout(); } } }
From source file:org.talend.components.snowflake.tsnowflakerow.TSnowflakeRowProperties.java
public ValidationResult validateGuessQuery() { String tableName = StringUtils.strip((String) table.tableName.getStoredValue(), "\""); if (tableName == null || tableName.isEmpty()) { return new ValidationResult(Result.ERROR, getI18nMessage("error.missing.tableName")); }/* ww w.j a v a 2 s . co m*/ Schema schema = table.main.schema.getValue(); if (schema == null || schema.getFields().isEmpty()) { return new ValidationResult(Result.ERROR, getI18nMessage("error.missing.schema")); } query.setValue("\"" + generateSqlQuery(tableName, schema) + "\""); return ValidationResult.OK; }
From source file:org.talend.components.snowflake.tsnowflakerow.TSnowflakeRowPropertiesTest.java
@Test public void testValidateGuessSchema() { ValidationResult expected = ValidationResult.OK; String expectedQuery = "SELECT employee.id, employee.name, employee.age FROM employee"; rowProperties.table.tableName.setValue("employee"); Schema schema = SchemaBuilder.builder().record("record").fields().requiredInt("id").requiredString("name") .requiredInt("age").endRecord(); rowProperties.table.main.schema.setValue(schema); Assert.assertEquals(expected, rowProperties.validateGuessQuery()); Assert.assertEquals(expectedQuery, StringUtils.strip(rowProperties.query.getValue(), "\"")); }
From source file:org.talend.designer.maven.utils.ClasspathsJarGenerator.java
private static String wrapWithSlash(String str) { str = StringUtils.strip(str, SLASH); str = StringUtils.wrap(str, SLASH); return str; }
From source file:org.talend.designer.maven.utils.PomIdsHelper.java
private static String getJobFolderSuffix(Property property) { String suffix = ItemResourceUtil.getItemRelativePath(property).toPortableString(); suffix = StringUtils.strip(suffix, "/"); //$NON-NLS-1$ suffix = StringUtils.replace(suffix, "/", "."); //$NON-NLS-1$ //$NON-NLS-2$ return suffix; }
From source file:org.wikipedia.nirvana.archive.ArchiveWithHeaders.java
public void add(String item, String header) { newLines++;// www. ja v a2 s. c om Section part = null; String headerStripped = StringUtils.strip(header, "=").trim(); if (addToTop) { boolean found = false; for (int i = 0; i < parts.size(); i++) { part = parts.get(i); if (part.getHeader() != null && part.getHeader().compareTo(headerStripped) == 0) { found = true; break; } } if (found) { part.addItemToBegin(item); } else { part = createSection(enumeration, headerStripped, header, false); parts.add(0, part); part.addItemToBegin(item); } } else { boolean found = false; for (int i = parts.size() - 1; i >= 0; i--) { part = parts.get(i); if (part.getHeader() != null && part.getHeader().compareTo(headerStripped) == 0) { found = true; break; } } if (found) { part.addItemToEnd(item); } else { part = createSection(enumeration, headerStripped, header, false); parts.add(part); part.addItemToEnd(item); } } }
From source file:org.wikipedia.nirvana.archive.ArchiveWithHeaders.java
public void add(String item, String header, String headerHeader) { newLines++;/*from ww w . j ava 2 s . c om*/ String headerHeaderStripped = StringUtils.strip(headerHeader, "=").trim(); String headerStripped = StringUtils.strip(header, "=").trim(); Section part = null; int hhIndex = -1; hhIndex = findSuperHeader(headerHeaderStripped); // , // if (hhIndex < 0) { if (addToTop) { part = createSection(enumeration, headerStripped, header, headerHeaderStripped, headerHeader, false); parts.add(0, part); part.addItemToBegin(item); return; } else { boolean createNewSection = true; if (parts.size() != 0 && parts.get(0).getHeaderHeader() == null) { // , ( ) if (latestItemHeaderHeader != null && latestItemHeaderHeader.compareTo(headerHeader) == 0) { createNewSection = false; } } if (createNewSection) { part = createSection(enumeration, headerStripped, header, headerHeaderStripped, headerHeader, false); parts.add(part); part.addItemToEnd(item); return; } else { hhIndex = 0; } } } else { } // 1 ? int hIndex = findHeaderInSuperSection(headerStripped, hhIndex); if (hIndex < 0) { // if (addToTop) { part = parts.get(hhIndex); part.clearHeaderHeader(); part = createSection(enumeration, headerStripped, header, headerHeaderStripped, headerHeader, false); parts.add(hhIndex, part); part.addItemToBegin(item); } else { part = createSection(enumeration, headerStripped, header, false); parts.add(findLastSectionInSuperSection(hhIndex) + 1, part); part.addItemToEnd(item); } } else { part = parts.get(hIndex); if (addToTop) { part.addItemToBegin(item); } else { part.addItemToEnd(item); } } }
From source file:org.wikipedia.nirvana.archive.ArchiveWithHeadersWithItemsCount.java
protected Section createSection(Enumeration enumeration, String header, String headerText, boolean old) { if (old) {/*from w w w . j a v a2s.co m*/ IntAndString data = new IntAndString(); String ht = headerVariableToConstant(headerText, data); String h = StringUtils.strip(ht, "=").trim(); return new SectionWithItemsCount(enumeration, h, ht, old, data.val); } return new SectionWithItemsCount(enumeration, header, headerText, old); }
From source file:org.wikipedia.nirvana.archive.ArchiveWithHeadersWithItemsCount.java
protected Section createSection(Enumeration enumeration, String header, String headerText, String sHeader, String sHeaderText, boolean old) { if (old) {/* w w w.j a va 2 s .c o m*/ IntAndString data = new IntAndString(); String ht = headerVariableToConstant(headerText, data); String h = StringUtils.strip(ht, "=").trim(); return new SectionWithItemsCount(enumeration, h, ht, sHeader, sHeaderText, old, data.val); } return new SectionWithItemsCount(enumeration, header, headerText, sHeader, sHeaderText, old); }