📄 qdccrosswalk.java
字号:
/* * QDCCrosswalk.java * * Version: $Revision: 1.2 $ * * Date: $Date: 2006/03/17 00:04:38 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. */package org.dspace.content.crosswalk;import java.io.IOException;import java.sql.SQLException;import java.util.Iterator;import java.util.List;import java.util.ArrayList;import java.util.HashMap;import java.util.Properties;import java.util.Enumeration;import java.io.StringReader;import java.io.File;import java.io.FileInputStream;import java.sql.SQLException;import org.apache.log4j.Logger;import org.dspace.core.Context;import org.dspace.core.Constants;import org.dspace.content.Item;import org.dspace.content.DCValue;import org.dspace.content.DSpaceObject;import org.dspace.content.MetadataSchema;import org.dspace.authorize.AuthorizeException;import org.dspace.core.ConfigurationManager;import org.dspace.core.SelfNamedPlugin;import org.jdom.*;import org.jdom.output.XMLOutputter;import org.jdom.output.Format;import org.jdom.input.SAXBuilder;import org.jdom.input.JDOMParseException;/** * Configurable QDC Crosswalk * <p> * This class supports multiple dissemination crosswalks from DSpace * internal data to the Qualified Dublin Core XML format * (see <a href="http://dublincore.org/">http://dublincore.org/</a> * <p> * It registers multiple Plugin names, which it reads from * the DSpace configuration as follows: * * <h3>Configuration</h3> * Every key starting with <code>"crosswalk.qdc.properties."</code> describes a * QDC crosswalk. Everything after the last period is the <em>plugin instance</em>, * and the value is the pathname (relative to <code><em>dspace.dir</em>/config</code>) * of the crosswalk configuration file. * <p> * You can have two aliases point to the same crosswalk, * just add two configuration entries with the same value, e.g. * <pre> * crosswalk.qdc.properties.QDC = xwalk/qdc.properties * crosswalk.qdc.properties.default = xwalk/qdc.properties * </pre> * The first line creates a plugin with the name <code>"QDC"</code> * which is configured from the file <em>dspace-dir</em><code>/xwalk/qdc.properties</code>. * <p> * Since there is significant overhead in reading the properties file to * configure the crosswalk, and a crosswalk instance may be used any number * of times, we recommend caching one instance of the crosswalk for each * alias and simply reusing those instances. The PluginManager does * this by default. * <p> * Each named crosswalk has two other types of configuration lines: * <p> * XML Namespaces: all XML namespace prefixes used in the XML fragments below * <em>must</em> be defined in the configuration as follows. Add a line of * the form: <pre> * crosswalk.qdc.namespace.{NAME}.{prefix} = {namespace-URI}</pre> * e.g. for the namespaces <code>dc</code> and <code>dcterms</code> * in the plugin named <code>QDC</code>, add these lines: * <pre>crosswalk.qdc.namespace.QDC.dc = http://purl.org/dc/elements/1.1/ * crosswalk.qdc.namespace.QDC.dcterms = http://purl.org/dc/terms/</pre> * * <p> * Finally, you need to declare an XML Schema URI for the plugin, with * a line of the form <pre> * crosswalk.qdc.schema.{NAME} = {schema-URI}</pre> * for example, * <pre>crosswalk.qdc.schemaLocation.QDC = \ * http://purl.org/dc/terms/ \ * http://dublincore.org/schemas/xmls/qdc/2003/04/02/qualifieddc.xsd</pre> * * @author Larry Stone * @version $Revision: 1.2 $ */public class QDCCrosswalk extends SelfNamedPlugin implements DisseminationCrosswalk, IngestionCrosswalk{ /** log4j category */ private static Logger log = Logger.getLogger(QDCCrosswalk.class); // map of qdc to JDOM Element private HashMap qdc2element = new HashMap(); // map of JDOM Element to qdc DCValue private HashMap element2qdc = new HashMap(); // the XML namespaces from config file for this name. private Namespace namespaces[] = null; private static final Namespace DCTERMS_NS = Namespace.getNamespace("dcterms", "http://purl.org/dc/terms/"); // sentinal: done init? private boolean inited = false; // my plugin name private String myName = null; // prefix of all DSpace Configuration entries. private static final String CONFIG_PREFIX = "crosswalk.qdc"; // XML schemaLocation fragment for this crosswalk, from config. private String schemaLocation = null; private static final Namespace XLINK_NS = Namespace.getNamespace("xlink", "http://www.w3.org/TR/xlink"); private static XMLOutputter outputUgly = new XMLOutputter(); private static XMLOutputter outputPretty = new XMLOutputter(Format.getPrettyFormat()); private static SAXBuilder builder = new SAXBuilder(); /** * Fill in the plugin-name table from DSpace configuration entries * for configuration files for flavors of QDC crosswalk: */ private static String aliases[] = null; static { List aliasList = new ArrayList(); Enumeration pe = ConfigurationManager.propertyNames(); String propname = CONFIG_PREFIX + ".properties."; while (pe.hasMoreElements()) { String key = (String)pe.nextElement(); if (key.startsWith(propname)) aliasList.add(key.substring(propname.length())); } aliases = (String[])aliasList.toArray(new String[aliasList.size()]); } public static String[] getPluginNames() { return aliases; } // utility: return "fully qualified" name of XML element, for a // hashtable key to use on ingesting elements. // Format is {prefix:}name where prefix is optional. private String makeQualifiedTagName(Element element) { String prefix = ""; Namespace ns = element.getNamespace(); if (ns != null) prefix = ns.getPrefix() + ":"; return prefix+element.getName(); } /** * Initialize Crosswalk table from a properties file * which itself is the value of the DSpace configuration property * "crosswalk.qdc.properties.X", where "X" is the alias name of this instance. * Each instance may be configured with a separate mapping table. * * The QDC crosswalk configuration properties follow the format: * * {qdc-element} = {XML-fragment} * * 1. qualified DC field name is of the form (qualifier is optional) * {MDschema}.{element}.{qualifier} * * e.g. dc.contributor.author * dc.title * * 2. XML fragment is prototype of metadata element, with empty * placeholders for value). * * Example properties line:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -