List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty
public static String defaultIfEmpty(String str, String defaultStr)
Returns either the passed in String, or if the String is empty or null
, the value of defaultStr
.
From source file:com.cognifide.cq.cqsm.core.servlets.ScriptUploadServlet.java
private String getRedirectTo(SlingHttpServletRequest request) { return StringUtils.defaultIfEmpty(request.getParameter("redirectTo"), REDIRECT_URL); }
From source file:jp.co.tis.gsp.tools.dba.mojo.ExportSchemaMojo.java
private ExportParams createExportParams() { ExportParams param = new ExportParams(); File exportFile = new File(outputDirectoryTemp, StringUtils.defaultIfEmpty(dmpFile, schema + ".dmp")); param.setUser(user);/*from w w w . j a v a 2 s.c om*/ param.setPassword(password); param.setAdminUser(adminUser); param.setAdminPassword(adminPassword); param.setSchema(schema); param.setDumpFile(exportFile); param.setDdlDirectory(ddlDirectory); param.setExtraDdlDirectory(extraDdlDirectory); param.setOutputDirectory(outputDirectoryTemp); return param; }
From source file:info.magnolia.content2bean.impl.DescriptorFileBasedTypeMapping.java
protected TypeDescriptor processProperties(Class<?> className, Properties props) throws Exception { String descriptorClassName = StringUtils.defaultIfEmpty(props.getProperty("descriptorClass"), PropertiesBasedTypeDescriptor.class.getName()); final ClassFactory cl = Classes.getClassFactory(); Class<? extends TypeDescriptor> descriptorClass = cl.forName(descriptorClassName); return cl.newInstance(descriptorClass, props); }
From source file:com.adobe.acs.commons.oak.impl.EnsureOakIndexServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { String forceParam = StringUtils.defaultIfEmpty(request.getParameter(PARAM_FORCE), "false"); boolean force = Boolean.parseBoolean(forceParam); String path = StringUtils.stripToNull(request.getParameter(PARAM_PATH)); try {/* w ww . ja va 2s . c o m*/ int count = 0; if (StringUtils.isBlank(path)) { count = ensureOakIndexManager.ensureAll(force); } else { count = ensureOakIndexManager.ensure(force, path); } response.setContentType("text/plain; charset=utf-8"); response.getWriter().println("Initiated the ensuring of " + count + " oak indexes"); response.setStatus(HttpServletResponse.SC_OK); } catch (IOException e) { log.warn("Caught IOException while handling doPost() in the Ensure Oak Index Servlet", e); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:com.adaptris.core.services.jdbc.ResultSetTranslatorImp.java
protected String toString(JdbcResultRow rs, int column) { String result = null;//from www .j a va 2s .com try { if (getColumnTranslators().size() > 0 && column < getColumnTranslators().size()) { result = getColumnTranslators().get(column).translate(rs, column); } else { if (attemptConversion()) { result = ColumnHelper.translate(rs, column); } else { result = ColumnHelper.toString(rs, column); } } } catch (Exception e) { logColumnErrors(column, e); } return StringUtils.defaultIfEmpty(result, ""); }
From source file:com.opengamma.component.tool.AbstractDbTool.java
/** * Initializes and runs the tool from standard command-line arguments. * <p>//w w w . j a v a 2s . c o m * The base class defined three options:<br /> * c/config - the config file, mandatory unless default specified<br /> * l/logback - the logback configuration, default tool-logback.xml<br /> * h/help - prints the help tool<br /> * * @param args the command-line arguments, not null * @param toolContextClass the type of database tool context to create, should match the generic type argument * @return true if successful, false otherwise */ public boolean initAndRun(String[] args, Class<? extends T> toolContextClass) { ArgumentChecker.notNull(args, "args"); Options options = createOptions(); CommandLineParser parser = new PosixParser(); CommandLine line; try { line = parser.parse(options, args); } catch (ParseException e) { usage(options); return false; } _commandLine = line; if (line.hasOption(HELP_OPTION)) { usage(options); return true; } String logbackResource = line.getOptionValue(LOGBACK_RESOURCE_OPTION); logbackResource = StringUtils.defaultIfEmpty(logbackResource, ToolUtils.getDefaultLogbackConfiguration()); String configResource = line.getOptionValue(CONFIG_RESOURCE_OPTION); return init(logbackResource) && run(configResource, toolContextClass); }
From source file:co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetAdminOpHTTPHandler.java
@POST @Path("/data/datasets/{name}/admin/exists") public void exists(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("name") String instanceName) { Id.Namespace namespace = Id.Namespace.from(namespaceId); try {/*from ww w .ja v a2s . c o m*/ DatasetAdmin datasetAdmin = getDatasetAdmin(Id.DatasetInstance.from(namespace, instanceName)); responder.sendJson(HttpResponseStatus.OK, new DatasetAdminOpResponse(datasetAdmin.exists(), null)); } catch (HandlerException e) { LOG.debug("Got handler exception", e); responder.sendString(e.getFailureStatus(), StringUtils.defaultIfEmpty(e.getMessage(), "")); } catch (Exception e) { LOG.error(getAdminOpErrorMessage("exists", instanceName), e); responder.sendString(HttpResponseStatus.INTERNAL_SERVER_ERROR, getAdminOpErrorMessage("exists", instanceName)); } }
From source file:com.adobe.acs.tools.csv_asset_importer.impl.Parameters.java
public Parameters(SlingHttpServletRequest request) throws IOException { final RequestParameter charsetParam = request.getRequestParameter("charset"); final RequestParameter delimiterParam = request.getRequestParameter("delimiter"); final RequestParameter fileParam = request.getRequestParameter("file"); final RequestParameter multiDelimiterParam = request.getRequestParameter("multiDelimiter"); final RequestParameter separatorParam = request.getRequestParameter("separator"); final RequestParameter fileLocationParam = request.getRequestParameter("fileLocation"); final RequestParameter importStrategyParam = request.getRequestParameter("importStrategy"); final RequestParameter updateBinaryParam = request.getRequestParameter("updateBinary"); final RequestParameter mimeTypePropertyParam = request.getRequestParameter("mimeTypeProperty"); final RequestParameter skipPropertyParam = request.getRequestParameter("skipProperty"); final RequestParameter absTargetPathPropertyParam = request.getRequestParameter("absTargetPathProperty"); final RequestParameter relSrcPathPropertyParam = request.getRequestParameter("relSrcPathProperty"); final RequestParameter uniquePropertyParam = request.getRequestParameter("uniqueProperty"); final RequestParameter ignorePropertiesParam = request.getRequestParameter("ignoreProperties"); final RequestParameter throttleParam = request.getRequestParameter("throttle"); final RequestParameter batchSizeParam = request.getRequestParameter("batchSize"); this.charset = DEFAULT_CHARSET; if (charsetParam != null) { this.charset = StringUtils.defaultIfEmpty(charsetParam.toString(), DEFAULT_CHARSET); }//from w w w . j a va 2 s. c o m this.delimiter = null; if (delimiterParam != null && StringUtils.isNotBlank(delimiterParam.toString())) { this.delimiter = delimiterParam.toString().charAt(0); } this.separator = null; if (separatorParam != null && StringUtils.isNotBlank(separatorParam.toString())) { this.separator = separatorParam.toString().charAt(0); } this.multiDelimiter = "|"; if (multiDelimiterParam != null && StringUtils.isNotBlank(multiDelimiterParam.toString())) { this.multiDelimiter = multiDelimiterParam.toString(); } this.importStrategy = ImportStrategy.FULL; if (importStrategyParam != null && StringUtils.isNotBlank(importStrategyParam.toString())) { this.importStrategy = ImportStrategy.valueOf(importStrategyParam.toString()); } this.updateBinary = false; if (updateBinaryParam != null && StringUtils.isNotBlank(updateBinaryParam.toString())) { this.updateBinary = StringUtils.equalsIgnoreCase(updateBinaryParam.toString(), "true"); } this.fileLocation = "/dev/null"; if (fileLocationParam != null && StringUtils.isNotBlank(fileLocationParam.toString())) { this.fileLocation = fileLocationParam.toString(); } this.skipProperty = null; if (skipPropertyParam != null && StringUtils.isNotBlank(skipPropertyParam.toString())) { skipProperty = StringUtils.stripToNull(skipPropertyParam.toString()); } this.mimeTypeProperty = null; if (mimeTypePropertyParam != null && StringUtils.isNotBlank(mimeTypePropertyParam.toString())) { mimeTypeProperty = StringUtils.stripToNull(mimeTypePropertyParam.toString()); } this.absTargetPathProperty = null; if (absTargetPathPropertyParam != null && StringUtils.isNotBlank(absTargetPathPropertyParam.toString())) { this.absTargetPathProperty = StringUtils.stripToNull(absTargetPathPropertyParam.toString()); } this.relSrcPathProperty = null; if (relSrcPathPropertyParam != null && StringUtils.isNotBlank(relSrcPathPropertyParam.toString())) { this.relSrcPathProperty = StringUtils.stripToNull(relSrcPathPropertyParam.toString()); } this.uniqueProperty = null; if (uniquePropertyParam != null && StringUtils.isNotBlank(uniquePropertyParam.toString())) { this.uniqueProperty = StringUtils.stripToNull(uniquePropertyParam.toString()); } this.ignoreProperties = new String[] { CsvAssetImporterServlet.TERMINATED }; if (ignorePropertiesParam != null && StringUtils.isNotBlank(ignorePropertiesParam.toString())) { final String[] tmp = StringUtils.split(StringUtils.stripToNull(ignorePropertiesParam.toString()), ","); final List<String> list = new ArrayList<String>(); for (final String t : tmp) { String val = StringUtils.stripToNull(t); if (val != null) { list.add(val); } } list.add(CsvAssetImporterServlet.TERMINATED); this.ignoreProperties = list.toArray(new String[] {}); } if (fileParam != null && fileParam.getInputStream() != null) { this.file = fileParam.getInputStream(); } this.throttle = DEFAULT_THROTTLE; if (throttleParam != null && StringUtils.isNotBlank(throttleParam.toString())) { try { this.throttle = Long.valueOf(throttleParam.toString()); if (this.throttle < 0) { this.throttle = DEFAULT_THROTTLE; } } catch (Exception e) { this.throttle = DEFAULT_THROTTLE; } } batchSize = DEFAULT_BATCH_SIZE; if (batchSizeParam != null && StringUtils.isNotBlank(batchSizeParam.toString())) { try { this.batchSize = Integer.valueOf(batchSizeParam.toString()); if (this.batchSize < 1) { this.batchSize = DEFAULT_BATCH_SIZE; } } catch (Exception e) { this.batchSize = DEFAULT_BATCH_SIZE; } } }
From source file:info.magnolia.jcr.util.PropertiesImportExport.java
/** * Each property or node in the stream has to be separated by the \n. *//*from w ww. ja v a2 s. com*/ public void createNodes(Node root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream); properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, NodeTypes.ContentNode.NAME); Node c = NodeUtil.createPath(root, path, type); populateNode(c, propertyName, valueStr); } }
From source file:com.adaptris.jdbc.JdbcResultSetImpl.java
private static JdbcResultRow mapRow(ResultSet resultSet) throws SQLException { ResultSetMetaData rsmd = resultSet.getMetaData(); int columnCount = rsmd.getColumnCount(); JdbcResultRow row = new JdbcResultRow(); for (int counter = 1; counter <= columnCount; counter++) { row.setFieldValue(StringUtils.defaultIfEmpty(rsmd.getColumnLabel(counter), rsmd.getColumnName(counter)), resultSet.getObject(counter), rsmd.getColumnType(counter)); }//from w ww . j a va 2s . co m return row; }