01: /*
02: * Created on 19 sept. 2005
03: *
04: * TODO To change the template for this generated file go to
05: * Window - Preferences - Java - Code Style - Code Templates
06: */
07:
08: /*
09: * LIUS - Lucene Index Update and Search
10: * http://sourceforge.net/projects/lius/
11: *
12: * Copyright (c) 2005, Laval University Library. All rights reserved.
13: *
14: * This library is free software; you can redistribute it and/or
15: * modify it under the terms of the GNU Lesser General Public
16: * License as published by the Free Software Foundation; either
17: * version 2.1 of the License, or (at your option) any later version.
18: *
19: * This library is distributed in the hope that it will be useful,
20: * but WITHOUT ANY WARRANTY; without even the implied warranty of
21: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22: * Lesser General Public License for more details.
23: *
24: * You should have received a copy of the GNU Lesser General Public
25: * License along with this library; if not, write to the Free Software
26: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27: */
28:
29: package ca.ulaval.bibl.lius.index.OpenOffice;
30:
31: import java.io.File;
32: import java.io.IOException;
33: import java.util.ArrayList;
34: import java.util.List;
35:
36: import org.jdom.Element;
37: import org.jdom.JDOMException;
38: import org.jdom.input.SAXBuilder;
39:
40: /**
41: * @author RIBEN9
42: *
43: * TODO To change the template for this generated type comment go to Window -
44: * Preferences - Java - Code Style - Code Templates
45: */
46: public class OOIndexer2 extends OOIndexer {
47:
48: public Object parse(Object file) {
49:
50: org.jdom.Document xmlDocContent = new org.jdom.Document();
51:
52: org.jdom.Document xmlMeta = new org.jdom.Document();
53:
54: try {
55:
56: List files = (List) file;
57:
58: SAXBuilder builder = new SAXBuilder();
59:
60: builder.setValidation(false);
61:
62: xmlDocContent = builder.build(new File((String) files
63: .get(0)));
64:
65: xmlMeta = builder.build(new File((String) files.get(1)));
66: Element rootMeta = xmlMeta.getRootElement();
67: Element meta = null;
68: List ls = new ArrayList();
69: if ((ls = rootMeta.getChildren()).size() > 0) {
70: meta = (Element) ls.get(0);
71: }
72:
73: xmlDocContent.getRootElement().addContent(meta.detach());
74:
75: xmlDocContent.getRootElement().addNamespaceDeclaration(
76: NS_DC);
77: }
78:
79: catch (JDOMException e) {
80: logger.error(e.getMessage());
81: deleteTmp((String) file);
82: } catch (IOException e) {
83: logger.error(e.getMessage());
84: deleteTmp((String) file);
85: }
86:
87: return xmlDocContent;
88: }
89: }
|