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

📄 dspaceoaicatalog.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    public Map listIdentifiers(String resumptionToken)            throws BadResumptionTokenException, OAIInternalServerError    {        // Resumption tokens not yet supported        throw new BadResumptionTokenException();    }    /**     * Retrieve the specified metadata for the specified identifier     *      * @param identifier     *            the OAI identifier     * @param metadataPrefix     *            the OAI metadataPrefix     * @return the <record/>portion of the XML response.     * @exception OAIInternalServerError     *                signals an http status code 500 problem     * @exception CannotDisseminateFormatException     *                the metadataPrefix is not supported by the item.     * @exception IdDoesNotExistException     *                the identifier wasn't found     */    public String getRecord(String identifier, String metadataPrefix)            throws OAIInternalServerError, CannotDisseminateFormatException,            IdDoesNotExistException    {        log                .info(LogManager.getHeader(null, "oai_request",                        "verb=getRecord,identifier="                                + ((identifier == null) ? "null" : identifier)                                + ",metadataPrefix="                                + ((metadataPrefix == null) ? "null"                                        : metadataPrefix)));        Context context = null;        String record = null;        HarvestedItemInfo itemInfo = null;                // First get the item from the DB        try        {            // Valid IDs start with oai:hostname:            if (identifier.startsWith(OAI_ID_PREFIX))            {                context = new Context();                /*                 * Try and get the item. the .substring() is to strip the                 * oai:(hostname): prefix to get the raw handle                 */                itemInfo = Harvest.getSingle(context, identifier                        .substring(OAI_ID_PREFIX.length()), true);            }            if (itemInfo == null)            {                log.info(LogManager.getHeader(null, "oai_error",                        "id_does_not_exist"));                throw new IdDoesNotExistException(identifier);            }            String schemaURL;            if ((schemaURL = getCrosswalks().getSchemaURL(metadataPrefix)) == null)            {                log.info(LogManager.getHeader(null, "oai_error",                        "cannot_disseminate_format"));                throw new CannotDisseminateFormatException(metadataPrefix);            }            record = getRecordFactory().create(itemInfo, schemaURL,                    metadataPrefix);        }        catch (SQLException se)        {            // Log the error            log.warn(LogManager.getHeader(context, "database_error", ""), se);            throw new OAIInternalServerError(se.toString());        }        finally        {            if (context != null)            {                context.abort();            }        }        return record;    }    /**     * Retrieve a list of records that satisfy the specified criteria. Note,     * though, that unlike the other OAI verb type methods implemented here,     * both of the listRecords methods are already implemented in     * AbstractCatalog rather than abstracted. This is because it is possible to     * implement ListRecords as a combination of ListIdentifiers and GetRecord     * combinations. Nevertheless, I suggest that you override both the     * AbstractCatalog.listRecords methods here since it will probably improve     * the performance if you create the response in one fell swoop rather than     * construct it one GetRecord at a time.     *      * @param from     *            beginning date using the proper granularity     * @param until     *            ending date using the proper granularity     * @param set     *            the set name or null if no such limit is requested     * @param metadataPrefix     *            the OAI metadataPrefix or null if no such limit is requested     * @return a Map object containing entries for a "records" Iterator object     *         (containing XML <record/>Strings) and an optional     *         "resumptionMap" Map.     * @exception OAIInternalServerError     *                signals an http status code 500 problem     * @exception NoSetHierarchyException     *                The repository doesn't support sets.     * @exception CannotDisseminateFormatException     *                the metadataPrefix isn't supported by the item.     */    public Map listRecords(String from, String until, String set,            String metadataPrefix) throws OAIInternalServerError,            NoSetHierarchyException, CannotDisseminateFormatException,            NoItemsMatchException, BadArgumentException    {        log                .info(LogManager.getHeader(null, "oai_request",                        "verb=listRecords,from="                                + ((from == null) ? "null" : from)                                + ",until="                                + ((until == null) ? "null" : until)                                + ",set="                                + ((set == null) ? "null" : set)                                + ",metadataPrefix="                                + ((metadataPrefix == null) ? "null"                                        : metadataPrefix)));        Map m = doRecordHarvest(from, until, set, metadataPrefix, 0);        // Null means bad metadata prefix was bad        if (m == null)        {            log.info(LogManager.getHeader(null, "oai_error",                    "cannot_disseminate_format"));            throw new CannotDisseminateFormatException(metadataPrefix);        }        // If there were zero results, return the appropriate error        Iterator i = (Iterator) m.get("records");        if ((i == null) || !i.hasNext())        {            log.info(LogManager.getHeader(null, "oai_error", "no_items_match"));            throw new NoItemsMatchException();        }        return m;    }    /**     * Retrieve the next set of records associated with the resumptionToken     *      * @param resumptionToken     *            implementation-dependent format taken from the previous     *            listRecords() Map result.     * @return a Map object containing entries for "headers" and "identifiers"     *         Iterators (both containing Strings) as well as an optional     *         "resumptionMap" Map.     * @exception OAIInternalServerError     *                signals an http status code 500 problem     * @exception BadResumptionTokenException     *                the value of the resumptionToken argument is invalid or     *                expired.     */    public Map listRecords(String resumptionToken)            throws BadResumptionTokenException, OAIInternalServerError    {        log.info(LogManager.getHeader(null, "oai_request",                "verb=listRecords,resumptionToken=" + resumptionToken));        /*         * FIXME: This may return zero records if the previous harvest returned         * a number of records that's an exact multiple of MAX_RECORDS. I hope         * that's OK.         */        Object[] params = decodeResumptionToken(resumptionToken);        Integer offset = (Integer) params[4];        Map m = null;        /*         * We catch BadArgumentExceptions here, because doRecordHarvest() throws         * BadArgumentExcpetions when the set spec is bad. set spec bad == bad         * resumption token.         */        try        {            m = doRecordHarvest((String) params[0], (String) params[1],                    (String) params[2], (String) params[3], offset.intValue());        }        catch (BadArgumentException bae)        {            m = null;        }        // null result means a problem -> bad resumption token        if (m == null)        {            log.info(LogManager.getHeader(null, "oai_error",                    "bad_resumption_token"));            throw new BadResumptionTokenException();        }        return m;    }    /**     * Method to do the actual harvest of records     *      * @param from     *            OAI 'from' parameter     * @param until     *            OAI 'until' parameter     * @param set     *            OAI 'set' parameter     * @param metadataPrefix     *            OAI 'metadataPrefix' parameter     * @param offset     *            where to start this harvest     *      * @return the Map for listRecords to return, or null if the metadataPrefix     *         is invalid     */    private Map doRecordHarvest(String from, String until, String set,            String metadataPrefix, int offset) throws OAIInternalServerError,            BadArgumentException    {        Context context = null;        String schemaURL = getCrosswalks().getSchemaURL(metadataPrefix);        Map results = new HashMap();        if (schemaURL == null)        {            return null;        }        // List to put results in        List records = new LinkedList();        try        {            context = new Context();            // Get the relevant HarvestedItemInfo objects to make headers            Collection scope = resolveSet(context, set);            List itemInfos = Harvest.harvest(context, scope, from, until,                    offset, MAX_RECORDS, // Limit amount returned from one                                         // request                    true, true, true); // Need items, containers + withdrawals            // Build list of XML records from item info objects            Iterator i = itemInfos.iterator();            while (i.hasNext())            {                HarvestedItemInfo itemInfo = (HarvestedItemInfo) i.next();                try                {                    String recordXML = getRecordFactory().create(itemInfo,                            schemaURL, metadataPrefix);                    records.add(recordXML);                }                catch (CannotDisseminateFormatException cdfe)                {                    /*                     * FIXME: I've a feeling a                     * "CannotDisseminateFormatException" should be discarded                     * here - it's OK if some records in the requested date                     * range don't have the requested metadata format available.                     * I'll just log it for now.                     */                    if (log.isDebugEnabled())                    {                        log.debug(LogManager.getHeader(context, "oai_warning",                                "Couldn't disseminate " + metadataPrefix                                        + " for " + itemInfo.handle));                    }                }            }            // Put results in form needed to return            results.put("records", records.iterator());            log.info(LogManager.getHeader(context, "oai_harvest", "results="                    + records.size()));            // If we have MAX_RECORDS records, we need to provide a resumption

⌨️ 快捷键说明

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