2 * Copyright (C) 2010 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package cz.cvut.fel.dce.barcodescanner.result.supplement;
19 import android.content.Context;
20 import android.widget.TextView;
22 import cz.cvut.fel.dce.barcodescanner.HttpHelper;
23 import cz.cvut.fel.dce.barcodescanner.R;
24 import cz.cvut.fel.dce.barcodescanner.history.HistoryManager;
25 import com.google.zxing.client.result.URIParsedResult;
27 import java.io.IOException;
29 import java.net.URISyntaxException;
31 final class URIResultInfoRetriever extends SupplementalInfoRetriever {
33 private static final int MAX_REDIRECTS = 5;
35 private final URIParsedResult result;
36 private final String redirectString;
38 URIResultInfoRetriever(TextView textView, URIParsedResult result, HistoryManager historyManager, Context context) {
39 super(textView, historyManager);
40 redirectString = context.getString(R.string.msg_redirect);
45 void retrieveSupplementalInfo() throws IOException {
48 oldURI = new URI(result.getURI());
49 } catch (URISyntaxException ignored) {
52 URI newURI = HttpHelper.unredirect(oldURI);
54 while (count++ < MAX_REDIRECTS && !oldURI.equals(newURI)) {
55 append(result.getDisplayResult(),
57 new String[] { redirectString + " : " + newURI },
60 newURI = HttpHelper.unredirect(newURI);