001/* 002 * Copyright 2010-2013 Ning, Inc. 003 * 004 * Ning licenses this file to you under the Apache License, version 2.0 005 * (the "License"); you may not use this file except in compliance with the 006 * License. You may obtain a copy of the License at: 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations 014 * under the License. 015 */ 016 017package com.ning.billing.recurly; 018 019import java.util.regex.Matcher; 020import java.util.regex.Pattern; 021 022public abstract class PaginationUtils { 023 024 public static String[] getLinks(final String linkHeader) { 025 String start = null; 026 String prev = null; 027 String next = null; 028 029 final Pattern pattern = Pattern.compile("\\<([^>]+)\\>; rel=\\\"([^\"]+)\\\""); 030 final Matcher matcher = pattern.matcher(linkHeader); 031 while (matcher.find()) { 032 if ("start".equals(matcher.group(2))) { 033 start = matcher.group(1); 034 } else if ("prev".equals(matcher.group(2))) { 035 prev = matcher.group(1); 036 } else if ("next".equals(matcher.group(2))) { 037 next = matcher.group(1); 038 } 039 } 040 041 return new String[]{start, prev, next}; 042 } 043}