Example usage for java.util.regex Pattern split

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

Introduction

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

Prototype

public String[] split(CharSequence input) 

Source Link

Document

Splits the given input sequence around matches of this pattern.

Usage

From source file:kilim.tools.Asm.java

static String[] split(Pattern p, String s) {
    return p.split(s);
}

From source file:fr.xebia.springframework.security.core.userdetails.memory.ExtendedUserMapBuilder.java

/**
 * Build an {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser} from user attributes.
 * Protected for test purpose.//from   w w  w . j  a  va 2 s . c  o  m
 * @param userAttributes a list.
 * @return the build {@link fr.xebia.springframework.security.core.userdetails.ExtendedUser}.
 */
protected static ExtendedUser buildExtendedUser(String userAttributes) {
    if (userAttributes == null) {
        return null;
    }

    String[] userAttributesStringArray = StringUtils.delimitedListToStringArray(userAttributes, "=");

    if (userAttributesStringArray.length != 2) {
        return null; // we need a username and some attributes.
    }
    String username = userAttributesStringArray[0].trim();

    Pattern pattern = Pattern.compile("(enabled|disabled){1}$");
    Matcher matcher = pattern.matcher(userAttributesStringArray[1].trim());

    // Check activated attribute
    boolean activated = true;
    if (matcher.find()) {
        activated = ENABLED.equals(matcher.group());
    }

    // Check authorized IP addresses
    String allowedIpAddresses = "";
    pattern = Pattern.compile("@\\(.*\\)");
    matcher = pattern.matcher(userAttributesStringArray[1]);
    if (matcher.find()) {
        allowedIpAddresses = StringUtils.deleteAny(matcher.group(), "@() ");
    }

    // Get user password and roles :
    pattern = Pattern.compile("((,\\ *@\\(.*\\)){0,1}(\\ *,\\ *(enabled|disabled)\\ *){0,1})$");
    String[] remainingAttributes = pattern.split(userAttributesStringArray[1]);
    if (remainingAttributes.length != 1) {
        return null; // password and role(s) must have been defined.
    }

    String[] attributes = StringUtils.commaDelimitedListToStringArray(remainingAttributes[0]);
    if (attributes.length < 2) {
        return null; // we need at least one password and one role.
    }
    String password = attributes[0].trim();
    List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
    for (int i = 1; i < attributes.length; i++) {
        authorities.add(new GrantedAuthorityImpl(attributes[i].trim()));
    }

    ExtendedUser extendedUser = new ExtendedUser(username, password, activated, true, true, true, authorities);
    extendedUser.setAllowedRemoteAddresses(allowedIpAddresses);
    return extendedUser;
}

From source file:spade.query.neo4j.GetVertex.java

@Override
public Set<AbstractVertex> execute(String argument_string) {
    Pattern argument_pattern = Pattern.compile(",");
    String[] arguments = argument_pattern.split(argument_string);
    String constraints = arguments[0].trim();
    Map<String, List<String>> parameters = parseConstraints(constraints);
    Integer limit = null;/* w  ww  . java2s . co m*/
    if (arguments.length > 1)
        limit = Integer.parseInt(arguments[1].trim());

    return execute(parameters, limit);
}

From source file:spade.query.neo4j.GetEdge.java

@Override
public Set<AbstractEdge> execute(String argument_string) {
    Pattern argument_pattern = Pattern.compile(",");
    String[] arguments = argument_pattern.split(argument_string);
    String constraints = arguments[0].trim();
    Map<String, List<String>> parameters = parseConstraints(constraints);
    Integer limit = null;/*from   ww w  . j a v  a2  s .  c om*/
    if (arguments.length > 1)
        limit = Integer.parseInt(arguments[1].trim());

    return execute(parameters, limit);
}

From source file:eu.earthobservatory.org.StrabonEndpoint.Authenticate.java

/**
 * Authenticate user//from w  w  w.  java  2s  .c om
 * @throws IOException 
 * */
public boolean authenticateUser(String authorization, ServletContext context) throws IOException {
    Properties properties = new Properties();
    if (authorization == null)
        return false; // no authorization

    if (!authorization.toUpperCase().startsWith("BASIC "))
        return false; // only BASIC authentication

    // get encoded user and password, comes after "BASIC "
    String userpassEncoded = authorization.substring(6);
    // decode 
    String userpassDecoded = new String(Base64.decodeBase64(userpassEncoded));

    Pattern pattern = Pattern.compile(":");
    String[] credentials = pattern.split(userpassDecoded);
    // get credentials.properties as input stream
    InputStream input = new FileInputStream(context.getRealPath(CREDENTIALS_PROPERTIES_FILE));

    // load the properties
    properties.load(input);

    // close the stream
    input.close();

    // check if the given credentials are allowed       
    if (!userpassDecoded.equals(":") && credentials[0].equals(properties.get("username"))
            && credentials[1].equals(properties.get("password")))
        return true;
    else
        return false;
}

From source file:org.esupportail.lecture.domain.model.CustomManagedSource.java

/**
 * Returns the Id of the Parent (a managedCategory) of sourceProfile referred by this CustomManagedSource.
 * It gets it from the SourceProfile id (m:parentId:interneId)
 * @return "parentId"  It is ID of the ManagedCategoryProfile
 *//* www  . j  a  va 2s  . com*/
public String getManagedSourceProfileParentId() {
    if (LOG.isDebugEnabled()) {
        LOG.debug("getManagedSourceProfileParentId()");
    }
    // TODO (VR) : elementId has changed (contextId:m:profileId:sourceId)
    Pattern p = Pattern.compile(":");
    String[] items = p.split(this.getElementId());
    if (LOG.isDebugEnabled()) {
        LOG.debug("" + "getManagedSourceProfileParentId() - decomposed ID : contextId=" + items[0] + " typeId="
                + items[1] + " profileId=" + items[2] + " interneId=" + items[3]);
    }
    String parentId = items[0] + ":" + items[1] + ":" + items[2];
    return parentId;
}

From source file:net.duckling.ddl.service.export.impl.ExportAttachSaver.java

private String getNormalFilename(String filename) {
    // transform the "+" into " "
    filename = filename.replaceAll("\\+", " ");
    Pattern p = Pattern.compile("(\\%[0-9A-F]{2}){3}");
    String[] ss = p.split(filename);
    StringBuffer sb = new StringBuffer();
    Matcher m = p.matcher(filename);
    for (int i = 0; i < ss.length; i++) {
        sb.append(ss[i]);/*w  w  w  .  jav a 2s  . c  o m*/
        if (m.find()) {
            sb.append(code2Utf8(m.group()));
        }
    }
    return sb.toString();
}

From source file:com.neu.controller.OutcomeController.java

@RequestMapping(value = "/outcome.htm", method = RequestMethod.GET, headers = "Accept=*/*", produces = "application/json")
@ResponseStatus(HttpStatus.OK)//w ww .j  av a2 s. c om
public @ResponseBody String searchresult(HttpServletRequest request) throws Exception {
    System.out.println("in drugsearch controller");
    String action = request.getParameter("action");
    List<DrugOutcome> outcomes;
    String csvFile = "Merge.csv";
    String rpath = request.getRealPath("/");
    rpath = rpath + "/dataFiles/" + csvFile;
    Pattern pattern = Pattern.compile(",");

    BufferedReader in = new BufferedReader(new FileReader(rpath));
    outcomes = in.lines().skip(1).map(line -> {
        String[] x = pattern.split(line);
        return new DrugOutcome(x[3], x[20], x[7], x[6], x[8], x[13], x[4], x[5]);
    }).collect(Collectors.toList());
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
    mapper.writeValue(System.out, outcomes);

    //            Drugs drug=new Drugs("AZ","sn");
    return mapper.writeValueAsString(outcomes);
}

From source file:com.neu.controller.SearchController.java

@RequestMapping(value = "/search.htm", method = RequestMethod.GET, headers = "Accept=*/*", produces = "application/json")
@ResponseStatus(HttpStatus.OK)/*from   ww  w. j  a v a2 s .c om*/
public @ResponseBody String searchresult(HttpServletRequest request) throws Exception {
    System.out.println("in drugsearch controller");
    String action = request.getParameter("action");
    List<Drugs> drugs;
    String csvFile = "UserSearch.csv";
    String rpath = request.getRealPath("/");
    rpath = rpath + "/dataFiles/" + csvFile;

    Pattern pattern = Pattern.compile(",");

    BufferedReader in = new BufferedReader(new FileReader(rpath));
    drugs = in.lines().skip(1).map(line -> {
        String[] x = pattern.split(line);
        return new Drugs(x[0], x[3]);
    }).collect(Collectors.toList());
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationConfig.Feature.INDENT_OUTPUT);
    mapper.writeValue(System.out, drugs);

    //            Drugs drug=new Drugs("AZ","sn");
    return mapper.writeValueAsString(drugs);
}

From source file:de.tuberlin.dima.aim3.assignment1.BookAndAuthorJoinTest.java

Multimap<String, Book> readBooksByAuthors(File outputFile) throws IOException {
    Multimap<String, Book> booksByAuthors = HashMultimap.create();

    Pattern separator = Pattern.compile("\t");
    for (String line : Files.readLines(outputFile, Charsets.UTF_8)) {
        String[] tokens = separator.split(line);
        booksByAuthors.put(tokens[0], new Book(tokens[1], Integer.parseInt(tokens[2])));
    }//from w  w  w. j  a va 2 s  .  c  om
    return booksByAuthors;
}