| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| Decoder |
|
| 2.4285714285714284;2.429 |
| 1 | /* Copyright (2007) Schibsted Søk AS | |
| 2 | * This file is part of SESAT. | |
| 3 | * | |
| 4 | * SESAT is free software: you can redistribute it and/or modify | |
| 5 | * it under the terms of the GNU Affero General Public License as published by | |
| 6 | * the Free Software Foundation, either version 3 of the License, or | |
| 7 | * (at your option) any later version. | |
| 8 | * | |
| 9 | * SESAT is distributed in the hope that it will be useful, | |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 | * GNU Affero General Public License for more details. | |
| 13 | * | |
| 14 | * You should have received a copy of the GNU Affero General Public License | |
| 15 | * along with SESAT. If not, see <http://www.gnu.org/licenses/>. | |
| 16 | */ | |
| 17 | package no.sesat.search.result; | |
| 18 | ||
| 19 | import java.io.UnsupportedEncodingException; | |
| 20 | import java.util.Date; | |
| 21 | import java.util.Calendar; | |
| 22 | ||
| 23 | /** | |
| 24 | * Created by IntelliJ IDEA. | |
| 25 | * User: SSTHKJER | |
| 26 | * Date: 13.jan.2006 | |
| 27 | * Time: 11:32:54 | |
| 28 | * To change this template use File | Settings | File Templates. | |
| 29 | * | |
| 30 | * @todo make this a generic helper class for functions needed in templates | |
| 31 | * | |
| 32 | */ | |
| 33 | ||
| 34 | ||
| 35 | public class Decoder { | |
| 36 | ||
| 37 | 0 | public Decoder() {} |
| 38 | ||
| 39 | public String yip_decoder(String s) { | |
| 40 | try { | |
| 41 | 0 | s = java.net.URLDecoder.decode(s, "UTF-8"); |
| 42 | 0 | } catch (UnsupportedEncodingException e) { |
| 43 | 0 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| 44 | 0 | } |
| 45 | 0 | return s; |
| 46 | } | |
| 47 | ||
| 48 | //function for infotext, must decode before stripping string | |
| 49 | public String yip_decoder(String s, int length) { | |
| 50 | try { | |
| 51 | 0 | s = java.net.URLDecoder.decode(s, "UTF-8"); |
| 52 | 0 | if (s.length() < length) { |
| 53 | 0 | length = s.length(); |
| 54 | 0 | s = s.substring(0, length); |
| 55 | } else { | |
| 56 | /* Make sure we are not cutting the string in the middle of a HTML tag. */ | |
| 57 | 0 | if (s.indexOf("<",length) > s.indexOf(">", length)){ |
| 58 | 0 | length = s.indexOf(">", length) + 1; |
| 59 | 0 | s = s.substring(0, length); |
| 60 | } else { | |
| 61 | 0 | s = s.substring(0, length) + ".."; |
| 62 | } | |
| 63 | } | |
| 64 | 0 | } catch (UnsupportedEncodingException e) { |
| 65 | 0 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| 66 | 0 | } |
| 67 | 0 | return s; |
| 68 | } | |
| 69 | ||
| 70 | public String ypurl(String s) { | |
| 71 | ||
| 72 | 0 | if (!s.startsWith("http://")) { |
| 73 | 0 | s = "http://" + s; |
| 74 | } | |
| 75 | 0 | return s; |
| 76 | } | |
| 77 | ||
| 78 | public boolean yip_checknames(String s1, String s2) { | |
| 79 | ||
| 80 | 0 | if (s1.equalsIgnoreCase(s2)) { |
| 81 | 0 | return true; |
| 82 | } else | |
| 83 | 0 | return false; |
| 84 | } | |
| 85 | ||
| 86 | public boolean checkInfoTextLength(String s, int i) { | |
| 87 | try { | |
| 88 | 0 | s = java.net.URLDecoder.decode(s, "UTF-8"); |
| 89 | 0 | } catch (UnsupportedEncodingException e) { |
| 90 | 0 | e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. |
| 91 | 0 | } |
| 92 | 0 | int length = s.length(); |
| 93 | 0 | if (length > i) |
| 94 | 0 | return true; |
| 95 | ||
| 96 | 0 | return false; |
| 97 | } | |
| 98 | ||
| 99 | //to be inserted in link to olympic tv-program | |
| 100 | public String dayOfMonth() { | |
| 101 | 0 | Calendar cal = Calendar.getInstance(); |
| 102 | 0 | int day = cal.get(Calendar.DAY_OF_MONTH); |
| 103 | ||
| 104 | 0 | return Integer.toString(day); |
| 105 | } | |
| 106 | } |