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

📄 item.java

📁 DSPACE的源码 dspace-1.4-source
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * @return created bitstream     * @throws AuthorizeException     * @throws IOException     * @throws SQLException     */    public Bitstream createSingleBitstream(InputStream is)            throws AuthorizeException, IOException, SQLException    {        return createSingleBitstream(is, "ORIGINAL");    }    /**     * Get all non-internal bitstreams in the item. This is mainly used for     * auditing for provenance messages and adding format.* DC values. The order     * is indeterminate.     *      * @return non-internal bitstreams.     */    public Bitstream[] getNonInternalBitstreams() throws SQLException    {        List bitstreamList = new ArrayList();        // Go through the bundles and bitstreams picking out ones which aren't        // of internal formats        Bundle[] bunds = getBundles();        for (int i = 0; i < bunds.length; i++)        {            Bitstream[] bitstreams = bunds[i].getBitstreams();            for (int j = 0; j < bitstreams.length; j++)            {                if (!bitstreams[j].getFormat().isInternal())                {                    // Bitstream is not of an internal format                    bitstreamList.add(bitstreams[j]);                }            }        }        Bitstream[] bsArray = new Bitstream[bitstreamList.size()];        bsArray = (Bitstream[]) bitstreamList.toArray(bsArray);        return bsArray;    }    /**     * Store a copy of the license a user granted in this item.     *      * @param license     *            the license the user granted     * @param eperson     *            the eperson who granted the license     * @throws SQLException     * @throws IOException     * @throws AuthorizeException     */    public void licenseGranted(String license, EPerson eperson)            throws SQLException, IOException, AuthorizeException    {        // Put together text to store        String licenseText = "License granted by " + eperson.getFullName()                + " (" + eperson.getEmail() + ") on "                + DCDate.getCurrent().toString() + " (GMT):\n\n" + license;        // Store text as a bitstream        byte[] licenseBytes = licenseText.getBytes();        ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes);        Bitstream b = createSingleBitstream(bais, "LICENSE");        // Now set the format and name of the bitstream        b.setName("license.txt");        b.setSource("Written by org.dspace.content.Item");        // Find the License format        BitstreamFormat bf = BitstreamFormat.findByShortDescription(ourContext,                "License");        b.setFormat(bf);        b.update();    }    /**     * Remove all licenses from an item - it was rejected     *      * @throws SQLException     * @throws AuthorizeException     * @throws IOException     */    public void removeLicenses() throws SQLException, AuthorizeException,            IOException    {        // Find the License format        BitstreamFormat bf = BitstreamFormat.findByShortDescription(ourContext,                "License");        int licensetype = bf.getID();        // search through bundles, looking for bitstream type license        Bundle[] bunds = getBundles();        for (int i = 0; i < bunds.length; i++)        {            boolean removethisbundle = false;            Bitstream[] bits = bunds[i].getBitstreams();            for (int j = 0; j < bits.length; j++)            {                BitstreamFormat bft = bits[j].getFormat();                if (bft.getID() == licensetype)                {                    removethisbundle = true;                }            }            // probably serious troubles with Authorizations            // fix by telling system not to check authorization?            if (removethisbundle)            {                removeBundle(bunds[i]);            }        }    }    /**     * Update the item "in archive" flag and Dublin Core metadata in the     * database     *      * @throws SQLException     * @throws AuthorizeException     */    public void update() throws SQLException, AuthorizeException    {        // Check authorisation        // only do write authorization if user is not an editor        if (!canEdit())        {            AuthorizeManager.authorizeAction(ourContext, this, Constants.WRITE);        }        HistoryManager.saveHistory(ourContext, this, HistoryManager.MODIFY,                ourContext.getCurrentUser(), ourContext.getExtraLogInfo());        log.info(LogManager.getHeader(ourContext, "update_item", "item_id="                + getID()));        // Set the last modified date        itemRow.setColumn("last_modified", new Date());        // Set sequence IDs for bitstreams in item        int sequence = 0;        Bundle[] bunds = getBundles();        // find the highest current sequence number        for (int i = 0; i < bunds.length; i++)        {            Bitstream[] streams = bunds[i].getBitstreams();            for (int k = 0; k < streams.length; k++)            {                if (streams[k].getSequenceID() > sequence)                {                    sequence = streams[k].getSequenceID();                }            }        }        // start sequencing bitstreams without sequence IDs        sequence++;        for (int i = 0; i < bunds.length; i++)        {            Bitstream[] streams = bunds[i].getBitstreams();            for (int k = 0; k < streams.length; k++)            {                if (streams[k].getSequenceID() < 0)                {                    streams[k].setSequenceID(sequence);                    sequence++;                    streams[k].update();                }            }        }        // Make sure that withdrawn and in_archive are non-null        if (itemRow.isColumnNull("in_archive"))        {            itemRow.setColumn("in_archive", false);        }        if (itemRow.isColumnNull("withdrawn"))        {            itemRow.setColumn("withdrawn", false);        }        // Map counting number of values for each element/qualifier.        // Keys are Strings: "element" or "element.qualifier"        // Values are Integers indicating number of values written for a        // element/qualifier        Map elementCount = new HashMap();        DatabaseManager.update(ourContext, itemRow);        // Redo Dublin Core if it's changed        if (dublinCoreChanged)        {            // Remove existing DC            removeMetadataFromDatabase();            // Add in-memory DC            Iterator i = dublinCore.iterator();            while (i.hasNext())            {                DCValue dcv = (DCValue) i.next();                // Get the DC Type                int schemaID;                MetadataSchema schema = MetadataSchema.find(ourContext,dcv.schema);                if (schema == null) {                    schemaID = MetadataSchema.DC_SCHEMA_ID;                } else {                    schemaID = schema.getSchemaID();                }                MetadataField field = MetadataField.findByElement(ourContext,                        schemaID, dcv.element, dcv.qualifier);                if (field == null)                {                    // Bad DC field, log and throw exception                    log.warn(LogManager                            .getHeader(ourContext, "bad_dc",                                    "Bad DC field. SchemaID="+String.valueOf(schemaID)                                            + ", element: \""                                            + ((dcv.element == null) ? "null"                                                    : dcv.element)                                            + "\" qualifier: \""                                            + ((dcv.qualifier == null) ? "null"                                                    : dcv.qualifier)                                            + "\" value: \""                                            + ((dcv.value == null) ? "null"                                                    : dcv.value) + "\""));                    throw new SQLException("bad_dublin_core "                            + "SchemaID="+String.valueOf(schemaID)+", "                            + dcv.element                            + " " + dcv.qualifier);                }                // Work out the place number for ordering                int current = 0;                // Key into map is "element" or "element.qualifier"                String key = dcv.element                        + ((dcv.qualifier == null) ? "" : ("." + dcv.qualifier));                Integer currentInteger = (Integer) elementCount.get(key);                if (currentInteger != null)                {                    current = currentInteger.intValue();                }                current++;                elementCount.put(key, new Integer(current));                // Write DCValue                MetadataValue metadata = new MetadataValue();                metadata.setItemId(getID());                metadata.setFieldId(field.getFieldID());                metadata.setValue(dcv.value);                metadata.setLanguage(dcv.language);                metadata.setPlace(current);                metadata.create(ourContext);            }            dublinCoreChanged = false;        }        // Update browse indices        Browse.itemChanged(ourContext, this);    }    /**     * Withdraw the item from the archive. It is kept in place, and the content     * and metadata are not deleted, but it is not publicly accessible.     *      * @throws SQLException     * @throws AuthorizeException     * @throws IOException     */    public void withdraw() throws SQLException, AuthorizeException, IOException    {        String timestamp = DCDate.getCurrent().toString();        // Build some provenance data while we're at it.        String collectionProv = "";        Collection[] colls = getCollections();        for (int i = 0; i < colls.length; i++)        {            collectionProv = collectionProv + colls[i].getMetadata("name")                    + " (ID: " + colls[i].getID() + ")\n";        }        // Check permission. User either has to have REMOVE on owning collection        // or be COLLECTION_EDITOR of owning collection        if (AuthorizeManager.authorizeActionBoolean(ourContext,                getOwningCollection(), Constants.COLLECTION_ADMIN)                || AuthorizeManager.authorizeActionBoolean(ourContext,                        getOwningCollection(), Constants.REMOVE))        {            // authorized        }        else        {            throw new AuthorizeException(                    "To withdraw item must be COLLECTION_ADMIN or have REMOVE authorization on owning Collection");        }        // Set withdrawn flag. timestamp will be set; last_modified in update()        itemRow.setColumn("withdrawn", true);        // in_archive flag is now false        itemRow.setColumn("in_archive", false);        // Add suitable provenance - includes user, date, collections +        // bitstream checksums        EPerson e = ourContext.getCurrentUser();        String prov = "Item withdrawn by " + e.getFullName() + " ("                + e.getEmail() + ") on " + timestamp + "\n"                + "Item was in collections:\n" + collectionProv                + InstallItem.getBitstreamProvenanceMessage(this);        addDC("description", "provenance", "en", prov);        // Update item in DB        update();        // Invoke History system        HistoryManager.saveHistory(ourContext, this, HistoryManager.MODIFY, e,                ourContext.getExtraLogInfo());        // Remove from indicies        Browse.itemRemoved(ourContext, getID());        DSIndexer.unIndexContent(ourContext, this);        // and all of our authorization policies        // FIXME: not very "multiple-inclusion" friendly        AuthorizeManager.removeAllPolicies(ourContext, this);        // Write log        log.info(LogManager.getHeader(ourContext, "withdraw_item", "user="                + e.getEmail() + ",item_id=" + getID()));    }    /**     * Reinstate a withdrawn item     *      * @throws SQLException     * @throws AuthorizeException     * @throws IOException     */    public void reinstate() throws SQLException, AuthorizeException,            IOException    {        String timestamp = DCDate.getCurrent().toString();        // Check permission. User must have ADD on all collections.        // Build some provenance data while we're at it.        String collectionProv = "";        Collection[] colls = getCollections();        for (int i = 0; i < colls.length; i++)        {            collectionProv = collectionProv + colls[i].getMetadata("name")                    + " (ID: " + colls[i].getID() + ")\n";            AuthorizeManager.authorizeAction(ourContext, colls[i],                    Constants.ADD);        }        // Clear withdrawn flag

⌨️ 快捷键说明

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