2 * Sone - TextFilter.java - Copyright © 2011–2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU 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.
9 * This program 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 General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.text;
21 * Filter for newly inserted text. This filter strips HTTP links to the local
22 * node of identifying marks, e.g. a link to “http://localhost:8888/KSK@gpl.txt”
23 * will be converted to “KSK@gpl.txt”. This will only work for links that point
24 * to the same address Sone is accessed by, so if you access Sone using
25 * localhost:8888, links to 127.0.0.1:8888 will not be removed.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29 public class TextFilter {
32 * Filters the given text, stripping the host header part for links to the
36 * The host header from the request
39 * @return The filtered text
41 public static String filter(String hostHeader, String text) {
43 /* filter http(s) links to own node. */
44 if (hostHeader != null) {
46 for (String toRemove : new String[] { "http://" + hostHeader + "/", "https://" + hostHeader + "/", "http://" + hostHeader, "https://" + hostHeader }) {
47 while (line.indexOf(toRemove) != -1) {
48 line = line.replace(toRemove, "");