Example usage for java.util.regex Pattern matches

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

Introduction

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

Prototype

public static boolean matches(String regex, CharSequence input) 

Source Link

Document

Compiles the given regular expression and attempts to match the given input against it.

Usage

From source file:hudson.plugins.git.SubmoduleConfig.java

public boolean branchMatchesInterest(Branch br) {
    for (String regex : branches) {
        if (!Pattern.matches(regex, br.getName())) {
            return false;
        }/*w w w . j a v a2s .  c  o m*/
    }
    return true;
}

From source file:com.adanac.module.blog.servlet.Login.java

@Override
protected void service() throws ServletException, IOException {
    Map<String, Object> result = new HashMap<>();
    HttpServletRequest request = getRequest();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    if (StringUtils.isBlank(username)) {
        writeText("???");
        return;//  ww w  .  j av  a2  s  .  co  m
    }
    int chineseNumber = 0;
    Matcher matcher = chinesePattern.matcher(username);
    while (matcher.find()) {
        chineseNumber++;
    }
    int length = chineseNumber * 6 + (username.length() - chineseNumber);
    if (length < 6) {
        writeText("????66");
        return;
    }
    if (length > 30) {
        writeText("???306");
        return;
    }
    if (!Pattern.matches(pattern, username)) {
        writeText("????");
        return;
    }
    if (DirtyWordsUtil.isDirtyWords(username)) {
        writeText("????");
        return;
    }
    if (StringUtils.isBlank(password)) {
        writeText("??");
        return;
    }
    if (password.length() < 6) {
        writeText("???6");
        return;
    }
    if (password.length() > 30) {
        writeText("??30");
        return;
    }
    Map<String, String> user = DaoFactory.getDao(UserDao.class).login(username, password);
    if (user != null) {
        request.getSession().setAttribute("user", user);
        result.put("success", true);
        result.put("url", getDynamicUrl());
        writeJsonObject(result);
        return;
    }
    Map<String, String> userInDB = DaoFactory.getDao(UserDao.class).getUser(username);
    if (userInDB != null) {
        writeText("???");
        return;
    }
    if (DaoFactory.getDao(UserDao.class).saveCommonLogin(username, password)) {
        Map<String, String> newUser = DaoFactory.getDao(UserDao.class).getUser(username);
        request.getSession().setAttribute("user", newUser);
        result.put("success", true);
        result.put("url", getDynamicUrl());
        writeJsonObject(result);
        return;
    }
    writeText("??");
}

From source file:org.apache.eagle.security.resolver.AbstractCommandResolver.java

@Override
public void validateRequest(GenericAttributeResolveRequest request) throws BadAttributeResolveRequestException {
    String query = request.getQuery();
    if (query == null || !Pattern.matches("[a-zA-Z]+", query)) {
        throw new BadAttributeResolveRequestException(
                String.format("Command must be in {%s}", StringUtils.join(commands, ",")));
    }/*from  w  ww .  j  a  va 2  s .  com*/
}

From source file:gov.nist.healthcare.ttt.webapp.api.GetCCDAFolderTest.java

public static HashMap<String, Object> buildJson(HashMap<String, Object> parent, String[] path) {
    if (path.length == 1) {
        if (Pattern.matches(extensionRegex, path[0])) {
            return createFile(path[0]);
        } else {//from  ww w .j av a2s  .  co m
            return createDir(path[0]);
        }
    } else {
        HashMap<String, Object> nextParent = createDir(path[0]);
        parent.putAll(buildJson(nextParent, Arrays.copyOfRange(path, 1, path.length)));
        return parent;
    }
}

From source file:com.namespace.controller.ApplicationLogoutController.java

@RequestMapping("/logout")
public String applicationLogout(final HttpServletRequest request, final HttpServletResponse response) {

    final WebContext context = new J2EContext(request, response);
    final ProfileManager manager = new ProfileManager(context);
    manager.logout();/*from   w  w  w.  j  av  a  2s .co m*/

    final String url = context.getRequestParameter(Pac4jConstants.URL);
    if (url != null) {
        final String redirectUrl;
        if (Pattern.matches(this.logoutUrlPattern, url)) {
            redirectUrl = url;
        } else {
            redirectUrl = this.defaultUrl;
        }
        return "redirect:" + redirectUrl;
    }

    return null;
}

From source file:eagle.service.security.hive.resolver.HiveCommandResolver.java

@Override
public void validateRequest(GenericAttributeResolveRequest request) throws BadAttributeResolveRequestException {
    String query = request.getQuery();
    if (query == null || !Pattern.matches("[a-zA-Z]+", query)) {
        throw new BadAttributeResolveRequestException(HIVE_ATTRIBUTE_RESOLVE_FORMAT_HINT);
    }/*w  w  w .  j av  a  2  s . c  om*/
}

From source file:com.u2apple.tool.dao.DeviceXmlDaoJaxbImpl.java

private void loadVids() throws JAXBException {
    File dir = new File(Configuration.getProperty(Constants.VID_DIR));
    File[] files = dir.listFiles(new FilenameFilter() {
        @Override//w ww.  j  ava2  s . c o  m
        public boolean accept(File dir, String name) {
            return Pattern.matches(VID_FILE_NAME_PATTERN, name);
        }
    });
    if (files != null) {
        for (File file : files) {
            JAXBContext jaxbContext = JAXBContext.newInstance(VID.class);
            Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
            VID vid = (VID) jaxbUnmarshaller.unmarshal(file);
            if (vid != null) {
                staticMapFile.getVids().add(vid);
            }
        }
    }
}

From source file:com.matrimony.controller.ProfileController.java

@RequestMapping(value = "updateBasicProfile", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
@ResponseBody/*from   w ww  . ja v  a2  s  . c  om*/
public String updateBasicProfile(HttpServletRequest request, HttpServletResponse response, User userBasic) {
    User ssUser = (User) request.getSession().getAttribute("user");
    if (ssUser == null)
        return null;
    Timestamp currentTime = new Timestamp(System.currentTimeMillis());
    Properties props = new Properties();
    boolean wellForm = true;
    System.out.println(userBasic.getEmail());
    StringResouces sr = new StringResouces(StringResouces.vi_VN);
    if (!Pattern.matches(Regex.NAME, userBasic.getFirstName())) {
        wellForm = false;
        props.put("txtFirstName", sr.getData().get("firstNameInvalid"));
    }
    if (!Pattern.matches(Regex.NAME, userBasic.getLastName())) {
        wellForm = false;
        props.put("txtLastName", sr.getData().get("lastNameInvalid"));
    }
    if (!Pattern.matches(Regex.EMAIL, userBasic.getEmail())) {
        wellForm = false;
        props.put("txtEmail", sr.getData().get("emailInvalid"));
    }
    if (!Pattern.matches(Regex.PHONE, userBasic.getContactNumber())) {
        wellForm = false;
        props.put("txtPhone", sr.getData().get("phoneInvalid"));
    }
    if (!"12345678".equals(userBasic.getPassword())) {
        if (!Pattern.matches(Regex.PASSWORD, userBasic.getPassword())) {
            wellForm = false;
            props.put("txtPassword", sr.getData().get("passwordInvalid"));
        }
    }
    if (wellForm) {
        ssUser.setUsername(userBasic.getUsername());
        ssUser.setLastName(userBasic.getLastName());
        ssUser.setFirstName(userBasic.getFirstName());
        ssUser.setMiddleName(userBasic.getMiddleName());
        ssUser.setName(ssUser.getLastName() + " " + ssUser.getMiddleName() + " " + ssUser.getFirstName());
        ssUser.setEmail(userBasic.getEmail());
        System.out.println(userBasic.getPassword());
        if (!"12345678".equals(userBasic.getPassword())) {
            ssUser.setPassword(userBasic.getPassword());
            ssUser.setSalt(null);
        }
        ssUser.setUpdateTime(currentTime);
        UserDAO.Update(ssUser);
    }
    props.put("wellForm", wellForm);
    String json = Global.gson.toJson(props);
    System.out.println(json);
    return json;
}

From source file:csns.web.validator.DepartmentValidator.java

@Override
public void validate(Object target, Errors errors) {
    Department department = (Department) target;
    Long id = department.getId();

    String name = department.getName();
    if (!StringUtils.hasText(name))
        errors.rejectValue("name", "error.field.required");
    else {/* w  w  w . j  av a2  s. c  om*/
        Department d = departmentDao.getDepartmentByName(name);
        if (d != null && !d.getId().equals(id))
            errors.rejectValue("name", "error.department.name.taken");
    }

    String fullName = department.getFullName();
    if (!StringUtils.hasText(fullName))
        errors.rejectValue("fullName", "error.field.required");
    else {
        Department d = departmentDao.getDepartmentByFullName(fullName);
        if (d != null && !d.getId().equals(id))
            errors.rejectValue("fullName", "error.department.name.taken");
    }

    String abbreviation = department.getAbbreviation();
    if (!StringUtils.hasText(abbreviation))
        errors.rejectValue("abbreviation", "error.field.required");
    else if (!Pattern.matches("[a-z]+", abbreviation))
        errors.rejectValue("abbreviation", "error.department.abbreviation.invalid");
    else {
        Department d = departmentDao.getDepartment(abbreviation);
        if (d != null && !d.getId().equals(id))
            errors.rejectValue("abbreviation", "error.department.abbreviation.taken");
    }

    if (department.getAdministrators().size() == 0)
        errors.rejectValue("administrators", "error.field.required");
}

From source file:org.jboss.forge.shell.plugins.builtin.RunUrlPlugin.java

@DefaultCommand
public void run(@Option(description = "url...", required = true) final String url, final PipeOut pipeOut,
        final String... args) throws Exception {
    String urlPattern = "^(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]";
    if (Pattern.matches(urlPattern, url)) {
        URL remote = new URL(url);
        String temporalDir = System.getProperty("java.io.tmpdir");
        File tempFile = new File(temporalDir, "temp" + UUID.randomUUID().toString().replace("-", ""));
        tempFile.createNewFile();/* w  w  w.  j  a  v  a2 s.  com*/
        UnknownFileResource tempResource = new UnknownFileResource(factory, tempFile);

        PluginUtil.downloadFromURL(pipeOut, remote, tempResource);

        try {
            shell.execute(tempFile, args);
        } catch (IOException e) {
            throw new RuntimeException("error executing script from url " + url);
        }
    } else {
        throw new RuntimeException("resource must be a url: " + url);
    }
}