// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/model/Item.java
// public interface Item {
// 
// 	public String getTitle();
// 
// 	public String getNavigationLink();
// 
// 	public String getDownloadLink();
// 
// 	public Image getImage();
// 
// 	public boolean isEnabled();
// 
// }
// 
// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/model/search/SearchPage.java
// public abstract class SearchPage implements Page {
// 
// 	protected String url;
// 
// 	private String query;
// 
// 	public SearchPage(String url) {
// 		this.url = url;
// 	}
// 
// 	public String getSubtitle() throws IOException {
// 		return "Общо " + getItems().length + " резултата";
// 	}
// 
// 	public int getItemsCount() throws IOException {
// 		return getItems().length;
// 	}
// 
// 	public Item[] getItems(int index, int length) throws IOException {
// 		int len = Math.min(length, getItems().length - index);
// 		Item[] result = new Item[len];
// 		System.arraycopy(getItems(), index, result, 0, len);
// 		return result;
// 	}
// 
// 	public Item getItem(int index) throws IOException {
// 		return getItems()[index];
// 	}
// 
// 	protected String getQuery() throws IOException {
// 		if (query == null) {
// 			String urlQuery = new URL(url).getQuery();
// 			// remove all params after the first one
// 			int ampIndex = urlQuery.indexOf('&');
// 			if (ampIndex != -1) {
// 				urlQuery = urlQuery.substring(0, ampIndex);
// 			}
// 			// extract the value of the first param
// 			int eqIndex = urlQuery.indexOf('=');
// 			if (eqIndex != -1) {
// 				query = urlQuery.substring(eqIndex + 1);
// 			}
// 		}
// 		return query;
// 	}
// 	
// }


import name.raev.kaloyan.kindle.chitanka.model.Item;
import name.raev.kaloyan.kindle.chitanka.model.search.SearchPage;
import java.io.IOException;
import org.json.simple.parser.ParseException;
/**
 * Copyright 2017 Kaloyan Raev
 * 
 * This file is part of chitanka4kindle.
 * 
 * chitanka4kindle is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * chitanka4kindle is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with chitanka4kindle.  If not, see <http://www.gnu.org/licenses/>.
 */
package name.raev.kaloyan.kindle.chitanka.model.search.text;




public class SearchTextsPage extends SearchPage {

	private Text[] texts;
	private Item[] items;

	public SearchTextsPage(String url) {
		super(url);
	}

	public String getTitle() throws IOException {
		return "Творби с „" + getQuery() + "“";
	}

	public Item[] getItems() throws IOException {
		if (items == null) {
			items = new Item[getTexts().length];
			for (int i = 0; i < items.length; i++) {
				items[i] = new TextItem(getTexts()[i]);
			}
		}
		return items;
	}

// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/model/Item.java
// public interface Item {
// 
// 	public String getTitle();
// 
// 	public String getNavigationLink();
// 
// 	public String getDownloadLink();
// 
// 	public Image getImage();
// 
// 	public boolean isEnabled();
// 
// }
// 
// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/model/search/SearchPage.java
// public abstract class SearchPage implements Page {
// 
// 	protected String url;
// 
// 	private String query;
// 
// 	public SearchPage(String url) {
// 		this.url = url;
// 	}
// 
// 	public String getSubtitle() throws IOException {
// 		return "Общо " + getItems().length + " резултата";
// 	}
// 
// 	public int getItemsCount() throws IOException {
// 		return getItems().length;
// 	}
// 
// 	public Item[] getItems(int index, int length) throws IOException {
// 		int len = Math.min(length, getItems().length - index);
// 		Item[] result = new Item[len];
// 		System.arraycopy(getItems(), index, result, 0, len);
// 		return result;
// 	}
// 
// 	public Item getItem(int index) throws IOException {
// 		return getItems()[index];
// 	}
// 
// 	protected String getQuery() throws IOException {
// 		if (query == null) {
// 			String urlQuery = new URL(url).getQuery();
// 			// remove all params after the first one
// 			int ampIndex = urlQuery.indexOf('&');
// 			if (ampIndex != -1) {
// 				urlQuery = urlQuery.substring(0, ampIndex);
// 			}
// 			// extract the value of the first param
// 			int eqIndex = urlQuery.indexOf('=');
// 			if (eqIndex != -1) {
// 				query = urlQuery.substring(eqIndex + 1);
// 			}
// 		}
// 		return query;
// 	}
// 	
// }


// Path: src/main/java/name/raev/kaloyan/kindle/chitanka/model/search/text/SearchTextsPage.java
import name.raev.kaloyan.kindle.chitanka.model.Item;
import name.raev.kaloyan.kindle.chitanka.model.search.SearchPage;
import java.io.IOException;
import org.json.simple.parser.ParseException;

/**
 * Copyright 2017 Kaloyan Raev
 * 
 * This file is part of chitanka4kindle.
 * 
 * chitanka4kindle is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * chitanka4kindle is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with chitanka4kindle.  If not, see <http://www.gnu.org/licenses/>.
 */
package name.raev.kaloyan.kindle.chitanka.model.search.text;




public class SearchTextsPage extends SearchPage {

	private Text[] texts;
	private Item[] items;

	public SearchTextsPage(String url) {
		super(url);
	}

	public String getTitle() throws IOException {
		return "Творби с „" + getQuery() + "“";
	}

	public Item[] getItems() throws IOException {
		if (items == null) {
			items = new Item[getTexts().length];
			for (int i = 0; i < items.length; i++) {
				items[i] = new TextItem(getTexts()[i]);
			}
		}
		return items;
	}

	private Text[] getTexts() throws IOException {