List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:com.mirth.connect.util.CodeTemplateUtil.java
public static String stripDocumentation(String code) { if (StringUtils.isNotBlank(code)) { code = StringUtils.trim(code); Matcher matcher = COMMENT_PATTERN.matcher(code); if (matcher.find()) { return StringUtils.trim(code.substring(matcher.end())); }//from w w w .j av a 2 s . c o m } return code; }
From source file:io.wcm.devops.conga.generator.plugins.fileheader.XmlFileHeader.java
@Override public FileHeaderContext extract(FileContext file) { try {// www. ja va 2 s .co m Document doc = documentBuilder.parse(file.getFile()); if (doc.getChildNodes().getLength() > 0) { Node firstNode = doc.getChildNodes().item(0); if (firstNode instanceof Comment) { String comment = StringUtils.trim(((Comment) firstNode).getTextContent()); List<String> lines = ImmutableList.copyOf(StringUtils.split(comment, "\n")); return new FileHeaderContext().commentLines(lines); } } } catch (SAXException | IOException ex) { throw new GeneratorException("Unable to parse file header from " + FileUtil.getCanonicalPath(file), ex); } return null; }
From source file:com.thinkbiganalytics.alerts.spi.defaults.DefaultAlertCriteria.java
protected BooleanBuilder orFilter(QJpaAlert alert) { BooleanBuilder globalFilter = new BooleanBuilder(); if (StringUtils.isNotBlank(getOrFilter())) { Lists.newArrayList(StringUtils.split(getOrFilter(), ",")).stream().forEach(filter -> { filter = StringUtils.trim(filter); if (filter != null) { BooleanBuilder booleanBuilder = new BooleanBuilder(); List<Predicate> preds = new ArrayList<>(); try { Alert.State state = Alert.State.valueOf(filter.toUpperCase()); preds.add(alert.state.eq(state)); } catch (IllegalArgumentException e) { }/* w w w. j av a2s .co m*/ preds.add(alert.typeString.like(filter.concat("%"))); preds.add(alert.subtype.like(filter.concat("%"))); booleanBuilder.andAnyOf(preds.toArray(new Predicate[preds.size()])); globalFilter.and(booleanBuilder); } }); } return globalFilter; }
From source file:com.yqboots.menu.core.MenuItemManagerImpl.java
/** * {@inheritDoc}/*from w w w. j ava2s . c om*/ */ @Override public Page<MenuItem> getMenuItems(final String wildcardName, final Pageable pageable) { final String searchStr = StringUtils.trim(StringUtils.defaultString(wildcardName)); return menuItemRepository.findByNameLikeIgnoreCaseOrderByName(DBUtils.wildcard(searchStr), pageable); }
From source file:net.lmxm.ute.configuration.ConfigurationReader.java
/** * Parses the file.//from ww w .j av a 2s . c o m * * @param fileType the file type * * @return the file */ private FileReference parseFile(final FileType fileType) { final String prefix = "parseFile() :"; LOGGER.debug("{} entered", prefix); FileReference file = new FileReference(); file.setName(StringUtils.trim(fileType.getName())); file.setTargetName(StringUtils.trim(fileType.getTargetName())); if (file.isEmpty()) { file = null; } LOGGER.debug("{} returning {}", prefix, file); return file; }
From source file:com.adguard.commons.io.IoUtils.java
/** * Reads line from the input stream/* ww w . j av a 2 s. c o m*/ * * @param inputStream Input stream * @param encoding Characters encoding * @return Line read or null if response is empty */ public static String readLine(InputStream inputStream, Charset encoding) throws IOException { byte[] lineBytes = readLineBytes(inputStream); if (lineBytes == null || lineBytes.length == 0) { return null; } return StringUtils.trim(new String(lineBytes, encoding)); }
From source file:de.micromata.genome.gwiki.page.impl.wiki.blueprint.GWikiBlueprintEditorActionBean.java
public Object onEvaluate() { if (StringUtils.isBlank(templateId) == true) { buildTemplateList();//from w w w. j av a2 s . c o m return null; } else { renderTemplate(); } if (wikiTemplate == null) { return null; } // TODO validate form. wikiContext.setRequestAttribute(GWikiFormInputMacro.EVAL_FORM, Boolean.TRUE); evaluatedWiki = StringUtils.trim(wikiTemplate.getCompiledObject().getSource()); return null; }
From source file:com.ottogroup.bi.spqr.pipeline.component.source.SourceRuntimeEnvironment.java
/** * Initializes the runtime environment using the provided input * @param processingNodeId/*from ww w . ja v a 2 s. com*/ * @param pipelineId * @param source * @param queueProducer * @param executorService * @throws RequiredInputMissingException */ public SourceRuntimeEnvironment(final String processingNodeId, final String pipelineId, final Source source, final StreamingMessageQueueProducer queueProducer, final ExecutorService executorService) throws RequiredInputMissingException { /////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(processingNodeId)) throw new RequiredInputMissingException("Missing required processing node identifier"); if (StringUtils.isBlank(pipelineId)) throw new RequiredInputMissingException("Missing required pipeline identifier"); if (source == null) throw new RequiredInputMissingException("Missing required source"); if (queueProducer == null) throw new RequiredInputMissingException("Missing required queue producer"); if (executorService == null) throw new RequiredInputMissingException("Missing required executor service"); // /////////////////////////////////////////////////////////////// this.processingNodeId = StringUtils.lowerCase(StringUtils.trim(processingNodeId)); this.pipelineId = StringUtils.lowerCase(StringUtils.trim(pipelineId)); this.sourceId = StringUtils.lowerCase(StringUtils.trim(source.getId())); this.source = source; this.source.setIncomingMessageCallback(this); this.queueProducer = queueProducer; this.executorService = executorService; this.executorService.submit(source); if (logger.isDebugEnabled()) logger.debug("source runtime environment initialized [id=" + source.getId() + "]"); }
From source file:com.ottogroup.bi.spqr.operator.esper.EsperOperator.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *///from w w w . java 2s . c o m public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { if (properties == null) throw new RequiredInputMissingException("Missing required properties"); ///////////////////////////////////////////////////////////////////////////////// // fetch an validate properties Set<String> esperQueryStrings = new HashSet<>(); for (int i = 1; i < Integer.MAX_VALUE; i++) { String tmpStr = properties.getProperty(CFG_ESPER_STATEMENT_PREFIX + i); if (StringUtils.isBlank(tmpStr)) break; esperQueryStrings.add(StringUtils.trim(tmpStr)); } if (esperQueryStrings.isEmpty()) throw new RequiredInputMissingException("Missing required ESPER statement(s)"); ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // fetch event configuration Map<String, Map<String, String>> eventConfiguration = new HashMap<>(); for (int i = 1; i < Integer.MAX_VALUE; i++) { final String typeDefEvent = StringUtils .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_EVENT_SUFFIX)); if (StringUtils.isBlank(typeDefEvent)) break; final String typeDefName = StringUtils .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_NAME_SUFFIX)); final String typeDefType = StringUtils .trim(properties.getProperty(CFG_ESPER_TYPE_DEF_PREFIX + i + CFG_ESPER_TYPE_DEF_TYPE_SUFFIX)); if (StringUtils.isBlank(typeDefName) || StringUtils.isBlank(typeDefType)) throw new RequiredInputMissingException( "Missing type def name or type for event '" + typeDefEvent + "' at position " + i); Map<String, String> ec = eventConfiguration.get(typeDefEvent); if (ec == null) ec = new HashMap<>(); ec.put(typeDefName, typeDefType); eventConfiguration.put(typeDefEvent, ec); } /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // create esper configuration Configuration esperConfiguration = new Configuration(); for (final String event : eventConfiguration.keySet()) { Map<String, String> ec = eventConfiguration.get(event); if (ec != null && !ec.isEmpty()) { Map<String, Object> typeDefinition = new HashMap<>(); for (final String typeDefName : ec.keySet()) { final String typeDefType = ec.get(typeDefName); try { typeDefinition.put(typeDefName, Class.forName(typeDefType)); } catch (ClassNotFoundException e) { throw new ComponentInitializationFailedException("Failed to lookup provided type '" + typeDefType + "' for event '" + event + "'. Error: " + e.getMessage()); } } esperConfiguration.addEventType(event, typeDefinition); } } Map<String, Object> spqrDefaultTypeDefinition = new HashMap<>(); spqrDefaultTypeDefinition.put(SPQR_EVENT_TIMESTAMP_FIELD, Long.class); spqrDefaultTypeDefinition.put(SPQR_EVENT_BODY_FIELD, Map.class); esperConfiguration.addEventType(DEFAULT_INPUT_EVENT, spqrDefaultTypeDefinition); esperConfiguration.addEventType(DEFAULT_OUTPUT_EVENT, spqrDefaultTypeDefinition); /////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // initialize service provider, submit statements and retrieve runtime this.esperServiceProvider = EPServiceProviderManager.getDefaultProvider(esperConfiguration); this.esperServiceProvider.initialize(); for (final String qs : esperQueryStrings) { try { EPStatement esperStatement = this.esperServiceProvider.getEPAdministrator().createEPL(qs); esperStatement.setSubscriber(this); } catch (EPStatementException e) { throw new ComponentInitializationFailedException( "Failed to parse query into ESPER statement. Error: " + e.getMessage(), e); } } this.esperRuntime = this.esperServiceProvider.getEPRuntime(); /////////////////////////////////////////////////////////////////////////////////// }
From source file:com.ottogroup.bi.spqr.pipeline.queue.chronicle.DefaultStreamingMessageQueue.java
/** * @see com.ottogroup.bi.spqr.pipeline.queue.StreamingMessageQueue#initialize(java.util.Properties) *//*from w w w. j av a 2s.co m*/ public void initialize(Properties properties) throws RequiredInputMissingException { //////////////////////////////////////////////////////////////////////////////// // extract and validate input if (properties == null) throw new RequiredInputMissingException("Missing required properties"); if (StringUtils.isBlank(this.id)) throw new RequiredInputMissingException("Missing required queue identifier"); if (StringUtils.equalsIgnoreCase( StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_DELETE_ON_EXIT)), "false")) this.deleteOnExit = false; this.basePath = StringUtils.lowerCase(StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_PATH))); if (StringUtils.isBlank(this.basePath)) this.basePath = System.getProperty("java.io.tmpdir"); String tmpCycleFormat = StringUtils .trim(properties.getProperty(CFG_CHRONICLE_QUEUE_CYCLE_FORMAT, "yyyy-MM-dd-HH-mm")); if (StringUtils.isNotBlank(tmpCycleFormat)) this.cycleFormat = tmpCycleFormat; String pathToChronicle = this.basePath; if (!StringUtils.endsWith(pathToChronicle, File.separator)) pathToChronicle = pathToChronicle + File.separator; pathToChronicle = pathToChronicle + id; try { this.queueRollingInterval = TimeUnit.MINUTES.toMillis( Long.parseLong(StringUtils.trim(properties.getProperty(CFG_CHRONICLE_QUEUE_ROLLING_INTERVAL)))); if (this.queueRollingInterval < VanillaChronicle.MIN_CYCLE_LENGTH) { this.queueRollingInterval = VanillaChronicle.MIN_CYCLE_LENGTH; } } catch (Exception e) { logger.info("Invalid queue rolling interval found: " + e.getMessage() + ". Using default: " + TimeUnit.MINUTES.toMillis(60)); } this.queueWaitStrategy = getWaitStrategy( StringUtils.trim(properties.getProperty(CFG_QUEUE_MESSAGE_WAIT_STRATEGY))); // //////////////////////////////////////////////////////////////////////////////// // clears the queue if requested if (this.deleteOnExit) { ChronicleTools.deleteDirOnExit(pathToChronicle); ChronicleTools.deleteOnExit(pathToChronicle); } try { this.chronicle = ChronicleQueueBuilder.vanilla(pathToChronicle) .cycleLength((int) this.queueRollingInterval).cycleFormat(this.cycleFormat).build(); this.queueConsumer = new DefaultStreamingMessageQueueConsumer(this.getId(), this.chronicle.createTailer(), this.queueWaitStrategy); this.queueProducer = new DefaultStreamingMessageQueueProducer(this.getId(), this.chronicle.createAppender(), this.queueWaitStrategy); } catch (IOException e) { throw new RuntimeException( "Failed to initialize chronicle at '" + pathToChronicle + "'. Error: " + e.getMessage()); } logger.info("queue[type=chronicle, id=" + this.id + ", deleteOnExist=" + this.deleteOnExit + ", path=" + pathToChronicle + "']"); }