From 09484955dc5ee4b4511f5b6cea89da60f2ef3071 Mon Sep 17 00:00:00 2001 From: Michael Peter Christen Date: Fri, 27 Apr 2012 17:48:51 +0200 Subject: [PATCH] added new entry class for embed tags --- .../yacy/document/parser/html/EmbedEntry.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 source/net/yacy/document/parser/html/EmbedEntry.java diff --git a/source/net/yacy/document/parser/html/EmbedEntry.java b/source/net/yacy/document/parser/html/EmbedEntry.java new file mode 100644 index 000000000..f64d02427 --- /dev/null +++ b/source/net/yacy/document/parser/html/EmbedEntry.java @@ -0,0 +1,79 @@ +/** + * EmbedEntry + * Copyright 2012 by Michael Peter Christen, mc@yacy.net, Frankfurt am Main, Germany + * First released 27.04.2012 at http://yacy.net + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program in the file lgpl21.txt + * If not, see . + */ + +package net.yacy.document.parser.html; + +import net.yacy.cora.document.MultiProtocolURI; + +public class EmbedEntry { + + private final MultiProtocolURI url; + private final int width, height; + private final String type, pluginspage; + + public EmbedEntry(final MultiProtocolURI url, int width, int height, String type, String pluginspage) { + this.url = url; + this.width = width; + this.height = height; + this.type = type; + this.pluginspage = pluginspage; + } + + public MultiProtocolURI getUrl() { + return this.url; + } + + public final int getWidth() { + return this.width; + } + + public final int getHeight() { + return this.height; + } + + public final String getType() { + return this.type; + } + + public final String getPluginspage() { + return this.pluginspage; + } + + @Override + public String toString() { + return " 0 ? " type=\"" + this.type + "\"" : "") + + (this.pluginspage != null && this.pluginspage.length() > 0 ? " pluginspage=\"" + this.pluginspage + "\"" : "") + + (this.width >= 0 ? " width=\"" + this.width + "\"" : "") + + (this.height >= 0 ? " height=\"" + this.height + "\"" : "") + + ">"; + } + + @Override + public int hashCode() { + // if htmlFilterImageEntry elements are stored in a TreeSet, the biggest images shall be listed first + // this hash method therefore tries to compute a 'perfect hash' based on the size of the images + // unfortunately it can not be ensured that all images get different hashes, but this should appear + // only in very rare cases + if (this.width < 0 || this.height < 0) + return /*0x7FFF0000 |*/ (this.url.hashCode() & 0xFFFF); + return ((0x7FFF - (((this.width * this.height) >> 9) & 0x7FFF)) << 16) | (this.url.hashCode() & 0xFFFF); + } +}