Example usage for java.util.regex Pattern toString

List of usage examples for java.util.regex Pattern toString

Introduction

In this page you can find the example usage for java.util.regex Pattern toString.

Prototype

public String toString() 

Source Link

Document

Returns the string representation of this pattern.

Usage

From source file:org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils.java

public static void validatePartitionNameCharacters(List<String> partVals, Pattern partitionValidationPattern)
        throws MetaException {

    String invalidPartitionVal = getPartitionValWithInvalidCharacter(partVals, partitionValidationPattern);
    if (invalidPartitionVal != null) {
        throw new MetaException("Partition value '" + invalidPartitionVal + "' contains a character "
                + "not matched by whitelist pattern '" + partitionValidationPattern.toString() + "'.  "
                + "(configure with " + MetastoreConf.ConfVars.PARTITION_NAME_WHITELIST_PATTERN.getVarname()
                + ")");
    }//from w ww  . ja  v  a 2  s  .  co m
}

From source file:es.pode.administracion.presentacion.adminusuarios.altaUsuario.AltaUsuarioControllerImpl.java

private Boolean validaEmail(String email) {
    Boolean resultado = Boolean.TRUE;
    if (log.isDebugEnabled())
        log.debug("VALIDAEMAIL");
    //Pattern pattern = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
    Pattern pattern = Pattern
            .compile("[A-Za-z0-9.-_]([A-Za-z0-9.-_])*@[A-Za-z0-9]([A-Za-z0-9.-_])*.([A-Za-z0-9])*");
    if (log.isDebugEnabled())
        log.debug("pattern.toString() " + pattern.toString());
    Matcher matcher = pattern.matcher(email);
    if (matcher.find()) {
        if (log.isDebugEnabled())
            log.debug("El email coincide con el patron es correcto el campo email");
    } else {/* ww w  .  j  a  v a  2  s . c  om*/
        resultado = Boolean.FALSE;
    }
    return resultado;

}

From source file:org.apache.metron.parsers.regex.RegularExpressionsParser.java

private void extractNamedGroups(Map<String, Object> json, String recordType, String originalMessage) {
    Map<Pattern, Set<String>> patternMap = recordTypePatternMap.get(recordType.toLowerCase());
    if (patternMap != null) {
        for (Map.Entry<Pattern, Set<String>> entry : patternMap.entrySet()) {
            Pattern pattern = entry.getKey();
            Set<String> namedGroups = entry.getValue();
            if (pattern != null && namedGroups != null && namedGroups.size() > 0) {
                Matcher m = pattern.matcher(originalMessage);
                if (m.matches()) {
                    LOG.debug("RecordType : {} Trying regex : {} for message : {} ", recordType,
                            pattern.toString(), originalMessage);
                    for (String namedGroup : namedGroups) {
                        if (m.group(namedGroup) != null) {
                            json.put(namedGroup, m.group(namedGroup).trim());
                        }//from w  w w  .  jav a2  s.  c  o  m
                    }
                    break;
                }
            }
        }
    } else {
        LOG.warn("No pattern found for record type : {}", recordType);
    }
}

From source file:org.apache.maven.plugin.javadoc.JavadocUtil.java

/**
 * Parse the output for 'javadoc -J-version' and return the javadoc version recognized.
 * <br/>//w  w w. j  a v a 2s  . c o m
 * Here are some output for 'javadoc -J-version' depending the JDK used:
 * <table>
 * <tr>
 *   <th>JDK</th>
 *   <th>Output for 'javadoc -J-version'</th>
 * </tr>
 * <tr>
 *   <td>Sun 1.4</td>
 *   <td>java full version "1.4.2_12-b03"</td>
 * </tr>
 * <tr>
 *   <td>Sun 1.5</td>
 *   <td>java full version "1.5.0_07-164"</td>
 * </tr>
 * <tr>
 *   <td>IBM 1.4</td>
 *   <td>javadoc full version "J2RE 1.4.2 IBM Windows 32 build cn1420-20040626"</td>
 * </tr>
 * <tr>
 *   <td>IBM 1.5 (French JVM)</td>
 *   <td>javadoc version complte de "J2RE 1.5.0 IBM Windows 32 build pwi32pdev-20070426a"</td>
 * </tr>
 * <tr>
 *   <td>FreeBSD 1.5</td>
 *   <td>java full version "diablo-1.5.0-b01"</td>
 * </tr>
 * <tr>
 *   <td>BEA jrockit 1.5</td>
 *   <td>java full version "1.5.0_11-b03"</td>
 * </tr>
 * </table>
 *
 * @param output for 'javadoc -J-version'
 * @return the version of the javadoc for the output.
 * @throws PatternSyntaxException if the output doesn't match with the output pattern
 * <tt>(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*</tt>.
 * @throws IllegalArgumentException if the output is null
 */
protected static float parseJavadocVersion(String output) throws IllegalArgumentException {
    if (StringUtils.isEmpty(output)) {
        throw new IllegalArgumentException("The output could not be null.");
    }

    Pattern pattern = Pattern.compile("(?s).*?([0-9]+\\.[0-9]+)(\\.([0-9]+))?.*");

    Matcher matcher = pattern.matcher(output);
    if (!matcher.matches()) {
        throw new PatternSyntaxException("Unrecognized version of Javadoc: '" + output + "'", pattern.pattern(),
                pattern.toString().length() - 1);
    }

    String version = matcher.group(3);
    if (version == null) {
        version = matcher.group(1);
    } else {
        version = matcher.group(1) + version;
    }

    return Float.parseFloat(version);
}

From source file:edu.umd.cs.submitServer.MultipartRequest.java

/**
 * Return the parameter's value if matched by the provided regex pattern. If
 * the parameter is not specified or if it does not match the provided
 * regex, null is returned./*from w ww .  j a  v  a2 s .  c  o m*/
 *
 * @param name
 *            name of the parameter to retrieve
 * @param p
 *            pattern that must match a valid parameter
 * @return the parameter if it specified and valid, null otherwise
 */
private @CheckForNull String getOptionalRegexParameter(String name, Pattern p) {
    String s = getParameter(name);
    if (s != null) {
        s = s.trim();
        if (p.matcher(s).matches()) {
            return s;
        }
        String scrubbed = XSSScrubber.scrubbedStr(s);
        logger.error(
                "Param \"" + name + "\" value \"" + scrubbed + "\" doesn't match regex filter " + p.toString());
        if (strictChecking) {
            throw new IllegalArgumentException(name + " was malformed according to regular expression");
        } else {
            return scrubbed;
        }
    }
    return null;
}

From source file:edu.umd.cs.submitServer.MultipartRequest.java

/**
 * Return the parameter's value if matched by the provided regex pattern. If
 * the parameter is not specified or if it does not match the provided
 * regex, null is returned.//from w  ww.j a v a  2  s. c  o  m
 *
 * @param name
 *            name of the parameter to retrieve
 * @param p
 *            pattern that must match a valid parameter
 * @return the parameter if it specified and valid, null otherwise
 */
private String getRegexParameter(String name, Pattern p) throws InvalidRequiredParameterException {
    String s = getParameter(name);
    if (s != null) {
        if (p.matcher(s).matches()) {
            return s;
        }
        String scrubbed = XSSScrubber.scrubbedStr(s);
        logger.error(
                "Param \"" + name + "\" value \"" + scrubbed + "\" doesn't match regex filter " + p.toString());
        if (strictChecking) {
            throw new IllegalArgumentException(name + " was malformed according to regular expression");
        } else {
            return scrubbed;
        }
    }
    throw new InvalidRequiredParameterException(name + " is a required parameter but was not specified");
}

From source file:org.hyperic.hq.plugin.multilogtrack.MultiLogTrackPlugin.java

private TrackEvent processLine(String property, Pattern primaryIncludePattern, Pattern includePattern,
        Pattern excludePattern, FileInfo info, String line, String basedir, String logfilepattern, int offset) {
    if (null == includePattern || !includePattern.matcher(line).find()) {
        return null;
    }/*from ww  w  .j a  v  a  2s  .co m*/
    if (null != excludePattern && excludePattern.matcher(line).find()) {
        return null;
    }
    MultiLogTrackMeasurementPlugin.incrementNumLines(property, basedir, logfilepattern,
            primaryIncludePattern.toString(), offset);
    return newTrackEvent(System.currentTimeMillis(), LogTrackPlugin.LOGLEVEL_ANY, info.getName(), line);
}

From source file:org.apache.sling.validation.impl.ValidationServiceImpl.java

private void validateValueMap(ValueMap valueMap, Resource resource, String relativePath,
        Collection<ResourceProperty> resourceProperties, CompositeValidationResult result) {
    if (valueMap == null) {
        throw new IllegalArgumentException("ValueMap may not be null");
    }//from w w  w.  j a  v  a2 s  . c  om
    for (ResourceProperty resourceProperty : resourceProperties) {
        Pattern pattern = resourceProperty.getNamePattern();
        if (pattern != null) {
            boolean foundMatch = false;
            for (String key : valueMap.keySet()) {
                if (pattern.matcher(key).matches()) {
                    foundMatch = true;
                    validatePropertyValue(key, valueMap, resource, relativePath, resourceProperty, result);
                }
            }
            if (!foundMatch && resourceProperty.isRequired()) {
                result.addFailure(relativePath, null, I18N_KEY_MISSING_REQUIRED_PROPERTY_MATCHING_PATTERN,
                        pattern.toString());
            }
        } else {
            validatePropertyValue(resourceProperty.getName(), valueMap, resource, relativePath,
                    resourceProperty, result);
        }
    }
}

From source file:org.apache.sling.validation.impl.ValidationServiceImpl.java

/**
 * Validates a child resource with the help of the given {@code ChildResource} entry from the validation model
 * @param resource//from  ww w.  ja v a  2  s  .co  m
 * @param relativePath relativePath of the resource (must be empty or end with "/")
 * @param result
 * @param childResources
 */
private void validateChildren(Resource resource, String relativePath, Collection<ChildResource> childResources,
        CompositeValidationResult result) {
    // validate children resources, if any
    for (ChildResource childResource : childResources) {
        // if a pattern is set we validate all children matching that pattern
        Pattern pattern = childResource.getNamePattern();
        if (pattern != null) {
            boolean foundMatch = false;
            for (Resource child : resource.getChildren()) {
                Matcher matcher = pattern.matcher(child.getName());
                if (matcher.matches()) {
                    validateChildResource(child, relativePath, childResource, result);
                    foundMatch = true;
                }
            }
            if (!foundMatch && childResource.isRequired()) {
                result.addFailure(relativePath, null, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_MATCHING_PATTERN,
                        pattern.toString());
            }
        } else {
            Resource expectedResource = resource.getChild(childResource.getName());
            if (expectedResource != null) {
                validateChildResource(expectedResource, relativePath, childResource, result);
            } else if (childResource.isRequired()) {
                result.addFailure(relativePath, null, I18N_KEY_MISSING_REQUIRED_CHILD_RESOURCE_WITH_NAME,
                        childResource.getName());
            }
        }
    }
}

From source file:org.apache.hadoop.hbase.thrift2.client.ThriftAdmin.java

@Override
public TableName[] listTableNames(Pattern pattern, boolean includeSysTables) throws IOException {
    String regex = (pattern == null ? null : pattern.toString());
    try {//from  w  ww  . jav  a  2 s. c  o m
        List<TTableName> tTableNames = client.getTableNamesByPattern(regex, includeSysTables);
        return ThriftUtilities.tableNamesArrayFromThrift(tTableNames);
    } catch (TException e) {
        throw new IOException(e);
    }
}