List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast
public static String substringAfterLast(final String str, final String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.inkubator.hrm.web.ImageBioDataStreamerController.java
public StreamedContent getSertifikasiFile() throws IOException { FacesContext context = FacesUtil.getFacesContext(); String id = context.getExternalContext().getRequestParameterMap().get("id"); if (context.getRenderResponse() || id == null) { return new DefaultStreamedContent(); } else {//from w ww .j a v a 2s . c o m InputStream is = null; try { BioSertifikasi bioSertifikasi = bioSertifikasiService.getEntiyByPK(Long.parseLong(id)); String path = bioSertifikasi.getUploadPath(); if (StringUtils.isEmpty(path)) { path = facesIO.getPathUpload() + "no_image.png"; } is = facesIO.getInputStreamFromURL(path); return new DefaultStreamedContent(is, null, StringUtils.substringAfterLast(path, "/")); } catch (Exception ex) { LOGGER.error(ex, ex); return new DefaultStreamedContent(); } } }
From source file:com.inkubator.hrm.service.impl.BioSertifikasiServiceImpl.java
private String getUploadPath(Long id, UploadedFile documentFile) { String extension = StringUtils.substringAfterLast(documentFile.getFileName(), "."); String uploadPath = facesIO.getPathUpload() + "biosertifikasi_" + id + "." + extension; return uploadPath; }
From source file:com.nridge.ds.solr.SolrResponseBuilder.java
public void updateHeader(String aBaseURL, String aQuery, String aRequestHandler, int anOffset, int aLimit) { Logger appLogger = mAppMgr.getLogger(this, "updateHeader"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); Relationship headerRelationship = mDocument.getFirstRelationship(Solr.RESPONSE_HEADER); if (headerRelationship != null) { DataBag headerBag = headerRelationship.getBag(); if (StringUtils.isNotEmpty(aBaseURL)) { headerBag.setValueByName("base_url", aBaseURL); String collectionName = headerBag.getValueAsString("collection_name"); if (StringUtils.isEmpty(collectionName)) { collectionName = StringUtils.substringAfterLast(aBaseURL, "/"); headerBag.setValueByName("collection_name", collectionName); }/*w ww. jav a2 s . c om*/ } if (StringUtils.isNotEmpty(aQuery)) headerBag.setValueByName("query_keyword", aQuery); if (aLimit > 0) headerBag.setValueByName("page_size", aLimit); if (anOffset > -1) headerBag.setValueByName("offset_start", anOffset); if (StringUtils.isNotEmpty(aRequestHandler)) { if (aRequestHandler.charAt(0) == StrUtl.CHAR_FORWARDSLASH) headerBag.setValueByName("request_handler", aRequestHandler); else headerBag.setValueByName("request_handler", StrUtl.CHAR_FORWARDSLASH + aRequestHandler); } } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:com.xpn.xwiki.plugin.watchlist.WatchListEvent.java
/** * Compute the HTML diff for a given property. * /*from ww w . j a v a2 s . c o m*/ * @param objectDiff object diff object * @param diff the diff plugin API * @return the HTML diff * @throws XWikiException if the diff plugin fails to compute the HTML diff */ private String getPropertyHTMLDiff(ObjectDiff objectDiff, DiffPluginApi diff) throws XWikiException { String propDiff = diff.getDifferencesAsHTML(objectDiff.getPrevValue().toString(), objectDiff.getNewValue().toString(), false); // We hide PasswordClass properties and properties named "email" from notifications for security reasons. if ((objectDiff.getPropType().equals(StringUtils.substringAfterLast(PasswordClass.class.getName(), ".")) || objectDiff.getPropName().equals(EMAIL_PROPERTY_NAME)) && !StringUtils.isBlank(propDiff)) { propDiff = HIDDEN_PROPERTIES_OBFUSCATED_VALUE; } return propDiff; }
From source file:com.clickha.nifi.processors.FetchFileTransferV2.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();/* ww w .ja v a 2 s .c om*/ if (flowFile == null) { return; } final StopWatch stopWatch = new StopWatch(true); final String host = context.getProperty(HOSTNAME).evaluateAttributeExpressions(flowFile).getValue(); final int port = context.getProperty(UNDEFAULTED_PORT).evaluateAttributeExpressions(flowFile).asInteger(); final String filename = context.getProperty(REMOTE_FILENAME).evaluateAttributeExpressions(flowFile) .getValue(); // Try to get a FileTransfer object from our cache. BlockingQueue<FileTransferIdleWrapper> transferQueue; synchronized (fileTransferMap) { final Tuple<String, Integer> tuple = new Tuple<>(host, port); transferQueue = fileTransferMap.get(tuple); if (transferQueue == null) { transferQueue = new LinkedBlockingQueue<>(); fileTransferMap.put(tuple, transferQueue); } // periodically close idle connections if (System.currentTimeMillis() - lastClearTime > IDLE_CONNECTION_MILLIS) { closeConnections(false); lastClearTime = System.currentTimeMillis(); } } // we have a queue of FileTransfer Objects. Get one from the queue or create a new one. FileTransferV2 transfer; FileTransferIdleWrapper transferWrapper = transferQueue.poll(); if (transferWrapper == null) { transfer = createFileTransfer(context); } else { transfer = transferWrapper.getFileTransfer(); } // Pull data from remote system. final InputStream in; try { in = transfer.getInputStream(filename, flowFile); flowFile = session.write(flowFile, new OutputStreamCallback() { @Override public void process(final OutputStream out) throws IOException { StreamUtils.copy(in, out); transfer.flush(); } }); transferQueue.offer(new FileTransferIdleWrapper(transfer, System.nanoTime())); } catch (final FileNotFoundException e) { getLogger().error( "Failed to fetch content for {} from filename {} on remote host {} because the file could not be found on the remote system; routing to {}", new Object[] { flowFile, filename, host, REL_NOT_FOUND.getName() }); session.transfer(session.penalize(flowFile), REL_NOT_FOUND); session.getProvenanceReporter().route(flowFile, REL_NOT_FOUND); return; } catch (final PermissionDeniedException e) { getLogger().error( "Failed to fetch content for {} from filename {} on remote host {} due to insufficient permissions; routing to {}", new Object[] { flowFile, filename, host, REL_PERMISSION_DENIED.getName() }); session.transfer(session.penalize(flowFile), REL_PERMISSION_DENIED); session.getProvenanceReporter().route(flowFile, REL_PERMISSION_DENIED); return; } catch (final ProcessException | IOException e) { try { transfer.close(); } catch (final IOException e1) { getLogger().warn("Failed to close connection to {}:{} due to {}", new Object[] { host, port, e.toString() }, e); } getLogger().error( "Failed to fetch content for {} from filename {} on remote host {}:{} due to {}; routing to comms.failure", new Object[] { flowFile, filename, host, port, e.toString() }, e); session.transfer(session.penalize(flowFile), REL_COMMS_FAILURE); return; } // Add FlowFile attributes final String protocolName = transfer.getProtocolName(); final Map<String, String> attributes = new HashMap<>(); attributes.put(protocolName + ".remote.host", host); attributes.put(protocolName + ".remote.port", String.valueOf(port)); attributes.put(protocolName + ".remote.filename", filename); if (filename.contains("/")) { final String path = StringUtils.substringBeforeLast(filename, "/"); final String filenameOnly = StringUtils.substringAfterLast(filename, "/"); attributes.put(CoreAttributes.PATH.key(), path); attributes.put(CoreAttributes.FILENAME.key(), filenameOnly); } else { attributes.put(CoreAttributes.FILENAME.key(), filename); } flowFile = session.putAllAttributes(flowFile, attributes); // emit provenance event and transfer FlowFile session.getProvenanceReporter().fetch(flowFile, protocolName + "://" + host + ":" + port + "/" + filename, stopWatch.getElapsed(TimeUnit.MILLISECONDS)); session.transfer(flowFile, REL_SUCCESS); // it is critical that we commit the session before moving/deleting the remote file. Otherwise, we could have a situation where // we ingest the data, delete/move the remote file, and then NiFi dies/is shut down before the session is committed. This would // result in data loss! If we commit the session first, we are safe. session.commit(); final String completionStrategy = context.getProperty(COMPLETION_STRATEGY).getValue(); if (COMPLETION_DELETE.getValue().equalsIgnoreCase(completionStrategy)) { try { transfer.deleteFile(null, filename); } catch (final FileNotFoundException e) { // file doesn't exist -- effectively the same as removing it. Move on. } catch (final IOException ioe) { getLogger().warn( "Successfully fetched the content for {} from {}:{}{} but failed to remove the remote file due to {}", new Object[] { flowFile, host, port, filename, ioe }, ioe); } } else if (COMPLETION_MOVE.getValue().equalsIgnoreCase(completionStrategy)) { String targetDir = context.getProperty(MOVE_DESTINATION_DIR).evaluateAttributeExpressions(flowFile) .getValue(); if (!targetDir.endsWith("/")) { targetDir = targetDir + "/"; } final String simpleFilename = StringUtils.substringAfterLast(filename, "/"); final String target = targetDir + simpleFilename; try { transfer.rename(filename, target); } catch (final IOException ioe) { getLogger().warn( "Successfully fetched the content for {} from {}:{}{} but failed to rename the remote file due to {}", new Object[] { flowFile, host, port, filename, ioe }, ioe); } } }
From source file:com.inkubator.hrm.web.employee.EmpDataDetilController.java
public String doBack() throws Exception { if (isFromSearchEmployee) { /* /*from w w w . ja v a 2 s . c o m*/ * Jika berasal dari flow pencarian karyawan, * dapatkan real idFlowExecution dari urlBackToSearchEmployee yang sudah di insialisasi di awal load controller * lalu redirect ke URL /flow-protected/search_employee?+idFlowExecution */ ExternalContext context = FacesUtil.getExternalContext(); String idFlowExecution = StringUtils.substringAfterLast(urlBackToSearchEmployee, "?"); //Hapus dahulu flag dari sessionMap untuk agar ketika buka dari emp_placement_view, maka return nya sudah mengikuti behaviour normal Map<String, Object> sessionMap = context.getSessionMap(); sessionMap.remove("isFromSearchEmployee"); sessionMap.remove("urlBackToSearchEmployee"); //redirect ke halaman pencarian karyawan context.redirect( context.getRequestContextPath() + "/flow-protected/search_employee?" + idFlowExecution); return null; } return "/protected/personalia/emp_background_view.htm?faces-redirect=true"; }
From source file:io.wcm.handler.mediasource.inline.InlineRendition.java
@Override public String getFileExtension() { return StringUtils.substringAfterLast(this.fileName, "."); }
From source file:com.inkubator.hrm.web.ImageBioDataStreamerController.java
public StreamedContent getOhsaIncidentDocumentFile() throws IOException { FacesContext context = FacesUtil.getFacesContext(); String id = context.getExternalContext().getRequestParameterMap().get("id"); if (context.getRenderResponse() || id == null) { return new DefaultStreamedContent(); } else {/*from ww w .j ava2 s . co m*/ InputStream is = null; try { OhsaIncidentDocument ohsaIncidentDocument = ohsaIncidentDocumentService .getEntiyByPK(Integer.parseInt(id)); String path = ohsaIncidentDocument.getUploadedPath(); if (StringUtils.isEmpty(path)) { path = facesIO.getPathUpload() + "no_image.png"; } is = facesIO.getInputStreamFromURL(path); return new DefaultStreamedContent(is, null, StringUtils.substringAfterLast(path, "/")); } catch (Exception ex) { LOGGER.error(ex, ex); return new DefaultStreamedContent(); } } }
From source file:com.adobe.acs.commons.mcp.impl.processes.asset.AssetIngestor.java
protected CheckedConsumer<ResourceResolver> importAsset(final Source source, ActionManager actionManager) { return (ResourceResolver r) -> { createFolderNode(source.getElement().getParent(), r); actionManager.setCurrentItem(source.getElement().getItemName()); HierarchialElement el = source.getElement(); String path = source.getElement().getNodePath(); if (null != el && el.isFile() && el.getName().contains(".") && !preserveFileName) { String baseName = StringUtils.substringBeforeLast(el.getName(), "."); String extension = StringUtils.substringAfterLast(el.getName(), "."); path = (el.getParent() == null ? el.getJcrBasePath() : el.getParent().getNodePath()) + "/" + JcrUtil.createValidName(baseName, JcrUtil.HYPHEN_LABEL_CHAR_MAPPING, "-") + "." + JcrUtil.createValidName(extension, JcrUtil.HYPHEN_LABEL_CHAR_MAPPING, "-"); }/*from w ww .j a v a 2 s .com*/ handleExistingAsset(source, path, r); }; }
From source file:com.inkubator.hrm.web.ImageBioDataStreamerController.java
public StreamedContent getReferenceDocumentFile() throws IOException { FacesContext context = FacesUtil.getFacesContext(); String id = context.getExternalContext().getRequestParameterMap().get("id"); if (context.getRenderResponse() || id == null) { return new DefaultStreamedContent(); } else {//from w w w .j a va 2 s. c om InputStream is = null; try { Document document = documentService.getEntiyByPK(Long.parseLong(id)); String path = document.getUploadPath(); if (StringUtils.isEmpty(path)) { path = facesIO.getPathUpload() + "no_image.png"; } is = facesIO.getInputStreamFromURL(path); return new DefaultStreamedContent(is, null, StringUtils.substringAfterLast(path, "/")); } catch (Exception ex) { LOGGER.error(ex, ex); return new DefaultStreamedContent(); } } }