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 public Decoder() {}
38
39 public String yip_decoder(String s) {
40 try {
41 s = java.net.URLDecoder.decode(s, "UTF-8");
42 } catch (UnsupportedEncodingException e) {
43 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
44 }
45 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 s = java.net.URLDecoder.decode(s, "UTF-8");
52 if (s.length() < length) {
53 length = s.length();
54 s = s.substring(0, length);
55 } else {
56 /* Make sure we are not cutting the string in the middle of a HTML tag. */
57 if (s.indexOf("<",length) > s.indexOf(">", length)){
58 length = s.indexOf(">", length) + 1;
59 s = s.substring(0, length);
60 } else {
61 s = s.substring(0, length) + "..";
62 }
63 }
64 } catch (UnsupportedEncodingException e) {
65 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
66 }
67 return s;
68 }
69
70 public String ypurl(String s) {
71
72 if (!s.startsWith("http://")) {
73 s = "http://" + s;
74 }
75 return s;
76 }
77
78 public boolean yip_checknames(String s1, String s2) {
79
80 if (s1.equalsIgnoreCase(s2)) {
81 return true;
82 } else
83 return false;
84 }
85
86 public boolean checkInfoTextLength(String s, int i) {
87 try {
88 s = java.net.URLDecoder.decode(s, "UTF-8");
89 } catch (UnsupportedEncodingException e) {
90 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
91 }
92 int length = s.length();
93 if (length > i)
94 return true;
95
96 return false;
97 }
98
99 //to be inserted in link to olympic tv-program
100 public String dayOfMonth() {
101 Calendar cal = Calendar.getInstance();
102 int day = cal.get(Calendar.DAY_OF_MONTH);
103
104 return Integer.toString(day);
105 }
106 }