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

📄 historymanager.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                        (flag == MODIFY) ? "modify" : "").append(                        (flag == REMOVE) ? "remove" : "").toString();        return getUniqueIdInternal(uriPrefix, null, objname, Utils                .generateHexKey());    }    /**     * Return an RDF property id.     *      * @param objname     *            The name of an object     * @param property     *            The name of a property of the objecty     * @return The id for the property     */    private static String getPropertyId(String objname, String property)    {        return getUniqueIdInternal(uriPrefix, null, objname, property);    }    /**     * Return an RDF property id for Harmony property.     *      * @param property     *            The name of a Harmony property     * @return The id for the property     */    private static String getHarmonyId(String property)    {        return getUniqueIdInternal(uriPrefix, null, "harmony", property);    }    /**     * Internal method for id generation.     *      * @param uriPrefix     *            A URI     * @param handlePrefix     * @param objname     * @param objid     * @return A unique id     */    private static String getUniqueIdInternal(String uriPrefix,            String handlePrefix, String objname, String objid)    {        final String SLASH = "/";        return new StringBuffer().append(uriPrefix).append(                uriPrefix.endsWith(SLASH) ? "" : SLASH).append(objname).append(                objname.endsWith(SLASH) ? "" : SLASH).append(                (handlePrefix == null) ? "" : handlePrefix).append(                ((handlePrefix == null) || (handlePrefix.endsWith(SLASH))) ? ""                        : SLASH).append(objid).toString();    }    ////////////////////////////////////////    // Serialize methods    ////////////////////////////////////////    /**     * Return an RDF stream for this object.     *      * @param context     *            Current DSpace context     * @param obj     *            The object to serialize     * @return The serialization of the object     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception SQLException     *                If an error occurs while accessing the database     */    private static String serialize(Context context, Object obj)            throws RDFException, SQLException    {        if (obj == null)        {            return null;        }        Model model = new ModelMem();        // Add statements about this object        serializeInternal(context, obj, model);        StringWriter data = new StringWriter();        model.write(data);        // Since this is all in-memory, IOExceptions should never happen        try        {            data.close();        }        catch (IOException ioe)        {        }        return data.toString();    }    /**     * Add RDF statements about this object to the model.     *      * @param context     *            Current DSpace context     * @param obj     *            The object to make statements about     * @param model     *            The RDF statement graph     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception SQLException     *                If an error occurs while accessing the database     */    private static void serializeInternal(Context context, Object obj,            Model model) throws RDFException, SQLException    {        if (obj == null)        {            return;        }        String id = getUniqueId(obj);        Resource res = model.createResource(id);        //  FIXME Strictly speaking, this is NOT a property of the        //  object itself, but of the resulting serialization!        Property generatorId = model.createProperty(uriPrefix + "/generator");        model.add(res, generatorId, ID);        if (obj instanceof Community)        {            addData(context, (Community) obj, res, model);        }        else if (obj instanceof Collection)        {            addData(context, (Collection) obj, res, model);        }        else if (obj instanceof Item)        {            addData(context, (Item) obj, res, model);        }        else if (obj instanceof WorkspaceItem)        {            addData(context, (WorkspaceItem) obj, res, model);        }        else if (obj instanceof WorkflowItem)        {            addData(context, (WorkflowItem) obj, res, model);        }        else if (obj instanceof EPerson)        {            addData(context, (EPerson) obj, res, model);        }    }    /**     * Serialize and store an object.     *      * @param context     *            Current DSpace context.     * @param obj     *            The object to serialize and store.     * @return A unique id for the object.     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception IOException     *                If an error occurs while storing the serialization     * @exception SQLException     *                If an error occurs while accessing the database     */    private static String doSerialize(Context context, Object obj)            throws SQLException, IOException, RDFException    {        if (obj == null)        {            return null;        }        String id = getUniqueId(obj);        String serialization = serialize(context, obj);        store(context, serialization);        return id;    }    /**     * Store the serialization (unless it already exists).     *      * @param context     *            Current DSpace context.     * @param serialization     *            The serialization to store.     * @exception IOException     *                If an error occurs while storing the serialization     * @exception SQLException     *                If an error occurs while accessing the database     */    private static void store(Context context, String serialization)            throws SQLException, IOException    {        String checksum = Utils.getMD5(serialization);        TableRow row = DatabaseManager.findByUnique(context, "history",                "checksum", checksum);        // Already stored        if (row != null)        {            return;        }        TableRow h = DatabaseManager.create(context, "History");        int hid = h.getIntColumn("history_id");        File file = forId(hid, true);        FileWriter fw = new FileWriter(file);        fw.write(serialization);        fw.close();        h.setColumn("checksum", checksum);        h.setColumn("creation_date", nowAsTimeStamp());        DatabaseManager.update(context, h);    }    /**     * Return the last state for the object with id, or null.     *      * @param id     *            The object's history id     * @exception SQLException     *                If an error occurs while accessing the database     */    private static String findPreviousState(String id) throws SQLException    {        Connection connection = null;        PreparedStatement statement = null;        try        {            String sql = "SELECT MAX(history_state_id) FROM HistoryState WHERE object_id = ?";            connection = DatabaseManager.getConnection();            statement = connection.prepareStatement(sql);            statement.setString(1, id);            ResultSet results = statement.executeQuery();            return results.next() ? results.getString(1) : null;        }        finally        {            if (statement != null)            {                statement.close();            }            if (connection != null)            {                connection.close();            }        }    }    ////////////////////////////////////////    // addData methods    ////////////////////////////////////////    /**     * Add community-specific data to the model.     *      * @param context     *            Current DSpace context.     * @param community     *            The community     * @param res     *            RDF resource for the community     * @param model     *            The RDF graph     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception SQLException     *                If an error occurs while accessing the database     */    private static void addData(Context context, Community community,            Resource res, Model model) throws RDFException, SQLException    {        String shortname = getShortName(community);        model.add(res, model.createProperty(getPropertyId(shortname, "ID")),                community.getID());        String[] metadata = new String[] { "name", "short_description",                "introductory_text", "copyright_text", "side_bar_text" };        for (int i = 0; i < metadata.length; i++)        {            String meta = metadata[i];            addMetadata(model, res, shortname, meta, community                    .getMetadata(meta));        }        Property hasPart = model.createProperty(getHarmonyId("hasPart"));        Collection[] collections = community.getCollections();        for (int i = 0; i < collections.length; i++)        {            model.add(res, hasPart, getUniqueId(collections[i]));        }    }    /**     * Add collection-specific data to the model.     *      * @param context     *            Current DSpace context.     * @param collection     *            The collection     * @param res     *            RDF resource for the collection     * @param model     *            The RDF graph     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception SQLException     *                If an error occurs while accessing the database     */    private static void addData(Context context, Collection collection,            Resource res, Model model) throws SQLException, RDFException    {        String shortname = getShortName(collection);        model.add(res, model.createProperty(getPropertyId(shortname, "ID")),                collection.getID());        model.add(res, model                .createProperty(getPropertyId(shortname, "license")),                collection.getLicense());        String[] metadata = new String[] { "name", "short_description",                "introductory_text", "copyright_text", "side_bar_text",                "provenance_description" };        for (int i = 0; i < metadata.length; i++)        {            String meta = metadata[i];            addMetadata(model, res, shortname, meta, collection                    .getMetadata(meta));        }        Property hasPart = model.createProperty(getHarmonyId("hasPart"));        ItemIterator items = collection.getItems();        while (items.hasNext())        {            Item item = items.next();            model.add(res, hasPart, getUniqueId(item));        }    }    /**     * Add item-specific data to the model.     *      * @param context     *            Current DSpace context.     * @param item     *            The item     * @param res     *            RDF resource for the item     * @param model     *            The RDF graph     * @exception RDFException     *                If an error occurs while constructing an RDF graph     * @exception SQLException     *                If an error occurs while accessing the database     */    private static void addData(Context context, Item item, Resource res,            Model model) throws RDFException, SQLException    {        DCValue[] dcfields = item.getDC(Item.ANY, Item.ANY, Item.ANY);        for (int i = 0; i < dcfields.length; i++)        {            DCValue dc = dcfields[i];            String element = dc.element;            String qualifier = dc.qualifier;            String type = new StringBuffer().append(element).append(                    (qualifier == null) ? "" : ".").append(                    (qualifier == null) ? "" : qualifier).toString();            Property p = model

⌨️ 快捷键说明

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