Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package se.proxus.models;
- import org.apache.commons.lang3.StringUtils;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Document;
- import org.jsoup.nodes.Element;
- public class ImageBlockModel {
- private long id;
- private int width;
- private int height;
- private String url;
- private String name;
- private String source;
- private String character;
- private String tags;
- private String artist;
- private String extension;
- public ImageBlockModel(final String content) {
- try {
- parseContent(content);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void parseContent(final String content) throws Exception {
- Document imageBlock = Jsoup.parse(content);
- String shuushuu = "http://e-shuushuu.net";
- setUrl(shuushuu + imageBlock.select(".thumb_image").attr("href"));
- setExtension(getUrl().substring(getUrl().lastIndexOf(".") + 1));
- setName(imageBlock.select(".title").text());
- setId(Long.parseLong(getName().split("#")[1]));
- setArtist(imageBlock.select("#quicktag3_" + getId()).select("a").text()
- .replaceAll("\\(.*\\)", "").trim());
- setSource(imageBlock.select("#quicktag2_" + getId()).select("a").text());
- for (Element characters : imageBlock.select("#quicktag4_" + getId()).select(".tag")) {
- setCharacter(getCharacter() + " & " + characters.select("a").text());
- }
- setCharacter(getCharacter() == null ? "Original Character" : getCharacter().split(" & ")[1]
- .replace("& &", "&"));
- for (Element tag : imageBlock.select("#quicktag1_" + getId()).select(".tag")) {
- setTags(getTags() + tag.select("a").text() + ", ");
- }
- setTags(getTags() == null ? "No Tags" : getTags().substring(0, getTags().length() - 2)
- .replace("null", ""));
- for (Element dimensions : imageBlock.select("dd")) {
- String text = dimensions.text();
- if (text.contains("x")) {
- String[] dimension = text.replaceAll("\\(.*\\)", "").trim().split("x");
- if (StringUtils.isNumeric(dimension[0]) && StringUtils.isNumeric(dimension[1])) {
- setWidth(Integer.parseInt(dimension[0]));
- setHeight(Integer.parseInt(dimension[1]));
- }
- }
- }
- }
- public long getId() {
- return id;
- }
- public void setId(final long id) {
- this.id = id;
- }
- public int getWidth() {
- return width;
- }
- public void setWidth(final int width) {
- this.width = width;
- }
- public int getHeight() {
- return height;
- }
- public void setHeight(final int height) {
- this.height = height;
- }
- public String getUrl() {
- return url;
- }
- public void setUrl(final String url) {
- this.url = url;
- }
- public String getName() {
- return name;
- }
- public void setName(final String name) {
- this.name = name;
- }
- public String getSource() {
- return source;
- }
- public void setSource(final String source) {
- this.source = source;
- }
- public String getCharacter() {
- return character;
- }
- public void setCharacter(final String character) {
- this.character = character;
- }
- public String getArtist() {
- return artist;
- }
- public void setArtist(final String artist) {
- this.artist = artist;
- }
- public String getTags() {
- return tags;
- }
- public void setTags(final String tags) {
- this.tags = tags;
- }
- public String getExtension() {
- return extension;
- }
- public void setExtension(final String extension) {
- this.extension = extension;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement