⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 referencetaglet.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
字号:
/*
 *  YALE - Yet Another Learning Environment
 *  Copyright (C) 2001-2004
 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, 
 *          Katharina Morik, Oliver Ritthoff
 *      Artificial Intelligence Unit
 *      Computer Science Department
 *      University of Dortmund
 *      44221 Dortmund,  Germany
 *  email: yale-team@lists.sourceforge.net
 *  web:   http://yale.cs.uni-dortmund.de/
 *
 *  This program 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. 
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 *  USA.
 */
package edu.udo.cs.yale.doc;

import com.sun.tools.doclets.*;
import com.sun.javadoc.*;
import java.util.Map;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.kobjects.jdbc.TableManager;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.MalformedURLException;
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;

public class ReferenceTaglet implements Taglet {

    private static final String[] DOCUMENT_EXTENSIONS = {"ps", "ps.gz", "pdf", "pdf.gz", "ppt"};

    private static final String NAME = "yale.reference";
    public String getName() { return NAME; }
    public boolean inField() { return true; }
    public boolean inConstructor() { return true; }
    public boolean inMethod() { return true; }
    public boolean inOverview() { return true; }
    public boolean inPackage() { return true; }
    public boolean inType() { return true; }
    public boolean isInlineTag() { return true; }

    private static Method getResultSetMethod;
    private static File yaleHome;

    /** Find TableManager.getResultSet() method by reflection, since as far as we know it
     *  is not possible to include kdb.jar in the classpath. */
    static {
	//System.out.println("Classpath "+System.getProperty("java.home"));
	String yaleHomeName = System.getProperty("yale.home");
	File yaleHome = null;
	if (yaleHomeName == null) {
	    File buildDir = new File(ReferenceTaglet.class.getResource("../../../../..").getFile());
	    yaleHome = buildDir.getParentFile();
	    System.err.println("yale.home is not set! Assuming "+yaleHome);
//  	    yaleHome = new File(System.getProperty("user.home"), "yale");
//  	    if (!yaleHome.exists()) {
//  		System.err.println("yale.home is not set! Cannot guess!");
//  	    } else {
//  		System.err.println("yale.home is not set! Assuming "+yaleHome);
//  	    }
	} else {
	    yaleHome = new File(yaleHomeName);
	}

	if (yaleHome != null) {
	    try {
		URL url = new URL("file", null, 
				  new File(yaleHome, "lib"+File.separator+"kdb.jar").getAbsolutePath());
		ClassLoader classLoader = new URLClassLoader(new URL[] { url });
		Class tableManagerClass = classLoader.loadClass("org.kobjects.jdbc.TableManager");
		getResultSetMethod = tableManagerClass.getMethod("getResultSet",
								 new Class[] { String.class, int.class });
	    } catch (MalformedURLException e) {
		e.printStackTrace();
	    } catch (ClassNotFoundException e) {
		System.err.println("Cannot find class org.kobjects.jdbc.TableManager");
	    } catch (NoSuchMethodException e) {
		System.err.println("Cannot find method org.kobjects.jdbc.TableManager.getResultSet(String,int)");
	    }
	}
    }

    public static void register(Map tagletMap) {
	ReferenceTaglet tag = new ReferenceTaglet();
	Taglet t = (Taglet) tagletMap.get(tag.getName());
	if (t != null) {
	    tagletMap.remove(tag.getName());
	}
	tagletMap.put(tag.getName(), tag);
    }

    public String toString(Tag tag) {
        return toString(new Tag[] { tag });
    }
    
    public String toString(Tag[] tags) {
	if (tags.length == 0) {
	    return null;
	}
	String result ="<dt><b>Bibliography:</b></dt><dd>";
	result += "<ul>";
	for (int i = 0; i < tags.length; i++) {
	    String key = tags[i].text().trim();
	    String entry = getBibEntry(key);
	    result += "<li>" + ((entry != null) ? entry : key) + "</li>";
	}
	result += "</ul></dd>";
	return result;
    }


    private static String getBibEntry(String key) {
	if (getResultSetMethod == null) return null;

	File bibFile = new File(yaleHome, "tutorial"+File.separator+"YaleTutorial.bib");
	if (!bibFile.exists()) {
	    System.err.println("yale.home is not set! Cannot find YaleTutorial.bib");
	    return null;
	}
	ResultSet literatur = null;
	try {
	    literatur = (ResultSet)getResultSetMethod.invoke(null, new Object[] { "bibtex:"+ bibFile, 
										  new Integer(TableManager.READ)});
	} catch (IllegalAccessException e) {
	    System.err.println("Cannot access TableManager.getResultSet(): "+e);
	    getResultSetMethod = null;
	    return null;
	} catch (InvocationTargetException e) {
	    System.err.println("Exception in TableManager.getResultSet(): "+e.getCause());
	}
	
	if (literatur == null) return null;
	
	try {
	    boolean found = true;
	    while (literatur.next()) {
		String bibkey = literatur.getString("bibkey");
		if (bibkey == null) continue;
		if (bibkey.equals(key)) {
		    String result = "["+key+"] ";
		    result += escape(literatur.getString("author"))+": "+
			"<i>"+escape(literatur.getString("title"))+"</i> ";
		    String in = literatur.getString("booktitle");
		    if (in != null) {
			result += "In "+escape(in)+" ";
		    }
		    result += "("+literatur.getString("year")+")";
		    
		    for (int i = 0; i < DOCUMENT_EXTENSIONS.length; i++) {
			String link = getLink(key, DOCUMENT_EXTENSIONS[i]);
			if (link != null) {
			result += link;
		    }
		    }
		    
		    result += "</li>";
		    return result;
		}
	    }
	    System.err.println("Bibkey not found: "+key);
	    return null;
	} catch (SQLException e) {
	    System.err.println("SQLException occured: "+e.getMessage());
	    return null;
	}
    }

    private static String getLink(String key, String ext) {
	key = key.toLowerCase().replaceAll("/","_");
	File file = new File("/home/info-systeme/WWW/doc/DOKUMENTE/"+key+"."+ext);
	if (file.exists()) {
	    return "<a href=\"http://www-ai.cs.uni-dortmund.de/DOKUMENTE/"+key+"."+ext+"\">["+ext+"]</a>";
	} else {
	    return null;
	}	
    }

    private static String escape(String str) {
	if (str == null) return null;
	String escaped = str;
//  	escaped = escaped.replaceAll("?", "&auml;");
//    	escaped = escaped.replaceAll("?", "&ouml;");
//    	escaped = escaped.replaceAll("?", "&uuml;");
//    	escaped = escaped.replaceAll("?", "&Auml;");
//    	escaped = escaped.replaceAll("?", "&Ouml;");
//    	escaped = escaped.replaceAll("?", "&Uuml;");
//    	escaped = escaped.replaceAll("?", "&szlig;");
	escaped = escaped.replaceAll("<", "&lt;");
	escaped = escaped.replaceAll(">", "&gt;");
	escaped = escaped.replaceAll("\\{", "");
	escaped = escaped.replaceAll("\\}", "");
	return escaped;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -