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

📄 edititemservlet.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        Collection[] collections = item.getCollections();        // All DC types in the registry        MetadataField[] types = MetadataField.findAll(context);        request.setAttribute("item", item);        request.setAttribute("handle", handle);        request.setAttribute("collections", collections);        request.setAttribute("dc.types", types);        JSPManager.showJSP(request, response, "/tools/edit-item-form.jsp");    }    /**     * Process input from the edit item form     *      * @param context     *            DSpace context     * @param request     *            the HTTP request containing posted info     * @param response     *            the HTTP response     * @param item     *            the item     */    private void processUpdateItem(Context context, HttpServletRequest request,            HttpServletResponse response, Item item) throws ServletException,            IOException, SQLException, AuthorizeException    {        String button = UIUtil.getSubmitButton(request, "submit");        /*         * "Cancel" handled above, so whatever happens, we need to update the         * item metadata. First, we remove it all, then build it back up again.         */        item.clearMetadata(Item.ANY, Item.ANY, Item.ANY, Item.ANY);        // We'll sort the parameters by name. This ensures that DC fields        // of the same element/qualifier are added in the correct sequence.        // Get the parameters names        Enumeration unsortedParamNames = request.getParameterNames();        // Put them in a list        List sortedParamNames = new LinkedList();        while (unsortedParamNames.hasMoreElements())        {            sortedParamNames.add(unsortedParamNames.nextElement());        }        // Sort the list        Collections.sort(sortedParamNames);        Iterator iterator = sortedParamNames.iterator();        while (iterator.hasNext())        {            String p = (String) iterator.next();            if (p.startsWith("value"))            {                /*                 * It's a metadata value - it will be of the form                 * value_element_1 OR value_element_qualifier_2 (the number                 * being the sequence number) We use a StringTokenizer to                 * extract these values                 */                StringTokenizer st = new StringTokenizer(p, "_");                st.nextToken(); // Skip "value"                String schema = st.nextToken();                String element = st.nextToken();                String qualifier = null;                if (st.countTokens() == 2)                {                    qualifier = st.nextToken();                }                String sequenceNumber = st.nextToken();                // Get a string with "element" for unqualified or                // "element_qualifier"                String key = MetadataField.formKey(schema,element,qualifier);                // Get the language                String language = request.getParameter("language_" + key + "_"                        + sequenceNumber);                // Empty string language = null                if ((language != null) && language.equals(""))                {                    language = null;                }                // Get the value                String value = request.getParameter(p).trim();                // If remove button pressed for this value, we don't add it                // back to the item. We also don't add empty values.                if (!(value.equals("") || button.equals("submit_remove_" + key                        + "_" + sequenceNumber)))                {                    // Value is empty, or remove button for this wasn't pressed                    item.addMetadata(schema, element, qualifier, language, value);                }            }            // only process bitstreams if admin            else if (p.startsWith("bitstream_name")                    && AuthorizeManager.isAdmin(context))            {                // We have bitstream metadata                // First, get the bundle and bitstream ID                // Parameter name is bitstream_name_(bundleID)_(bitstreamID)                StringTokenizer st = new StringTokenizer(p, "_");                // Ignore "bitstream" and "name"                st.nextToken();                st.nextToken();                // Bundle ID and bitstream ID next                int bundleID = Integer.parseInt(st.nextToken());                int bitstreamID = Integer.parseInt(st.nextToken());                Bundle bundle = Bundle.find(context, bundleID);                Bitstream bitstream = Bitstream.find(context, bitstreamID);                // Get the string "(bundleID)_(bitstreamID)" for finding other                // parameters related to this bitstream                String key = String.valueOf(bundleID) + "_" + bitstreamID;                // Update bitstream metadata, or delete?                if (button.equals("submit_delete_bitstream_" + key))                {                    // "delete" button pressed                    bundle.removeBitstream(bitstream);                    // Delete bundle too, if empty                    if (bundle.getBitstreams().length == 0)                    {                        item.removeBundle(bundle);                    }                }                else                {                    // Update the bitstream metadata                    String name = request.getParameter(p);                    String source = request.getParameter("bitstream_source_"                            + key);                    String desc = request.getParameter("bitstream_description_"                            + key);                    int formatID = UIUtil.getIntParameter(request,                            "bitstream_format_id_" + key);                    String userFormatDesc = request                            .getParameter("bitstream_user_format_description_"                                    + key);                    int primaryBitstreamID = UIUtil.getIntParameter(request,                            bundleID + "_primary_bitstream_id");                    // Empty strings become non-null                    if (source.equals(""))                    {                        source = null;                    }                    if (desc.equals(""))                    {                        desc = null;                    }                    if (userFormatDesc.equals(""))                    {                        userFormatDesc = null;                    }                    bitstream.setName(name);                    bitstream.setSource(source);                    bitstream.setDescription(desc);                    bitstream                            .setFormat(BitstreamFormat.find(context, formatID));                    if (primaryBitstreamID > 0)                    {                        bundle.setPrimaryBitstreamID(primaryBitstreamID);                    }                    if (userFormatDesc != null)                    {                        bitstream.setUserFormatDescription(userFormatDesc);                    }                    bitstream.update();                    bundle.update();                }            }        }        item.update();        /*         * Now respond to button presses, other than "Remove" or "Delete" button         * presses which were dealt with in the above loop.         */        if (button.equals("submit_addfield"))        {            // Adding a metadata field            int dcTypeID = UIUtil.getIntParameter(request, "addfield_dctype");            String value = request.getParameter("addfield_value").trim();            String lang = request.getParameter("addfield_language");            // Empty language = null            if (lang.equals(""))            {                lang = null;            }            MetadataField field = MetadataField.find(context, dcTypeID);            MetadataSchema schema = MetadataSchema.find(context, field                    .getSchemaID());            item.addMetadata(schema.getName(), field.getElement(), field                    .getQualifier(), lang, value);            item.update();        }        if (button.equals("submit_addcc"))        {            // Show cc-edit page             request.setAttribute("item", item);            JSPManager                    .showJSP(request, response, "/tools/creative-commons-edit.jsp");        }                if (button.equals("submit_addbitstream"))        {            // Show upload bitstream page            request.setAttribute("item", item);            JSPManager                    .showJSP(request, response, "/tools/upload-bitstream.jsp");        }        else        {            // Show edit page again            showEditForm(context, request, response, item);        }                // update the item index        DSIndexer.reIndexContent(context, item);        // Complete transaction        context.complete();    }    /**     * Process the input from the upload bitstream page     *      * @param context     *            current DSpace context     * @param request     *            current servlet request object     * @param response     *            current servlet response object     */    private void processUploadBitstream(Context context,            HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException, SQLException,            AuthorizeException    {        // Wrap multipart request to get the submission info        FileUploadRequest wrapper = new FileUploadRequest(request);        Bitstream b = null;        Item item = Item.find(context, UIUtil.getIntParameter(wrapper,                "item_id"));        File temp = wrapper.getFile("file");        // Read the temp file as logo        InputStream is = new BufferedInputStream(new FileInputStream(temp));        // now check to see if person can edit item        checkEditAuthorization(context, item);        // do we already have an ORIGINAL bundle?        Bundle[] bundles = item.getBundles("ORIGINAL");        if (bundles.length < 1)        {            // set bundle's name to ORIGINAL            b = item.createSingleBitstream(is, "ORIGINAL");        }        else        {            // we have a bundle already, just add bitstream            b = bundles[0].createBitstream(is);        }        // Strip all but the last filename. It would be nice        // to know which OS the file came from.        String noPath = wrapper.getFilesystemName("file");        while (noPath.indexOf('/') > -1)        {            noPath = noPath.substring(noPath.indexOf('/') + 1);        }        while (noPath.indexOf('\\') > -1)        {            noPath = noPath.substring(noPath.indexOf('\\') + 1);        }        b.setName(noPath);        b.setSource(wrapper.getFilesystemName("file"));        // Identify the format        BitstreamFormat bf = FormatIdentifier.guessFormat(context, b);        b.setFormat(bf);        b.update();        item.update();        // Back to edit form        showEditForm(context, request, response, item);        // Remove temp file        temp.delete();        // Update DB        context.complete();    }}

⌨️ 快捷键说明

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