📄 resultlistentry.java
字号:
/* * This file is part of Caliph & Emir. * * Caliph & Emir 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 2 of the License, or * (at your option) any later version. * * Caliph & Emir 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 Caliph & Emir; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Copyright statement: * -------------------- * (c) 2002-2004 by Mathias Lux (mathias@juggle.at) * http://www.juggle.at *//* * Created by Mathias Lux, mathias@juggle.at * User: Mathias Lux, mathias@juggle.at * Date: 09.09.2002 * Time: 20:51:41 */package at.lux.fotoretrieval;import org.jdom.Document;import org.jdom.Element;import org.jdom.JDOMException;import org.jdom.Namespace;import org.jdom.output.XMLOutputter;import org.jdom.output.Format;import org.jdom.transform.JDOMResult;import org.jdom.transform.JDOMSource;import javax.xml.transform.*;import javax.xml.transform.stream.StreamSource;import java.io.IOException;import java.util.List;import java.text.DecimalFormat;import java.net.URL;/** * ResultListEntry * * @author Mathias Lux, mathias@juggle.at */public class ResultListEntry implements Comparable{ private double relevance; private Element documentRoot; private String filePath = null; private String thumbPath = null; private String descriptionPath = null; private String HTMLSummary = null; private static DecimalFormat df = ((DecimalFormat) DecimalFormat.getInstance()); private int quality = -1; private static Transformer myTransformer = null; public ResultListEntry(double relevance, Element documentRoot, String descriptionPath) { this.relevance = relevance; this.documentRoot = documentRoot; this.descriptionPath = descriptionPath; df.setMaximumFractionDigits(2); List results = RetrievalToolkit.xpathQuery(documentRoot, "//MediaProfile[@master='true']/MediaInstance/MediaLocator/MediaUri", null); if (results.size() > 0) { filePath = ((Element) results.get(0)).getTextTrim(); if (results.size() > 1) { thumbPath = ((Element) results.get(1)).getTextTrim(); } } // /Mpeg7/Description/MultimediaContent/Image/MediaInformation/MediaProfile/MediaFormat/VisualCoding/Frame results = RetrievalToolkit.xpathQuery(documentRoot, "//MediaProfile/MediaFormat/VisualCoding/Frame[number(@height) < 121 and number(@width) < 121]", null); if (results.size() > 0) { Element frame = ((Element) results.get(0)); Element profile = (Element) frame.getParent().getParent().getParent(); Namespace mpeg7 = profile.getNamespace(); Element uri = profile.getChild("MediaInstance", mpeg7).getChild("MediaLocator", mpeg7).getChild("MediaUri", mpeg7); thumbPath = uri.getTextTrim(); } // quality results = RetrievalToolkit.xpathQuery(documentRoot, "//QualityRating[@type='subjective']/RatingValue", null); if (results.size() > 0) { quality = Integer.parseInt(((Element) results.get(0)).getTextTrim()); } else { quality = -1; } HTMLSummary = getSummary(); this.documentRoot = null; documentRoot = null; } public double getRelevance() { return relevance; } public int getQuality() { return quality; } public String getFilePath() { return filePath; } public String getThumbPath() { return thumbPath; } public void setThumbPath(String thumbPath) { this.thumbPath = thumbPath; } /** * Gets path to MPEG-7 file * @return Path to MPEG-7 file */ public String getDescriptionPath() { return descriptionPath; } /** * Summary of result * @return Summary of result based on HTML 3.2 */ public String getHTMLSummary() { return HTMLSummary; } private String getSummary() { XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());// outputter.setOmitEncoding(true);// outputter.setOmitDeclaration(true); String doc = null; Document _d = null; try { _d = transform(documentRoot.getDocument()); } catch (JDOMException e) { debug("JDOMException " + e.getMessage()); } if (_d != null) { String f_name = filePath ; if (f_name.lastIndexOf('/')!=-1) { f_name = f_name.substring(f_name.lastIndexOf('/') + 1); } if (f_name.lastIndexOf('\\')!=-1) { f_name = f_name.substring(f_name.lastIndexOf('\\') + 1); } doc = outputter.outputString(_d); doc = "<html>" + doc.substring(doc.indexOf('>') + 1); doc = doc.replaceAll("<br />", "<br>"); doc = doc.replaceAll("<head />", ""); doc = doc.replaceAll("<td />", "<td>n.a.</td>"); doc = doc.replaceAll("_relevance_", "" + df.format(relevance)); doc = doc.replaceAll("_filename_", f_name);// System.out.println(doc); } return doc; } private Document transform(Document in) throws JDOMException { Document d = null; try { Transformer transformer = getTransformer(); JDOMResult out = new JDOMResult(); transformer.transform(new JDOMSource(in), out); d = out.getDocument(); } catch (TransformerException e) { debug("Transformation failed, TransformerException: " + e.getMessageAndLocation()); } catch (TransformerFactoryConfigurationError error) { debug("Transformation failed, " + error.toString()); } catch (IOException e) { debug("Transformation failed, IOException: " + e.getMessage()); } return d; } private static Transformer getTransformer() throws IOException, TransformerConfigurationException { Transformer transformer = myTransformer; if (transformer == null) { URL resource = RetrievalToolkit.class.getResource("data/html-short.xsl"); StreamSource source = new StreamSource(resource.openStream()); transformer = TransformerFactory.newInstance().newTransformer(source); } return transformer; } private void debug(String message) { System.out.println("[at.lux.fotoretrieval.ResultListEntry]" + message); } public int compareTo(Object o) { ResultListEntry r = (ResultListEntry) o; return (int) Math.signum(r.getRelevance()-relevance); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -