List of usage examples for org.apache.commons.lang3 StringUtils substringBefore
public static String substringBefore(final String str, final String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.kawanfw.sql.api.server.StatementAnalyser.java
/** * Returns the table name in use type from a DML SQL order. * /*from w w w . j av a2 s . com*/ * @return the table name in use (the first one in a <code>SELECT</code> * statement) for a DML statement. Returns null if statement is not * DML. */ public String getTableNameFromDmlStatement() throws IllegalArgumentException { // Extract the first order String statementTypeUpper = statementType.toUpperCase(); String sqlUpper = sql.toUpperCase(); // Extract the table depending on the ordOer sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper); sqlUpper = sqlUpper.trim(); String table = null; if (statementTypeUpper.equals(INSERT)) { sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO "); sqlUpper = sqlUpper.trim(); table = StringUtils.substringBefore(sqlUpper, " "); } else if (statementTypeUpper.equals(SELECT) || statementTypeUpper.equals(DELETE)) { sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM "); sqlUpper = sqlUpper.trim(); // Remove commas in the statement and replace with blanks in case we // have // a join: "TABLE," ==> "TABLE " sqlUpper = sqlUpper.replaceAll(",", " "); table = StringUtils.substringBefore(sqlUpper, BLANK); } else if (statementTypeUpper.equals(UPDATE)) { debug("sqlLocal :" + sqlUpper + ":"); table = StringUtils.substringBefore(sqlUpper, BLANK); } else { return null; // No table } debug("table: " + table); if (table != null) { table = table.trim(); } // Return the part after last dot if (table.contains(".")) { table = StringUtils.substringAfterLast(table, "."); } table = table.replace("\'", ""); table = table.replace("\"", ""); debug("table before return: " + table); return table; }
From source file:org.kawanfw.sql.tomcat.util.LinkedProperties.java
/** * Returns the properties name in the order of their position in a file. * //from w ww . java 2s . com * @param fileProperties * the file containing the properties * @return a Set of Strings backed by a LinkedHashSet ordererd by the * property position in the file * @throws IOException */ public static Set<String> getLinkedPropertiesName(File fileProperties) throws IOException { Set<String> linkedPropertiesName = new LinkedHashSet<String>(); BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new FileReader(fileProperties)); String line = null; while ((line = bufferedReader.readLine()) != null) { if (line.isEmpty()) { continue; } if (line.startsWith("#")) { continue; } if (line.startsWith("!")) { continue; } if (!line.contains("=")) { continue; } line = StringUtils.substringBefore(line, "="); line = line.trim(); linkedPropertiesName.add(line); } } finally { IOUtils.closeQuietly(bufferedReader); } return linkedPropertiesName; }
From source file:org.kawanfw.sql.util.FileNameFromBlobBuilder.java
/** * @return the raw file name of the file to create from the blob/clob column * with the content//w ww . ja v a 2 s . com */ public String getFileName() { String fileName = null; String unique = FrameworkFileUtil.getUniqueId(); sqlOrder = sqlOrder.trim(); String statementType = StringUtils.substringBefore(sqlOrder, BLANK); String tableName = getTableNameFromDmlStatement(statementType, sqlOrder); if (tableName == null) { tableName = "unknown"; } if (statementType == null) { statementType = "unknown"; } String blobHeader = "blob-"; if (isClob) { blobHeader = "clob-"; } if (columnName != null) { fileName = blobHeader + statementType.toLowerCase() + "-" + tableName.toLowerCase() + "." + columnName + "-" + unique + ".kawanfw"; } else { fileName = blobHeader + statementType.toLowerCase() + "-" + tableName.toLowerCase() + "-index-" + parameterIndex + "-" + unique + ".kawanfw"; } if (isClob) { fileName += ".txt"; } return fileName; }
From source file:org.kawanfw.sql.util.FileNameFromBlobBuilder.java
/** * Returns the table name in use type from a DML SQL order. * /*from ww w .ja v a 2 s . c om*/ * @param statementType * the statement type (INSERT, ...) * @param sql * the sql order * * @return the table name in use (the first one in a <code>SELECT</code> * statement) for a DML statement. Returns null if statement is not * DML. */ private String getTableNameFromDmlStatement(String statementType, String sql) throws IllegalArgumentException { // Extract the first order String statementTypeUpper = statementType.toUpperCase(); String sqlUpper = sql.toUpperCase(); // Extract the table depending on the ordOer sqlUpper = StringUtils.substringAfter(sqlUpper, statementTypeUpper); sqlUpper = sqlUpper.trim(); String table = null; if (statementTypeUpper.equals(INSERT)) { sqlUpper = StringUtils.substringAfter(sqlUpper, "INTO "); sqlUpper = sqlUpper.trim(); table = StringUtils.substringBefore(sqlUpper, " "); } else if (statementTypeUpper.equals(SELECT) || statementTypeUpper.equals(DELETE)) { sqlUpper = StringUtils.substringAfter(sqlUpper, "FROM "); sqlUpper = sqlUpper.trim(); // Remove commas in the statement and replace with blanks in case we // have // a join: "TABLE," ==> "TABLE " sqlUpper = sqlUpper.replaceAll(",", " "); table = StringUtils.substringBefore(sqlUpper, BLANK); } else if (statementTypeUpper.equals(UPDATE)) { // debug("sqlLocal :" + sqlUpper + ":"); table = StringUtils.substringBefore(sqlUpper, BLANK); } else { return null; // No table } if (table != null) { table = table.trim(); } // Return the part after last dot if (table.contains(".")) { table = StringUtils.substringAfterLast(table, "."); } table = table.replace("\'", ""); table = table.replace("\"", ""); return table; }
From source file:org.kawanfw.test.parms.ProxyLoader.java
public Proxy getProxy() throws IOException, URISyntaxException { if (FrameworkSystemUtil.isAndroid()) { return null; }// w w w . j av a 2 s . c o m System.setProperty("java.net.useSystemProxies", "true"); List<Proxy> proxies = ProxySelector.getDefault().select(new URI("http://www.google.com/")); if (proxies != null && proxies.size() >= 1) { System.out.println("Loading proxy file info..."); if (proxies.get(0).type().equals(Proxy.Type.DIRECT)) { return null; } File file = new File(NEOTUNNEL_TXT); if (file.exists()) { String proxyValues = FileUtils.readFileToString(file); String username = StringUtils.substringBefore(proxyValues, " "); String password = StringUtils.substringAfter(proxyValues, " "); username = username.trim(); password = password.trim(); proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 8080)); passwordAuthentication = new PasswordAuthentication(username, password.toCharArray()); System.out.println("USING PROXY WITH AUTHENTICATION: " + proxy + " / " + username + " " + password); } else { throw new FileNotFoundException("proxy values not found. No file " + file); } } return proxy; }
From source file:org.kitodo.forms.WorkflowForm.java
/** * Save updated content of the diagram.//from w ww . jav a 2 s .c o m */ private void saveFiles() { Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap(); xmlDiagram = requestParameterMap.get("diagram"); if (Objects.nonNull(xmlDiagram)) { svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator"); xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator"); saveXMLDiagram(); saveSVGDiagram(); } }
From source file:org.kitodo.production.forms.WorkflowForm.java
/** * Save content of the diagram files./*www.j av a 2s . c o m*/ * * @return true if save, false if not */ private boolean saveFiles() throws IOException, WorkflowException { Map<String, String> requestParameterMap = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap(); Map<String, URI> diagramsUris = getDiagramUris(); URI svgDiagramURI = diagramsUris.get(SVG_DIAGRAM_URI); URI xmlDiagramURI = diagramsUris.get(XML_DIAGRAM_URI); xmlDiagram = requestParameterMap.get("editForm:workflowTabView:xmlDiagram"); if (Objects.nonNull(xmlDiagram)) { svgDiagram = StringUtils.substringAfter(xmlDiagram, "kitodo-diagram-separator"); xmlDiagram = StringUtils.substringBefore(xmlDiagram, "kitodo-diagram-separator"); Reader reader = new Reader(new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8))); reader.validateWorkflowTasks(); Converter converter = new Converter( new ByteArrayInputStream(xmlDiagram.getBytes(StandardCharsets.UTF_8))); converter.validateWorkflowTaskList(); saveFile(svgDiagramURI, svgDiagram); saveFile(xmlDiagramURI, xmlDiagram); } return fileService.fileExist(xmlDiagramURI) && fileService.fileExist(svgDiagramURI); }
From source file:org.kuali.coeus.common.impl.KcViewHelperServiceImpl.java
public List<DataValidationItem> populateDataValidation() { List<DataValidationItem> dataValidationItems = new ArrayList<DataValidationItem>(); for (Map.Entry<String, AuditCluster> entry : getGlobalVariableService().getAuditErrorMap().entrySet()) { AuditCluster auditCluster = entry.getValue(); List<AuditError> auditErrors = auditCluster.getAuditErrorList(); String areaName = StringUtils.substringBefore(auditCluster.getLabel(), "."); String sectionName = StringUtils.substringAfter(auditCluster.getLabel(), "."); for (AuditError auditError : auditErrors) { DataValidationItem dataValidationItem = new DataValidationItem(); String pageId = StringUtils.substringBefore(auditError.getLink(), "."); String sectionId = StringUtils.substringAfter(auditError.getLink(), "."); ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setErrorKey(auditError.getMessageKey()); errorMessage.setMessageParameters(auditError.getParams()); dataValidationItem.setArea(areaName); dataValidationItem.setSection(sectionName); dataValidationItem.setDescription(KRADUtils.getMessageText(errorMessage, false)); dataValidationItem.setSeverity(auditCluster.getCategory()); dataValidationItem.setNavigateToPageId(pageId); dataValidationItem.setNavigateToSectionId(sectionId); dataValidationItems.add(dataValidationItem); }/*from w ww . ja v a 2 s .c o m*/ } Collections.sort(dataValidationItems, (o1, o2) -> o1.getArea().compareTo(o2.getArea())); return dataValidationItems; }
From source file:org.kuali.coeus.common.notification.impl.service.impl.KcNotificationServiceImpl.java
private List<NotificationRecipient.Builder> createRoleRecipients( List<NotificationTypeRecipient> roleRecipients) { List<NotificationRecipient.Builder> recipients = new ArrayList<NotificationRecipient.Builder>(); for (NotificationTypeRecipient roleRecipient : roleRecipients) { LOG.info("Processing recipient: " + roleRecipient.getRoleName() + " with " + roleRecipient.getRoleQualifiers().size() + " qualifiers."); String roleNamespace = StringUtils.substringBefore(roleRecipient.getRoleName(), Constants.COLON); String roleName = StringUtils.substringAfter(roleRecipient.getRoleName(), Constants.COLON); Collection<String> roleMembers = getRoleMemberPrincipalIds(roleNamespace, roleName, roleRecipient.getRoleQualifiers()); for (String roleMember : roleMembers) { NotificationRecipient.Builder recipient = NotificationRecipient.Builder.create(); try { recipient.setRecipientId(getPersonUserName(roleMember)); recipient.setRecipientType(MemberType.PRINCIPAL.getCode()); recipients.add(recipient); } catch (IllegalArgumentException e) { // Quietly ignore recipients that no longer exist LOG.info("Invalid recipient", e); }/*from w w w. j a v a2 s. c om*/ } } return recipients; }
From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentDocumentForm.java
protected List<String> getUnitRulesMessages(String messageType) { List<String> messages = new ArrayList<String>(); for (String message : this.unitRulesMessages) { if (StringUtils.substringBefore(message, KcKrmsConstants.MESSAGE_SEPARATOR).equals(messageType)) { messages.add(StringUtils.substringAfter(message, KcKrmsConstants.MESSAGE_SEPARATOR)); }/* w w w . ja v a 2s . c o m*/ } return messages; }