java.util.regex.PatternSyntaxException#printStackTrace ( )源码实例Demo

下面列出了java.util.regex.PatternSyntaxException#printStackTrace ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

Pattern[] toPatterns(String[] regexStrings) {
    if (regexStrings == null)
        return new Pattern[0];
    List<Pattern> patterns = new ArrayList<Pattern>();
    for (String pattern : regexStrings) {
        try {
            patterns.add(Pattern.compile(pattern));
        } catch (PatternSyntaxException pse) {
            ByteArrayOutputStream bs = new ByteArrayOutputStream();
            PrintStream ps = new PrintStream(bs);
            try {
                pse.printStackTrace(ps);
                logger.logDebug(String.format("%s: %s", this.getClass()
                        .getName(), bs.toString()));
            } finally {
                ps.close();
            }
        }
    }
    return patterns.toArray(new Pattern[patterns.size()]);
}
 
源代码2 项目: KodeBeagle   文件: ImportsUtilBase.java
public final Map<String, Set<String>> excludeConfiguredImports(
        final Map<String, Set<String>> importsVsMethods, final Set<String> excludeImports) {
    Map<String, Set<String>> finalImportsVsMethods = new HashMap<>();
    finalImportsVsMethods.putAll(importsVsMethods);
    Set<Map.Entry<String, Set<String>>> entrySet = importsVsMethods.entrySet();
    for (String importStatement : excludeImports) {
        Pattern pattern = Pattern.compile(importStatement);
        for (Map.Entry<String, Set<String>> entry : entrySet) {
            try {
                String entryImport = entry.getKey();
                Matcher matcher = pattern.matcher(entryImport);
                if (matcher.find()) {
                    finalImportsVsMethods.remove(entryImport);
                }
            } catch (PatternSyntaxException e) {
                KBNotification.getInstance().error(e);
                e.printStackTrace();
            }
        }
    }
    return finalImportsVsMethods;
}
 
源代码3 项目: PowerFileExplorer   文件: KeywordHighlght.java
static private void addKeyword( String regexp , int color )
{
    if ( color != 0 && !TextUtils.isEmpty(regexp) ){
        try{
            sList.add( new KeywordHighlght(regexp , color|0xFF000000) );
        }
        catch( PatternSyntaxException e) {
            e.printStackTrace();
        }
    }
}
 
源代码4 项目: EosProxyServer   文件: EosEcUtil.java
public static String[] safeSplitEosCryptoString( String cryptoStr ) {
    if ( StringUtils.isEmpty( cryptoStr)) {
        return new String[]{ cryptoStr };
    }

    try {
        return cryptoStr.split( EOS_CRYPTO_STR_SPLITTER );
    }
    catch (PatternSyntaxException e){
        e.printStackTrace();
        return new String[]{ cryptoStr };
    }
}
 
源代码5 项目: PocketEOS-Android   文件: EosEcUtil.java
public static String[] safeSplitEosCryptoString( String cryptoStr ) {
    if ( StringUtils.isEmpty( cryptoStr)) {
        return new String[]{ cryptoStr };
    }

    try {
        return cryptoStr.split( EOS_CRYPTO_STR_SPLITTER );
    }
    catch (PatternSyntaxException e){
        e.printStackTrace();
        return new String[]{ cryptoStr };
    }
}
 
源代码6 项目: hadoop   文件: TestGlobPattern.java
private void shouldThrow(String... globs) {
  for (String glob : globs) {
    try {
      GlobPattern.compile(glob);
    }
    catch (PatternSyntaxException e) {
      e.printStackTrace();
      continue;
    }
    assertTrue("glob "+ glob +" should throw", false);
  }
}
 
源代码7 项目: EosCommander   文件: EosEcUtil.java
public static String[] safeSplitEosCryptoString( String cryptoStr ) {
    if ( StringUtils.isEmpty( cryptoStr)) {
        return new String[]{ cryptoStr };
    }

    try {
        return cryptoStr.split( EOS_CRYPTO_STR_SPLITTER );
    }
    catch (PatternSyntaxException e){
        e.printStackTrace();
        return new String[]{ cryptoStr };
    }
}
 
源代码8 项目: big-c   文件: TestGlobPattern.java
private void shouldThrow(String... globs) {
  for (String glob : globs) {
    try {
      GlobPattern.compile(glob);
    }
    catch (PatternSyntaxException e) {
      e.printStackTrace();
      continue;
    }
    assertTrue("glob "+ glob +" should throw", false);
  }
}
 
源代码9 项目: JotaTextEditor   文件: KeywordHighlght.java
static private void addKeyword( String regexp , int color )
{
    if ( color != 0 && !TextUtils.isEmpty(regexp) ){
        try{
            sList.add( new KeywordHighlght(regexp , color|0xFF000000) );
        }
        catch( PatternSyntaxException e) {
            e.printStackTrace();
        }
    }
}
 
private boolean compute(String s) {
    for (String pattern : patterns) {
        try {
            if (s.matches(pattern)) {
                return true;
            }
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
源代码11 项目: carbon-commons   文件: EndPointsSetter.java
public String getEndPoints(String str) {
    String retVal = "<select name='pn' class='toolsClass' id='id_pn'>";
    try {
        String[] splitArray = str.split(",");
        for (String st : splitArray) {
            if (!st.toLowerCase().contains("local")) {
                retVal += "<option value='" + st + "'>" + st + "</option>";
            }
        }
    } catch (PatternSyntaxException ex) {
        ex.printStackTrace();
    }
    retVal += "</select>";
    return retVal;
}
 
源代码12 项目: WirelessRedstone   文件: DepLoader.java
private void loadJson(JsonObject node) throws IOException {
    boolean obfuscated = ((LaunchClassLoader) DepLoader.class.getClassLoader())
            .getClassBytes("net.minecraft.world.World") == null;

    String testClass = node.get("class").getAsString();
    if (DepLoader.class.getResource("/" + testClass.replace('.', '/') + ".class") != null)
        return;

    String repo = node.get("repo").getAsString();
    String filename = node.get("file").getAsString();
    if (!obfuscated && node.has("dev"))
        filename = node.get("dev").getAsString();

    boolean coreLib = node.has("coreLib") && node.get("coreLib").getAsBoolean();

    Pattern pattern = null;
    try {
        if(node.has("pattern"))
            pattern = Pattern.compile(node.get("pattern").getAsString());
    } catch (PatternSyntaxException e) {
        System.err.println("Invalid filename pattern: "+node.get("pattern"));
        e.printStackTrace();
    }
    if(pattern == null)
        pattern = Pattern.compile("(\\w+).*?([\\d\\.]+)[-\\w]*\\.[^\\d]+");

    VersionedFile file = new VersionedFile(filename, pattern);
    if (!file.matches())
        throw new RuntimeException("Invalid filename format for dependency: " + filename);

    addDep(new Dependency(repo, file, coreLib));
}
 
源代码13 项目: scelight   文件: RepSearchEngine.java
/**
 * Evaluates the text operator.
 * 
 * @param fvalue filter value
 * @param operator operator to be evaluated
 * @param value operand to evaluate
 * @return true if evaluation is true; false otherwise
 */
private boolean evalTextOp( String fvalue, final Operator operator, String value ) {
	if ( value == null )
		return false;
	value = value.toLowerCase();
	
	if ( operator != Operator.MATCHES ) // Regexp is case sensitive!
		fvalue = fvalue.toLowerCase();
	
	switch ( operator ) {
		case CONTAINS :
			return value.contains( fvalue );
		case ENDS_WITH :
			return value.endsWith( fvalue );
		case EQUAL :
			return value.equals( fvalue );
		case GREATER_THAN :
			return value.compareTo( fvalue ) > 0;
		case GREATER_THAN_OR_EQUAL :
			return value.compareTo( fvalue ) >= 0;
		case LESS_THAN :
			return value.compareTo( fvalue ) < 0;
		case LESS_THAN_OR_EQUAL :
			return value.compareTo( fvalue ) <= 0;
		case MATCHES : {
			// Cache compiled regular expressions.
			// If a pattern is invalid, store a null value so we don't try to compile it again.
			Pattern pattern = regexpPatternMap.get( fvalue );
			if ( pattern == null && !regexpPatternMap.containsKey( fvalue ) ) {
				try {
					pattern = Pattern.compile( fvalue );
				} catch ( final PatternSyntaxException pse ) {
					// Do nothing, pattern value will remain null
					pse.printStackTrace();
				}
				regexpPatternMap.put( fvalue, pattern );
			}
			return pattern != null && pattern.matcher( value ).matches();
		}
		case NOT_CONTAINS :
			return !value.contains( fvalue );
		case NOT_ENDS_WITH :
			return !value.endsWith( fvalue );
		case NOT_EQUAL :
			return !value.equals( fvalue );
		case NOT_STARTS_WITH :
			return !value.startsWith( fvalue );
		case STARTS_WITH :
			return value.startsWith( fvalue );
		default :
			throw new RuntimeException( "Unhandled operator: " + operator );
	}
}
 
protected void processSendMessage() {
    if (!TextUtils.isEmpty(messageEditText.getText().toString().trim()) || !TextUtils.isEmpty(filePath)) {
        String inputMessage = messageEditText.getText().toString();
        String[] inputMsg = inputMessage.toLowerCase().split(" ");
        List<String> userInputList = Arrays.asList(inputMsg);

        boolean disjointResult = (restrictedWords == null) || disjoint(restrictedWords, userInputList);
        boolean restrictedWordMatches;

        try {
            String dynamicRegex = ApplozicSetting.getInstance(getContext()).getRestrictedWordsRegex();
            String pattern = !TextUtils.isEmpty(dynamicRegex) ? dynamicRegex : (alCustomizationSettings != null
                    && !TextUtils.isEmpty(alCustomizationSettings.getRestrictedWordRegex()) ? alCustomizationSettings.getRestrictedWordRegex() : "");

            restrictedWordMatches = !TextUtils.isEmpty(pattern) && Pattern.compile(pattern).matcher(inputMessage.trim()).matches();
        } catch (PatternSyntaxException e) {
            e.printStackTrace();
            createInvalidPatternExceptionDialog();
            return;
        }

        if (disjointResult && !restrictedWordMatches) {
            sendMessage(messageEditText.getText().toString().trim());
            messageEditText.setText("");
        } else {
            final AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity()).
                    setPositiveButton(R.string.ok_alert, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            handleSendAndRecordButtonView(true);
                        }
                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    handleSendAndRecordButtonView(true);
                }
            });
            alertDialog.setTitle(alCustomizationSettings.getRestrictedWordMessage());
            alertDialog.setCancelable(true);
            alertDialog.create().show();
        }
    }
}
 
boolean validateCaptionTextAndShowDialog() {
    if (!TextUtils.isEmpty(messageEditText.getText().toString().trim())) {
        String inputMessage = messageEditText.getText().toString();
        String[] inputMsg = inputMessage.toLowerCase().split(" ");
        List<String> userInputList = Arrays.asList(inputMsg);

        boolean disjointResult = (restrictedWords == null) || disjoint(restrictedWords, userInputList);
        boolean restrictedWordMatches;

        try {
            String dynamicRegex = ApplozicSetting.getInstance(this).getRestrictedWordsRegex();
            String pattern = !TextUtils.isEmpty(dynamicRegex) ? dynamicRegex : (alCustomizationSettings != null
                    && !TextUtils.isEmpty(alCustomizationSettings.getRestrictedWordRegex()) ? alCustomizationSettings.getRestrictedWordRegex() : "");

            restrictedWordMatches = !TextUtils.isEmpty(pattern) && Pattern.compile(pattern).matcher(inputMessage.trim()).matches();
        } catch (PatternSyntaxException e) {
            Utils.printLog(this, TAG, "The Regex to match message is invalid");
            e.printStackTrace();
            return false;
        }

        if (!(disjointResult && !restrictedWordMatches)) {
            final AlertDialog.Builder alertDialog = new AlertDialog.Builder(this).
                    setPositiveButton(R.string.ok_alert, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                        }
                    }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                }
            });
            alertDialog.setTitle(alCustomizationSettings.getRestrictedWordMessage());
            alertDialog.setCancelable(true);
            alertDialog.create().show();
            return false;
        }
    }
    return true;
}