
com.jaeksoft.searchlib.crawler.mailbox.MailboxCrawlList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opensearchserver Show documentation
Show all versions of opensearchserver Show documentation
OpenSearchServer is a powerful, enterprise-class, search engine program. Using the web user interface,
the crawlers (web, file, database, ...) and the REST/RESTFul API you will be able to integrate quickly and
easily advanced full-text search capabilities in your application. OpenSearchServer runs on Windows and
Linux/Unix/BSD.
/**
* License Agreement for OpenSearchServer
*
* Copyright (C) 2013 Emmanuel Keller / Jaeksoft
*
* http://www.open-search-server.com
*
* This file is part of OpenSearchServer.
*
* OpenSearchServer 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 3 of the License, or
* (at your option) any later version.
*
* OpenSearchServer 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 OpenSearchServer.
* If not, see .
**/
package com.jaeksoft.searchlib.crawler.mailbox;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.TreeMap;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.jaeksoft.searchlib.util.ReadWriteLock;
import com.jaeksoft.searchlib.util.XPathParser;
import com.jaeksoft.searchlib.util.XmlWriter;
public class MailboxCrawlList {
final private ReadWriteLock rwl = new ReadWriteLock();
private TreeMap map;
private MailboxCrawlItem[] array;
private MailboxCrawlList() {
map = new TreeMap();
}
private final static String MAILBOX_CRAWLLIST_ROOTNODE_NAME = "mailboxCrawlList";
private final static String MAILBOX_CRAWL_NODE_NAME = "mailboxCrawlItem";
public static MailboxCrawlList fromXml(MailboxCrawlMaster crawlMaster,
File file) throws XPathExpressionException,
ParserConfigurationException, SAXException, IOException {
MailboxCrawlList crawlList = new MailboxCrawlList();
if (!file.exists())
return crawlList;
XPathParser xpp = new XPathParser(file);
Node rootNode = xpp.getNode(MAILBOX_CRAWLLIST_ROOTNODE_NAME);
if (rootNode == null)
return crawlList;
NodeList nodes = xpp.getNodeList(rootNode, MAILBOX_CRAWL_NODE_NAME);
if (nodes == null)
return crawlList;
for (int i = 0; i < nodes.getLength(); i++) {
MailboxCrawlItem crawlItem = MailboxCrawlItem.fromXml(crawlMaster,
xpp, nodes.item(i));
if (crawlItem != null)
crawlList.add(crawlItem);
}
return crawlList;
}
public void add(MailboxCrawlItem crawlItem) {
rwl.w.lock();
try {
map.put(crawlItem.getName(), crawlItem);
buildArray();
} finally {
rwl.w.unlock();
}
}
public MailboxCrawlItem get(String name) {
rwl.r.lock();
try {
return map.get(name);
} finally {
rwl.r.unlock();
}
}
public void remove(MailboxCrawlItem crawlItem) {
rwl.w.lock();
try {
map.remove(crawlItem.getName());
buildArray();
} finally {
rwl.w.unlock();
}
}
public void writeXml(XmlWriter xmlWriter) throws SAXException,
UnsupportedEncodingException {
rwl.r.lock();
try {
xmlWriter.startElement(MAILBOX_CRAWLLIST_ROOTNODE_NAME);
for (MailboxCrawlItem item : map.values())
item.writeXml(MAILBOX_CRAWL_NODE_NAME, xmlWriter);
xmlWriter.endElement();
} finally {
rwl.r.unlock();
}
}
private void buildArray() {
array = new MailboxCrawlItem[map.size()];
map.values().toArray(array);
}
public MailboxCrawlItem[] getArray() {
rwl.r.lock();
try {
return array;
} finally {
rwl.r.unlock();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy