List of usage examples for java.lang System lineSeparator
String lineSeparator
To view the source code for java.lang System lineSeparator.
Click Source Link
From source file:com.osparking.attendant.AttListForm.java
private void multiFuncButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multiFuncButtonActionPerformed String[] errorMsg = new String[1]; try {//ww w . j a va 2 s .co m switch (formMode) { case NormalMode: // <editor-fold defaultstate="collapsed" desc="-- Prepare to update user information"> setFormMode(FormMode.UpdateMode); multiFuncButton.setText(SAVE_BTN.getContent()); multiFuncButton.setEnabled(false); multiFuncButton.setMnemonic('s'); setModificationState(true); // change to modification mode createButton.setEnabled(false); deleteButton.setEnabled(false); break; // </editor-fold> case UpdateMode: // <editor-fold defaultstate="collapsed" desc="-- save modified user information "> if (allFieldsAreGood(errorMsg)) { // each field satisfies data requirements setFormMode(FormMode.NormalMode); multiFuncButton.setText(MODIFY_BTN.getContent()); multiFuncButton.setMnemonic('m'); setModificationState(false); int result = saveUpdatedRecord(); doAfterUpdateOperations(result); } else { if (errorMsg[0].length() > 0) { showMessageDialog(this, errorMsg[0]); } } break; // </editor-fold> case CreateMode: // <editor-fold defaultstate="collapsed" desc="-- Complete user creation operation"> if (!ID_usable) { JOptionPane.showConfirmDialog(this, ID_CHECK_DIALOG.getContent(), CREATTION_FAIL_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); return; } if (!Email_usable) { JOptionPane.showConfirmDialog(this, EMAIL_CHECK_DIALOG.getContent(), CREATTION_FAIL_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); return; } if (allFieldsAreGood(errorMsg)) { String newUserID = userIDText.getText().trim(); int result = saveCreatedRecord(); String dialogText = ""; if (result == 1) { // 1 record inserted == insertion success. // <editor-fold defaultstate="collapsed" desc="-- Refresh user list while maintaining sort order"> List sortKeys = usersTable.getRowSorter().getSortKeys(); /** * List newly created user on the list in any case. */ loadAttendantTable(newUserID); usersTable.getRowSorter().setSortKeys(sortKeys); int selectIndex = searchRow(newUserID); if (selectIndex < 0) selectIndex = 0; usersTable.changeSelection(selectIndex, 0, false, false); usersTable.requestFocus(); changeFieldButtonUsability(selectIndex); // </editor-fold> revokeCreationMode(); dialogText = ATT_CREATE_DIAG_1.getContent() + System.lineSeparator() + ATT_CREATE_DIAG_2.getContent() + newUserID; JOptionPane.showMessageDialog(this, dialogText, CREATION_RESULT_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); } else { dialogText = ATT_FAILED_DIAG_1.getContent() + System.lineSeparator() + ATT_CREATE_DIAG_2.getContent() + newUserID; showMessageDialog(this, dialogText, CREATION_RESULT_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); } } else { if (errorMsg[0].length() > 0) { showMessageDialog(this, errorMsg[0], USER_FIELD_CHECK_RESULT.getContent(), JOptionPane.WARNING_MESSAGE); } } break; // </editor-fold> default: } } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(User requested command: " + evt.getActionCommand() + ")"); } }
From source file:com.osparking.attendant.AttListForm.java
private boolean allFieldsAreGood(String[] errorMsg) { // ID is unchangable. So, check other fields if their format is good to use. Other fields include // name, cell phone number, phone number, new password, etc. // <editor-fold defaultstate="collapsed" desc="-- Syntax check of each field"> StringBuilder wrongFields = new StringBuilder(); // name should be longer than 2 characters if (userNameText.getText().trim().length() <= 1) { wrongFields.append(ATT_NAME_CHECK_DIALOG.getContent() + System.lineSeparator()); userNameText.requestFocus();//from w w w. j ava2 s. c o m } // given cellphone number exists, it should be longer than 10 String cellPhone = cellPhoneText.getText().trim(); int cellDigCount = getNumericDigitCount(cellPhone); if (cellPhone.length() > 0 && cellDigCount != 10 && cellDigCount != 11) { if (wrongFields.toString().length() == 0) cellPhoneText.requestFocus(); wrongFields.append(ATT_CELL_CHECK_DIALOG.getContent() + System.lineSeparator()); } // given phone number exists, it should be longer than 4 // some phone number is just the extension number of a company String phoneNumber = phoneText.getText().trim(); int phDigCount = getNumericDigitCount(phoneNumber); if (phoneNumber.length() > 0 && phDigCount < 4) { if (wrongFields.toString().length() == 0) phoneText.requestFocus(); wrongFields.append(PHONE_CHECK_DIALOG.getContent() + System.lineSeparator()); } // one of cell or phone should be supplied if ((cellDigCount == 0) && (phDigCount == 0)) { if (wrongFields.toString().length() == 0) cellPhoneText.requestFocus(); wrongFields.append(CELL_PHONE_CHECK_DIALOG.getContent() + System.lineSeparator()); } // when password is to be updated // supply new password and identical confirmation of it if (changePWCheckBox.isSelected()) { if (pwValidator.isInValidForm(new String(new1Password.getPassword()))) { String pass1 = new String(new1Password.getPassword()); String pass2 = new String(new2Password.getPassword()); if (!pass1.equals(pass2)) { if (wrongFields.toString().length() == 0) new1Password.requestFocus(); wrongFields.append(REPEAT_PW_CHECK_ERROR.getContent() + System.lineSeparator()); } } else { if (wrongFields.toString().length() == 0) new1Password.requestFocus(); wrongFields.append(PASSWORD_CHECK_DIALOG.getContent() + System.lineSeparator()); } } // </editor-fold> boolean result = false; // Check if current password matched DB stored one if (passwordMatched(loginID, new String(userPassword.getPassword()))) { if (wrongFields.length() == 0) { result = true; } else { result = false; } } else { if (wrongFields.toString().length() == 0) userPassword.requestFocus(); wrongFields.append(" - " + loginID + ADMIN_PW_CHECK_DIALOG.getContent() + System.lineSeparator()); result = false; } errorMsg[0] = wrongFields.toString(); return result; }
From source file:com.basistech.rosette.api.RosetteAPI.java
/** * Gets response from HTTP connection, according to the specified response class; * throws for an error response.// w ww.jav a 2s .c o m * * @param httpResponse the response object * @param clazz Response class * @return Response * @throws IOException * @throws RosetteAPIException if the status is not 200. */ private <T extends Response> T getResponse(HttpResponse httpResponse, Class<T> clazz) throws IOException, RosetteAPIException { int status = httpResponse.getStatusLine().getStatusCode(); String encoding = headerValueOrNull(httpResponse.getFirstHeader(HttpHeaders.CONTENT_ENCODING)); try (InputStream stream = httpResponse.getEntity().getContent(); InputStream inputStream = "gzip".equalsIgnoreCase(encoding) ? new GZIPInputStream(stream) : stream) { String ridHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-DocumentRequest-Id")); if (HTTP_OK != status) { String ecHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Code")); String emHeader = headerValueOrNull(httpResponse.getFirstHeader("X-RosetteAPI-Status-Message")); String responseContentType = headerValueOrNull( httpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE)); if ("application/json".equals(responseContentType)) { ErrorResponse errorResponse = mapper.readValue(inputStream, ErrorResponse.class); if (ridHeader != null) { LOG.debug("DocumentRequest ID " + ridHeader); } if (ecHeader != null) { errorResponse.setCode(ecHeader); } if (429 == status) { String concurrencyMessage = "You have exceeded your plan's limit on concurrent calls. " + "This could be caused by multiple processes or threads making Rosette API calls in parallel, " + "or if your httpClient is configured with higher concurrency than your plan allows."; if (emHeader == null) { emHeader = concurrencyMessage; } else { emHeader = concurrencyMessage + System.lineSeparator() + emHeader; } } if (emHeader != null) { errorResponse.setMessage(emHeader); } throw new RosetteAPIException(status, errorResponse); } else { String errorContent; if (inputStream != null) { byte[] content = getBytes(inputStream); errorContent = new String(content, "utf-8"); } else { errorContent = "(no body)"; } // something not from us at all throw new RosetteAPIException(status, new ErrorResponse("invalidErrorResponse", errorContent)); } } else { return mapper.readValue(inputStream, clazz); } } }
From source file:com.osparking.attendant.AttListForm.java
private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed try {//from w w w . jav a 2 s . c o m // When deleting a user account, to compare user password (stored at a login time) // with the password entered in the delete form, dual table in the MySQL is needed. String pwHashed = getHashedPW(new String(userPassword.getPassword())); String dialogText = ""; if (loginPW.equals(pwHashed)) { // Get a confirmation from the user for the deletion. dialogText = ATT_DELETE_DIALOG.getContent() + System.lineSeparator() + ID_LABEL.getContent() + userIDText.getText(); int result = JOptionPane.showConfirmDialog(this, dialogText, DELETE_DIALOGTITLE.getContent(), JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { deleteAttendant(); } else { // Clear password entered userPassword.setText(""); } } else { showMessageDialog(this, DELETE_FAIL_DAILOG.getContent() + System.lineSeparator(), DELETE_FAIL_DAILOGTITLE.getContent(), JOptionPane.INFORMATION_MESSAGE); userPassword.requestFocus(); } //throw new Exception("dummy"); } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(User Action: user account deletion)"); } }
From source file:com.osparking.attendant.AttListForm.java
private void deleteAttendant() { /**//from www . ja v a 2 s . com * Check if the user/attendant were deletable (not referenced from other tuple) * This checking involves two tables: Car_Arrival, LoginRecord */ Connection conn = null; PreparedStatement updateStmt = null; String deleteID = userIDText.getText(); int relatedRecordCount = DB_Access.getRecordCount("car_arrival", "AttendantID", deleteID); if (relatedRecordCount > 0) { String dialogMessage = ATT_CANT_DEL_1.getContent() + System.lineSeparator() + ATT_CANT_DEL_2.getContent() + userIDText.getText() + System.lineSeparator() + ATT_CANT_DEL_3.getContent() + relatedRecordCount + ATT_CANT_DEL_4.getContent() + System.lineSeparator() + ATT_CANT_DEL_5.getContent(); JOptionPane.showMessageDialog(this, dialogMessage, DELETE_RESULT_DIALOGTITLE.getContent(), JOptionPane.WARNING_MESSAGE); return; } relatedRecordCount = DB_Access.getRecordCount("loginrecord", "UserID", deleteID); if (relatedRecordCount > 0) { String dialogMessage = ATT_CANT_DEL_1.getContent() + System.lineSeparator() + ATT_CANT_DEL_2.getContent() + userIDText.getText() + System.lineSeparator() + ATT_CANT_DEL_3L.getContent() + relatedRecordCount + ATT_CANT_DEL_4L.getContent() + System.lineSeparator() + ATT_CANT_DEL_5L.getContent(); JOptionPane.showMessageDialog(this, dialogMessage, DELETE_RESULT_DIALOGTITLE.getContent(), JOptionPane.WARNING_MESSAGE); return; } String sql = "Delete From users_osp WHERE id = ?"; try { conn = JDBCMySQL.getConnection(); updateStmt = conn.prepareStatement(sql); updateStmt.setString(1, deleteID); int result = updateStmt.executeUpdate(); if (result == 1) { List sortKeys = usersTable.getRowSorter().getSortKeys(); int selectIndex = usersTable.getSelectedRow(); if (loadAttendantTable("") == 0) { clearDetailsForEmptyList(); } else { usersTable.getRowSorter().setSortKeys(sortKeys); if (selectIndex == usersTable.getRowCount()) { selectIndex--; } selectIndex = usersTable.convertRowIndexToModel(selectIndex); usersTable.changeSelection(selectIndex, 0, false, false); usersTable.requestFocus(); } logParkingOperation(OpLogLevel.UserCarChange, ("* User deleted (ID:" + deleteID + ")")); String dialogMessage = ATT_DEL_SUCC_1.getContent() + deleteID + ATT_DEL_SUCC_2.getContent() + System.lineSeparator() + ATT_DEL_SUCC_3.getContent(); JOptionPane.showMessageDialog(this, dialogMessage, DELETE_RESULT_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); clearPasswordFields(); } else { String dialogMessage = ATT_DEL_FAIL_1.getContent() + System.lineSeparator() + ATT_CANT_DEL_2.getContent() + userIDText.getText(); JOptionPane.showMessageDialog(this, dialogMessage, DELETE_RESULT_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); } } catch (Exception se) { logParkingException(Level.SEVERE, se, "(ID: " + deleteID + ")"); } finally { closeDBstuff(conn, updateStmt, null, "(ID: " + deleteID + ")"); } }
From source file:com.osparking.attendant.AttListForm.java
private void checkEmailButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkEmailButtonActionPerformed // Check syntax first, and then check if it's preoccupied, if everything were OK, then use the e-mail. // Otherwise, just return // Use avax.mail.jar library. // Refer http://examples.javacodegeeks.com/enterprise-java/mail/validate-email-address-with-java-mail-api/ // Download: https://java.net/projects/javamail/pages/Home#Download_JavaMail_1.5.2_Release String emailEntered = emailAddrText.getText().trim(); try {/*from www.j a v a 2s . c o m*/ boolean checkResult = validateEmail(emailEntered); if (checkResult) { String sql = "Select count(*) as dataCount From users_osp Where email = ?"; if (dataExistsInDB(sql, emailEntered)) { // Access DB and find if entered e-mail is already registered to the system. String dialogMessage = ATT_EMAIL_TAKEN_1.getContent() + emailAddrText.getText().trim() + ATT_EMAIL_TAKEN_2.getContent() + System.lineSeparator() + ATT_EMAIL_TAKEN_3.getContent(); JOptionPane.showConfirmDialog(this, dialogMessage, ATT_EMAIL_DUP_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); emailAddrText.requestFocus(); } else { Email_usable = true; usableEmail = emailEntered; checkEmailButton.setEnabled(false); String dialogMessage = ATT_EMAIL_TAKEN_1.getContent() + emailAddrText.getText().trim() + ATT_EMAIL_GOOD_2.getContent(); JOptionPane.showConfirmDialog(this, dialogMessage, ATT_EMAIL_DUP_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, INFORMATION_MESSAGE); } } else { String dialogMessage = EMAIL_SYNTAX_1.getContent() + emailAddrText.getText().trim() + EMAIL_SYNTAX_2.getContent(); JOptionPane.showConfirmDialog(this, dialogMessage, ATT_EMAIL_SYNTAX_CHECK_DIALOG.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); emailAddrText.requestFocus(); } } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(User action: new E-mail address('" + emailEntered + "') check button)"); } }
From source file:de.decoit.visa.rdf.RDFManager.java
/** * Read a SPARQL query from a file into a String and create a Query object * from that. If a resource was specified all occurrences of $URI$ * placeholder in the read query will be replaced with the URI of the * resource. If a model URI is specified, GRAPH lines will be added to the * query using the placeholders $S_MOD$ and $E_MOD$. * * @param pFileName File name of the SPARQL file. The file must exist and be * located in 'res/sparql'/* w w w. j a v a2s . co m*/ * @param pRes Optional resource object, will be used to replace the $URI$ * placeholder. Can be set to null if not required. * @param pMod Optional model URI, will be used to add GRAPH lines to the * query. If set to null the query will be executed on the * default model of the dataset. * @return A Query object containing the read SPARQL query, null if the * input file cannot be read */ private Query readSPARQL(String pFileName, Resource pRes, String pMod) { try { // Open the SPARQL file for reading Path inFile = Paths.get("res/sparql", pFileName); BufferedReader br = Files.newBufferedReader(inFile, StandardCharsets.UTF_8); // Read all lines and concatenate them using a StringBuilder StringBuilder rv = new StringBuilder(); String line = br.readLine(); while (line != null) { rv.append(line); rv.append(System.lineSeparator()); line = br.readLine(); } br.close(); // Get the String from the StringBuilder and, if required, replace // the $URI$ placeholder String rvStr = rv.toString(); if (pRes != null) { rvStr = rvStr.replaceAll("\\$URI\\$", pRes.getURI()); } if (pMod != null && !pMod.isEmpty()) { StringBuilder graphLine = new StringBuilder("GRAPH <"); graphLine.append(pMod); graphLine.append("> {"); rvStr = rvStr.replaceAll("\\$S_MOD\\$", graphLine.toString()).replaceAll("\\$E_MOD\\$", "}"); } else { rvStr = rvStr.replaceAll("\\$S_MOD\\$", "").replaceAll("\\$E_MOD\\$", ""); } // Build a Query object and return it return QueryFactory.create(rvStr); } catch (IOException ex) { StringBuilder sb = new StringBuilder("Caught: ["); sb.append(ex.getClass().getSimpleName()); sb.append("] "); sb.append(ex.getMessage()); log.error(sb.toString()); if (log.isDebugEnabled()) { for (StackTraceElement ste : ex.getStackTrace()) { log.debug(ste.toString()); } } return null; } }
From source file:com.osparking.attendant.AttListForm.java
private void checkIDButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkIDButtonActionPerformed String idEntered = userIDText.getText().trim(); String sql = "Select count(*) as dataCount From users_osp Where id = ?"; try {//from w w w . ja v a2s .c o m if (idEntered.length() < 2) { // Reject if ID were shorter than 2 characters JOptionPane.showConfirmDialog(this, ID_LENGTH_CHECK_DIALOG.getContent(), ATT_ID_DUP_CHCEK_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); userIDText.requestFocusInWindow(); return; } else if (dataExistsInDB(sql, idEntered)) { // Same ID is being used by other user, let the user know about this. String dialogMessage = ID_INUSE_1.getContent() + userIDText.getText().trim() + ID_INUSE_2.getContent() + System.lineSeparator() + ID_INUSE_3.getContent(); JOptionPane.showConfirmDialog(this, dialogMessage, ATT_ID_DUP_CHCEK_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); userIDText.requestFocusInWindow(); } else { String checkResult = IDSyntaxCheckResult(idEntered); if (checkResult.length() == 0) { ID_usable = true; usableID = idEntered; checkIDButton.setEnabled(false); String dialogMessage = ID_INUSE_1.getContent() + userIDText.getText().trim() + ATT_EMAIL_GOOD_2.getContent() + System.lineSeparator(); JOptionPane.showConfirmDialog(this, dialogMessage, ATT_ID_DUP_CHCEK_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, INFORMATION_MESSAGE); } else { JOptionPane.showConfirmDialog(this, checkResult, ATT_ID_DUP_CHCEK_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE, WARNING_MESSAGE); userIDText.requestFocus(); } } } catch (Exception ex) { logParkingException(Level.SEVERE, ex, "(User Action: new user ID('" + idEntered + "') Check Button is Being Processed)"); } }
From source file:com.osparking.attendant.AttListForm.java
private String IDSyntaxCheckResult(String idEntered) { // ID syntax requirement: // Allowed characters: alphabet, number digit(0-9), nested space or dot(.) // Additionally, ID should begin with an alphabet, ends by alphabet or number digit. // E.g., "Henry14", "John K. Park" StringBuilder tempStr = new StringBuilder(); int idLen = idEntered.length(); if (!isEnglish(idEntered.charAt(0))) { tempStr.append(ID_FIRST_CHAR_CHECK_DIALOG.getContent()); }// w ww .j a v a 2s.c o m char ch; for (int i = 1; i < idLen - 1; i++) { ch = idEntered.charAt(i); if (!isEnglish(ch) && !(Character.isDigit(ch)) && ch != ' ' && ch != '.' && ch != '_') { if (tempStr.length() > 0) tempStr.append(System.lineSeparator()); tempStr.append(ID_CHAR_CHECK_DIALOG.getContent()); } } ch = idEntered.charAt(idLen - 1); if (!(isEnglish(ch)) && !(Character.isDigit(ch))) { if (tempStr.length() > 0) tempStr.append(System.lineSeparator()); tempStr.append(ID_END_CHAR_CHECK_DIALOG.getContent()); } return tempStr.toString(); }
From source file:com.osparking.attendant.AttListForm.java
private void doAfterUpdateOperations(int result) { if (result == 1) { List sortKeys = usersTable.getRowSorter().getSortKeys(); loadAttendantTable(""); usersTable.getRowSorter().setSortKeys(sortKeys); int selectIndex = searchRow(userIDText.getText()); usersTable.changeSelection(selectIndex, 0, false, false); usersTable.requestFocus();//from w w w .java 2 s.co m String dialogMessage = USER_UPDATE_1.getContent() + System.lineSeparator() + System.lineSeparator() + USER_UPDATE_2.getContent() + userIDText.getText().trim(); JOptionPane.showMessageDialog(this, dialogMessage, ATT_USER_UPDATE_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); clearPasswordFields(); changedControls.clear(); logParkingOperation(OpLogLevel.UserCarChange, getModifiedUserInfo()); } else { //<editor-fold desc="-- Handle the case of update failure"> String dialogMessage = USER_UPDATE_A.getContent() + System.lineSeparator() + System.lineSeparator() + USER_UPDATE_2.getContent() + userIDText.getText().trim(); JOptionPane.showMessageDialog(this, dialogMessage, ATT_USER_UPDATE_DIALOGTITLE.getContent(), JOptionPane.PLAIN_MESSAGE); //</editor-fold> } }