List of usage examples for java.util.regex PatternSyntaxException getLocalizedMessage
public String getLocalizedMessage()
From source file:it.geosolutions.tools.compress.file.Extract.java
/** * Try to compile the passed regex throwing an error if the * /*www . j a v a 2 s . c om*/ * @param regex * @return the compiled Pattern * @throws Exception * if the regex is empty or null * @throws PatternSyntaxException * if the expression's syntax is invalid */ private static Pattern compile(String regex) throws Exception { if (regex != null && regex.length() > 0) { try { // compile the pattern return Pattern.compile(regex); } catch (PatternSyntaxException pse) { if (LOGGER.isErrorEnabled()) LOGGER.error(pse.getLocalizedMessage()); throw pse; } } else { final String message = "Unable to compile the passed regular expression: \'" + regex + "\'"; if (LOGGER.isErrorEnabled()) LOGGER.error(message); throw new Exception(message); } }
From source file:org.kalypso.commons.databinding.validation.StringRegexValidator.java
@Override protected IStatus doValidate(final String value) { try {//from w w w . j a v a 2 s. c om if (value == null || value.length() == 0) throw new PatternSyntaxException(Messages.getString("StringRegexValidator_0"), StringUtils.EMPTY, //$NON-NLS-1$ -1); Pattern.compile(value); return Status.OK_STATUS; } catch (final PatternSyntaxException ex) { return new Status(IStatus.ERROR, KalypsoCommonsPlugin.getID(), String.format(Messages.getString("StringRegexValidator_1"), ex.getLocalizedMessage()), ex); //$NON-NLS-1$ } }
From source file:org.opencms.db.CmsRewriteAliasMatcher.java
/** * Tries to rewrite a given path, and either returns the rewrite result or null if no * rewrite alias matched the path.<p> * * @param path the path to match//from w w w .ja v a 2 s . c o m * @return the rewrite result or null if no rewrite alias matched */ public RewriteResult match(String path) { for (CmsRewriteAlias alias : m_aliases) { try { Pattern pattern = Pattern.compile(alias.getPatternString()); Matcher matcher = pattern.matcher(path); if (matcher.matches()) { String newPath = matcher.replaceFirst(alias.getReplacementString()); return new RewriteResult(newPath, alias); } } catch (PatternSyntaxException e) { LOG.warn(e.getLocalizedMessage(), e); } catch (IndexOutOfBoundsException e) { LOG.warn(e.getLocalizedMessage(), e); } } return null; }
From source file:org.talend.dataprofiler.core.ui.views.PatternTestView.java
/** * Test the text by the regular text of regularText. *//* ww w . j a v a2 s. c o m*/ private void testRegularText() { // MOD qiongli 2011-1-7.Add java in Pattern Test View if (isJavaEngine) { String regexStr = regularText.getText(); if (regexStr.length() >= 2 && regexStr.startsWith("'") && regexStr.endsWith("'")) { //$NON-NLS-1$ //$NON-NLS-2$ regexStr = regexStr.substring(1, regexStr.length() - 1); } try { boolean flag = java.util.regex.Pattern.compile(regexStr).matcher(testText.getText()).find(); if (flag) { emoticonLabel.setImage(ImageLib.getImage(ImageLib.CHECK_MARK_PNG)); resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.Match")); //$NON-NLS-1$ return; } else { emoticonLabel.setImage(ImageLib.getImage(ImageLib.RED_WARNING_PNG)); resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.nonMatch")); //$NON-NLS-1$ return; } } catch (java.util.regex.PatternSyntaxException e) {// TDQ-5650 show the error message if any exception emoticonLabel.setImage(ImageLib.getImage(ImageLib.ICON_ERROR_INFO)); resultLabel.setText(e.getLocalizedMessage()); return; } } else { for (IRepositoryNode connRepNode : listTdDataProviders) { ConnectionItem connItem = (ConnectionItem) connRepNode.getObject().getProperty().getItem(); Connection tddataprovider = connItem.getConnection(); if (tddataprovider.getName().equals(dbCombo.getText())) { DbmsLanguage createDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(tddataprovider); String selectRegexpTestString = null; // MOD gdbu 2011-5-31 bug : 19119 if (null != createDbmsLanguage) { createDbmsLanguage.setRegularExpressionFunction(getFunctionName()); selectRegexpTestString = createDbmsLanguage.getSelectRegexpTestString(testText.getText(), regularText.getText()); } // ~19119 // TDQ-8637 if the 'selectRegexpTestString' is null,means doesn't implement method // DbmsLanguage.regexLike().should return. if (selectRegexpTestString == null) { MessageDialog.openInformation(new Shell(), DefaultMessagesImpl.getString("PatternTestView.NoSupportTitle"), //$NON-NLS-1$ DefaultMessagesImpl.getString("PatternTestView.NoSupportPatternTest")); //$NON-NLS-1$ return; } TypedReturnCode<java.sql.Connection> rcConn = JavaSqlFactory.createConnection(tddataprovider); Statement createStatement = null; try { if (!rcConn.isOk()) { throw new DataprofilerCoreException(rcConn.getMessage()); } java.sql.Connection connection = rcConn.getObject(); createStatement = connection.createStatement(); ResultSet resultSet = createStatement.executeQuery(selectRegexpTestString); while (resultSet.next()) { String okString = resultSet.getString(1); // MOD msjian 2011-11-15 TDQ-3967: in the postgres db, the match return value is "t" if ("1".equalsIgnoreCase(okString) //$NON-NLS-1$ || (createDbmsLanguage != null && (createDbmsLanguage.getDbmsName() .equals(SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage()) && "t".equalsIgnoreCase(okString)))) { //$NON-NLS-1$ // TDQ-3967 ~ emoticonLabel.setImage(ImageLib.getImage(ImageLib.CHECK_MARK_PNG)); resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.Match")); //$NON-NLS-1$ return; } } emoticonLabel.setImage(ImageLib.getImage(ImageLib.RED_WARNING_PNG)); resultLabel.setText(DefaultMessagesImpl.getString("PatternTestView.nonMatch")); //$NON-NLS-1$ return; } catch (Exception exception) { log.error(exception, exception); // bug TDQ-2066-->TDQ-3594 for mysql Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); MessageBoxExceptionHandler.process(exception, shell); // ~ emoticonLabel.setImage(null); return; } finally { if (createStatement != null) { try { createStatement.close(); } catch (SQLException e) { // do nothing until now } } ConnectionUtils.closeConnection(rcConn.getObject()); } } } } MessageDialog.openWarning(new Shell(), "", NO_DATABASE_SELECTEDED); //$NON-NLS-1$ }
From source file:se.trixon.toolbox.photokml.config.ModuleFoldersPanel.java
@Override public boolean hasValidSettings() { if (mInvalidDateFormat && mOptions.isFoldersSubFolders() && mOptions.getFoldersBy() == 1) { invalidSettings(Dict.INVALID_DATE_PATTERN.getString()); return false; }//from w w w . java 2 s . co m if (mOptions.isFoldersSubFolders() && mOptions.getFoldersBy() == 2) { try { Pattern pattern = Pattern.compile(mOptions.getFoldersRegex()); } catch (PatternSyntaxException e) { String message = "PatternSyntaxException: " + e.getLocalizedMessage(); invalidSettings(message); return false; } } return true; }