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

📄 xhistorydefaultserializer.java

📁 XBrowser是一个完全免费并且开源的Web浏览器
💻 JAVA
字号:
/****************************************************************
*              XBrowser  -  eXtended web Browser                *
*                                                               *
*           Copyright (c) 2000-2001  Armond Avanes              *
*     Refer to ReadMe & License files for more information      *
*                                                               *
*                                                               *
*                      By: Armond Avanes                        *
*       Armond555@yahoo.com     &    Armond333@yahoo.com        *
*                http://xbrowser.sourceforge.net/               *
*****************************************************************/
package xbrowser.history.io;

import java.io.*;
import java.net.*;
import java.util.*;
import java.text.*;

import xbrowser.*;
import xbrowser.util.*;
import xbrowser.history.*;

import org.w3c.dom.*;

public class XHistoryDefaultSerializer implements XHistorySerializer
{
	public XHistoryDefaultSerializer()
	{
	}

	public void importHistory(String file_name, XHistoryManager history_manager) throws Exception
	{
	URL dtd_url = XRepository.getResourceManager().getResourceURL(DTD_URL);
	Document doc = XMLManager.readFileDocument(file_name, DTD_SYMBOL, dtd_url);
	Node node = XMLManager.findNode(doc,"xhistory").getNextSibling().getFirstChild();

		while( node!=null )
		{
			if( node instanceof Element )
			{
				if( node.getNodeName().equals("xhistorydata") )
					loadHistoryData(node,history_manager);
			}

			node = node.getNextSibling();
		}
	}

	private void loadHistoryData(Node node, XHistoryManager history_manager) throws DOMException
	{
	XHistoryData history_data = new XHistoryData( XMLManager.getNodeAttribute(node,"location") );

		node = node.getFirstChild();
		while( node!=null )
		{
			if( node instanceof Element )
			{
				if( node.getNodeName().equals("title") )
					history_data.setTitle( XMLManager.getNodeValue(node) );
				else if( node.getNodeName().equals("firstvisited") )
					history_data.setFirstVisited( buildDate(node) );
				else if( node.getNodeName().equals("lastvisited") )
					history_data.setLastVisited( buildDate(node) );
				else if( node.getNodeName().equals("expiration") )
					history_data.setExpiration( buildDate(node) );
				else if( node.getNodeName().equals("visitcount") )
					history_data.setVisitCount( buildInteger(node) );
			}

			node = node.getNextSibling();
		}

		history_manager.addHistoryData(history_data);
	}

	private Date buildDate(Node node) throws DOMException
	{
	Date date = new Date();

        try
        {
	        date = df.parse( XMLManager.getNodeValue(node) );
		}
		catch( Exception e )
		{
		}

		return date;
	}

	private int buildInteger(Node node) throws DOMException
	{
	int i = 0;

        try
        {
	        i = new Integer(XMLManager.getNodeValue(node)).intValue();
		}
		catch( Exception e )
		{
		}

		return i;
	}

	public void exportHistory(String file_name, XHistoryManager history_manager) throws Exception
	{
	Document doc = XMLManager.newDocument();
	Element root = (Element)doc.createElement("xhistory");

		doc.appendChild(root);

		//// Saving History
	Iterator history = history_manager.getHistory();

		while( history.hasNext() )
			saveHistoryData( (XHistoryData)history.next(), doc, root);
		//// History Saved

		root.normalize();

		XMLManager.writeDocument(file_name, doc, null, DTD_SYMBOL, null);
	}

	private void saveHistoryData(XHistoryData history_data, Document doc, Element parent_node)
	{
	Element node = (Element)doc.createElement("xhistorydata");

		node.setAttribute("location", history_data.getLocation() );

		XMLManager.addDataNodeTo(doc, node, "title", history_data.getTitle());
		XMLManager.addDataNodeTo(doc, node, "firstvisited", df.format(history_data.getFirstVisited()));
		XMLManager.addDataNodeTo(doc, node, "lastvisited", df.format(history_data.getLastVisited()));
		XMLManager.addDataNodeTo(doc, node, "expiration", df.format(history_data.getExpiration()));
		XMLManager.addDataNodeTo(doc, node, "visitcount", ""+history_data.getVisitCount());

		parent_node.appendChild(node);
	}

// Attributes:
    private final String DTD_SYMBOL = "xbrowser:default:history";
    private final String DTD_URL = XProjectConstants.DTD_DIR+"XHistory.dtd";
}

⌨️ 快捷键说明

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