List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:com.amalto.core.server.Initialization.java
@Override public void onApplicationEvent(ContextRefreshedEvent event) { String version = Version.getSimpleVersionAsString(Initialization.class); LOGGER.info("======================================================="); //$NON-NLS-1$ LOGGER.info("Talend MDM " + version); //$NON-NLS-1$ LOGGER.info("======================================================="); //$NON-NLS-1$ //TMDM-2933: ThreadIsolatedSystemProperties allows threads to get different system properties when needed. previousSystemProperties = System.getProperties(); System.setProperties(ThreadIsolatedSystemProperties.getInstance()); LOGGER.info("Enabled system properties isolation for threads."); //$NON-NLS-1$ // Initializes server now if (serverLifecycle == null) { throw new IllegalStateException( "Server lifecycle is not set (is server running on a supported platform?)"); //$NON-NLS-1$ }/*from w ww .j a v a2 s . com*/ final Server server = ServerContext.INSTANCE.get(serverLifecycle); server.init(); // Initialize system storage LOGGER.info("Starting system storage..."); //$NON-NLS-1$ final StorageAdmin storageAdmin = server.getStorageAdmin(); String systemDataSourceName = storageAdmin.getDatasource(StorageAdmin.SYSTEM_STORAGE); storageAdmin.create(StorageAdmin.SYSTEM_STORAGE, StorageAdmin.SYSTEM_STORAGE, StorageType.SYSTEM, systemDataSourceName); Storage systemStorage = storageAdmin.get(StorageAdmin.SYSTEM_STORAGE, StorageType.SYSTEM); if (systemStorage == null) { LOGGER.error("System storage could not start."); //$NON-NLS-1$ throw new IllegalStateException("Could not start server (unable to initialize system storage)."); //$NON-NLS-1$ } else { LOGGER.info("System storage started."); //$NON-NLS-1$ } // Migration LOGGER.info("Initialization and migration of system database..."); //$NON-NLS-1$ AssembleConcreteBuilder concreteBuilder = new AssembleConcreteBuilder(); AssembleDirector director = new AssembleDirector(concreteBuilder); director.constructAll(); final AssembleProc assembleProc = concreteBuilder.getAssembleProc(); SecurityConfig.invokeSynchronousPrivateInternal(new Runnable() { @Override public void run() { assembleProc.run(); } }); LOGGER.info("Initialization and migration done."); //$NON-NLS-1$ // Find configured containers MetadataRepository repository = systemStorage.getMetadataRepository(); String className = StringUtils.substringAfterLast(DataClusterPOJO.class.getName(), "."); //$NON-NLS-1$ ComplexTypeMetadata containerType = repository.getComplexType(ClassRepository.format(className)); UserQueryBuilder qb = from(containerType); final Set<String> containerNames = new HashSet<String>(); systemStorage.begin(); try { StorageResults containers = systemStorage.fetch(qb.getSelect()); for (DataRecord container : containers) { String name = String.valueOf(container.get("name")); //$NON-NLS-1$ if (!DispatchWrapper.isMDMInternal(name)) { containerNames.add(name); } } systemStorage.commit(); } catch (Exception e) { systemStorage.rollback(); throw new RuntimeException("Could not list configured containers", e); //$NON-NLS-1$ } // Log configured containers StringBuilder containerNamesLog = new StringBuilder(); containerNamesLog.append('[').append(' '); for (String containerName : containerNames) { containerNamesLog.append(containerName).append(' '); } containerNamesLog.append(']'); LOGGER.info("Container to initialize (" + containerNames.size() + " found) : " + containerNamesLog); //$NON-NLS-1$ //$NON-NLS-2$ // Initialize configured containers SecurityConfig.invokeSynchronousPrivateInternal(new Runnable() { @Override public void run() { initContainers(server, storageAdmin, containerNames); } }); LOGGER.info("Talend MDM " + version + " started."); //$NON-NLS-1$ //$NON-NLS-2$ if (this.applicationEventPublisher != null) { this.applicationEventPublisher.publishEvent(new MDMInitializationCompletedEvent(this)); } }
From source file:eionet.cr.staging.FileDownloader.java
/** * Derives a name for the file to be downloaded from the given {@link URLConnection}. * * @param connection The given {@link URLConnection}. * @return The derived file name./*ww w. j a va 2 s. co m*/ */ private String getFileName(URLConnection connection) { // If file name already given, just return it. if (StringUtils.isNotBlank(newFileName)) { return newFileName; } // Attempt detection from the response's "Content-Disposition" header. String contentDisposition = connection.getHeaderField("Content-Disposition"); if (StringUtils.isNotBlank(contentDisposition)) { String s = StringUtils.substringAfter(contentDisposition, "filename"); if (StringUtils.isNotBlank(s)) { s = StringUtils.substringAfter(s, "="); if (StringUtils.isNotBlank(s)) { s = StringUtils.substringAfter(s, "\""); if (StringUtils.isNotBlank(s)) { s = StringUtils.substringBefore(s, "\""); if (StringUtils.isNotBlank(s)) { return s.trim(); } } } } } // // Attempt detection from the response's "Content-Location" header. // String contentLocation = connection.getHeaderField("Content-Location"); // if (StringUtils.isNotBlank(contentLocation)) { // String s = new File(contentLocation).getName(); // if (StringUtils.isNotBlank(s)) { // return s.trim(); // } // } // // Attempt detection from the URL itself. String s = StringUtils.substringAfterLast(connection.getURL().toString(), "#"); if (StringUtils.isBlank(s)) { s = StringUtils.substringAfterLast(connection.getURL().toString(), "/"); } if (StringUtils.isNotBlank(s)) { // Remove all characters that are not one of these: a latin letter, a digit, a minus, a dot, an underscore. s = s.replaceAll("[^a-zA-Z0-9-._]+", ""); } // If still no success, then just generate a hash from the URL. return StringUtils.isBlank(s) ? DigestUtils.md5Hex(connection.getURL().toString()) : s; }
From source file:com.twitter.finagle.common.zookeeper.Group.java
/** * Returns the member id given a node path. */// w w w .j ava2 s . c o m public String getMemberId(String nodePath) { MorePreconditions.checkNotBlank(nodePath); Preconditions.checkArgument(nodePath.startsWith(path + "/"), "Not a member of this group[%s]: %s", path, nodePath); String memberId = StringUtils.substringAfterLast(nodePath, "/"); Preconditions.checkArgument(nodeScheme.isMember(memberId), "Not a group member: %s", memberId); return memberId; }
From source file:de.pdark.dsmp.RequestHandler.java
private void serveURL(String downloadURL, boolean headOnly) throws IOException { URL url = new URL(downloadURL); url = config.getMirror(url);//from www .java 2 s . co m if (!"http".equals(url.getProtocol())) throw new IOException("Can only handle HTTP requests, got " + downloadURL); File f = getPatchFile(url); if (!f.exists()) f = getCacheFile(url, config.getCacheDirectory()); if (!f.exists()) { ProxyDownload d = new ProxyDownload(url, f, config); try { d.download(); } catch (DownloadFailed e) { log.error(e.getMessage()); println(e.getStatusLine()); println(); getOut().flush(); return; } } else { log.debug("Serving from local cache " + f.getAbsolutePath()); } println("HTTP/1.1 200 OK"); print("Date: "); Date d = new Date(f.lastModified()); println(INTERNET_FORMAT.format(d)); print("Content-length: "); println(String.valueOf(f.length())); print("Content-type: "); String ext = StringUtils.substringAfterLast(downloadURL, ".").toLowerCase(); String type = CONTENT_TYPES.get(ext); if (type == null) { log.warn("Unknown extension " + ext + ". Using content type text/plain."); type = "text/plain"; } println(type); println(); if (headOnly) { log.info("HEAD for : " + url.toExternalForm()); downloadLog.info("Downloaded: " + url.toExternalForm()); return; } InputStream data = new BufferedInputStream(new FileInputStream(f)); IOUtils.copy(data, out); data.close(); downloadLog.info("Downloaded: " + url.toExternalForm()); }
From source file:com.twitter.common.zookeeper.Group.java
public String getMemberId(String nodePath) { MorePreconditions.checkNotBlank(nodePath); Preconditions.checkArgument(nodePath.startsWith(path + "/"), "Not a member of this group[%s]: %s", path, nodePath);//from w w w .j av a 2 s .c om String memberId = StringUtils.substringAfterLast(nodePath, "/"); Preconditions.checkArgument(nodeScheme.isMember(memberId), "Not a group member: %s", memberId); return memberId; }
From source file:br.usp.ime.lapessc.xflow2.core.VCSMiner.java
private List<FileArtifact> getEntryFiles(CommitDTO dto) { List<FileArtifact> files = new ArrayList<FileArtifact>(); for (FileArtifactDTO fileDTO : dto.getFileArtifacts()) { FileArtifact file = new FileArtifact(); //If the file is replaced, we treat it as if it had been modified if (fileDTO.getOperationType() == 'R') file.setOperationType('M'); else/*from w ww. j a v a 2 s .c o m*/ file.setOperationType(fileDTO.getOperationType()); file.setPath(fileDTO.getPath()); String fileName = StringUtils.substringAfterLast(file.getPath(), "/"); file.setName(fileName); String fileExtension = StringUtils.substringAfterLast(fileName, "."); file.setExtesion(fileExtension); file.setSourceCode(fileDTO.getSourceCode()); file.setDiffCode(fileDTO.getDiffCode()); files.add(file); } return files; }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
private void insertSnapshot(Path snapshotPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(snapshotPath.toString(), Path.SEPARATOR); String snapshotName = StringUtils.substringAfterLast(snapshotPath.toString(), Path.SEPARATOR); long ts = Long.parseLong(StringUtils.substringBefore(snapshotName, "-PT-")); long recordCount = Long.parseLong(StringUtils.substringAfter(snapshotName, "-PT-")); PreparedStatement insert = connection.prepareStatement("INSERT INTO Snapshots VALUES (?, ?, ?, ?, ?)"); insert.setString(1, datasetPath);/* www . j a v a 2s .c o m*/ insert.setString(2, snapshotName); insert.setString(3, snapshotPath.toString()); insert.setTimestamp(4, new Timestamp(ts)); insert.setLong(5, recordCount); insert.executeUpdate(); }
From source file:edu.ku.brc.specify.tools.FormGenerator.java
public void generateForms() { SpViewSetObj viewSetObj = new SpViewSetObj(); viewSetObj.initialize();/* w w w .j a v a 2s .co m*/ viewSetObj.setName("All Forms"); SpUIViewSet viewSet = new SpUIViewSet(); viewSet.initialize(); viewSet.setName("All Forms"); for (DBTableInfo ti : DBTableIdMgr.getInstance().getTables()) { String tName = ti.getShortClassName(); if (tName.startsWith("Sp") || tName.startsWith("User")) { continue; } SpUIView view = new SpUIView(); view.initialize(); view.setBusinessRulesClassName(ti.getBusinessRuleName()); view.setName(tName); view.setSpViewSet(viewSet); viewSet.getSpViews().add(view); SpUIAltView altViewView = new SpUIAltView(); altViewView.initialize(); altViewView.setName(tName + " View"); altViewView.setDefault(true); altViewView.setMode(AltViewIFace.CreationMode.VIEW); SpUIAltView altViewEdit = new SpUIAltView(); altViewEdit.initialize(); altViewEdit.setName(tName + " Edit"); altViewEdit.setDefault(true); altViewEdit.setMode(AltViewIFace.CreationMode.EDIT); view.getSpAltViews().add(altViewView); view.getSpAltViews().add(altViewEdit); SpUIViewDef viewDef = new SpUIViewDef(); viewDef.initialize(); viewDef.setName(tName); viewDef.setColDef("100px,2px,p,p:g"); viewDef.createAutoRowDef("p", "2px"); viewDef.setDescription("Form For " + tName); viewDef.setType(ViewDefIFace.ViewType.form); viewDef.setDataClassName(ti.getClassName()); viewDef.setSettableName(FormHelper.DATA_OBJ_SETTER); viewDef.setGettableName(FormHelper.DATA_OBJ_GETTER); altViewView.setViewDef(viewDef); altViewEdit.setViewDef(viewDef); viewSet.getSpViewDefs().add(viewDef); viewDef.setSpViewSet(viewSet); SpUIRow row = new SpUIRow(); row.initialize(); viewDef.addRow(row); SpUICell cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setLabel(ti.getTitle()); cell.setTypeName("separator"); int id = 1; for (DBFieldInfo fi : ti.getFields()) { String fName = fi.getName(); if (fName.startsWith("text") || fName.startsWith("yesNo") || fName.startsWith("number") || fName.startsWith("version") || fName.startsWith("collectionMember") || fName.startsWith("timestampCreated") || fName.startsWith("timestampModified") || fName.startsWith("createdByAgent") || fName.startsWith("modifiedByAgent")) { continue; } row = new SpUIRow(); row.initialize(); viewDef.addRow(row); // Label cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setTypeName("label"); cell.setLabelFor(Integer.toString(id)); // Field cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setTypeName("field"); cell.setIdent(Integer.toString(id)); cell.setName(fName); cell.setUiType(FormCellFieldIFace.FieldType.text); id++; } for (DBRelationshipInfo ri : ti.getRelationships()) { String rName = StringUtils.substringAfterLast(ri.getClassName(), "."); row = new SpUIRow(); row.initialize(); viewDef.addRow(row); if (ri.getType() == DBRelationshipInfo.RelationshipType.ManyToOne) { // Label cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setTypeName("label"); cell.setLabelFor(Integer.toString(id)); // Field cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setTypeName("field"); cell.setIdent(Integer.toString(id)); cell.setName(ri.getName()); cell.setUiType(FormCellFieldIFace.FieldType.querycbx); Properties props = new Properties(); props.put("title", rName); props.put("name", rName); cell.setProperties(props); } else if (ri.getType() == DBRelationshipInfo.RelationshipType.OneToMany) { // Separator cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setLabel(ri.getTitle()); cell.setTypeName("separator"); // SubView or QueryCBX cell = new SpUICell(); cell.initialize(); row.addCell(cell); cell.setIdent(Integer.toString(id)); cell.setTypeName("subview"); cell.setViewName(rName); cell.setName(ri.getName()); if (StringUtils.contains(rName.toLowerCase(), "attachment")) { Properties props = new Properties(); props.put("addsearch", "true"); props.put("btn", "true"); props.put("icon", rName); cell.setProperties(props); } } else if (ri.getType() == DBRelationshipInfo.RelationshipType.OneToOne) { System.out.println("Skipping OneToOne: " + tName + " - " + ri.getName()); } else if (ri.getType() == DBRelationshipInfo.RelationshipType.ManyToMany) { System.out.println("Skipping ManyToMany: " + tName + " - " + ri.getName()); } id++; } //break; } StringBuilder sb = new StringBuilder(); viewSet.toXML(sb); try { FileUtils.writeStringToFile(new File("allforms.views.xml"), sb.toString()); //System.out.println(sb.toString()); } catch (IOException ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(FormGenerator.class, ex); ex.printStackTrace(); } }
From source file:eionet.cr.web.action.factsheet.CompiledDatasetActionBean.java
/** * Gets the value and label from the data. * * @param data/*from ww w . j a v a2 s.c o m*/ * @return Array, where element 0 is value and 1 is label. */ private String[] getValueAndLabel(String data) { String[] result = new String[2]; result[0] = StringUtils.substringBeforeLast(data, WebConstants.FILTER_LABEL_SEPARATOR); result[1] = StringUtils.substringAfterLast(data, WebConstants.FILTER_LABEL_SEPARATOR); return result; }
From source file:edu.ku.brc.specify.utilapps.ERDTable.java
/** * @param p/*from w w w . j a v a 2s . com*/ * @param r * @param font * @param y * @param all * @return */ public JComponent build(final PanelBuilder p, final DBRelationshipInfo r, final Font font, final int y, boolean all) { String type = r.getType().toString().toLowerCase(); type = getResourceString(type); CellConstraints cc = new CellConstraints(); p.add(ERDVisualizer.mkLabel(font, StringUtils.substringAfterLast(r.getClassName(), "."), SwingConstants.LEFT), cc.xy(1, y)); p.add(ERDVisualizer.mkLabel(font, StringUtils.capitalize(r.getTitle()), SwingConstants.LEFT), cc.xy(3, y)); JComponent comp = ERDVisualizer.mkLabel(font, type, SwingConstants.CENTER); p.add(comp, cc.xy(5, y)); if (all) { comp = ERDVisualizer.mkLabel(font, r.isRequired() ? yesStr : "", SwingConstants.CENTER); p.add(comp, cc.xy(7, y)); } return comp; }