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

📄 abstractmetsingester.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    String bundleName = manifest.getBundleName(mfile);                    if (!bundleName.equals(Constants.CONTENT_BUNDLE_NAME))                    {                        Bundle bn;                        Bundle bns[] = item.getBundles(bundleName);                        if (bns != null && bns.length > 0)                            bn = bns[0];                        else                            bn = item.createBundle(bundleName);                        bn.addBitstream(bs);                        contentBundle.removeBitstream(bs);                    }                    // finally, build compare lists by deleting matches.                    if (packageFiles.contains(path))                        packageFiles.remove(path);                    else                        missingFiles.add(path);                }            }            //  b. Process files mentioned in <mdRef>s - check and move            //     to METADATA bundle.            for (Iterator mi = manifest.getMdFiles().iterator(); mi.hasNext(); )            {                Element mdref = (Element)mi.next();                String path = METSManifest.getFileName(mdref);                // finally, build compare lists by deleting matches.                if (packageFiles.contains(path))                    packageFiles.remove(path);                else                    missingFiles.add(path);                // if there is a bitstream with that name in Content, move                // it to the Metadata bundle:                Bitstream mdbs = contentBundle.getBitstreamByName(path);                if (mdbs != null)                {                    if (mdBundle == null)                        mdBundle = item.createBundle(Constants.METADATA_BUNDLE_NAME);                    mdBundle.addBitstream(mdbs);                    contentBundle.removeBitstream(mdbs);                }            }            // KLUDGE: make sure Manifest file doesn't get flagged as missing            // or extra, since it won't be mentioned in the manifest.            if (packageFiles.contains(MANIFEST_FILE))                packageFiles.remove(MANIFEST_FILE);            // Give subclass a chance to refine the lists of in-package            // and missing files, delete extraneous files, etc.            checkPackageFiles(packageFiles, missingFiles, manifest);            // Any discrepency in file lists is a fatal error:            if (!(packageFiles.isEmpty() && missingFiles.isEmpty()))            {                StringBuffer msg = new StringBuffer("Package is unacceptable: contents do not match manifest.");                if (!missingFiles.isEmpty())                {                    msg.append("\nPackage is missing these files listed in Manifest:");                    for (Iterator mi = missingFiles.iterator(); mi.hasNext(); )                        msg.append("\n\t"+(String)mi.next());                }                if (!packageFiles.isEmpty())                {                    msg.append("\nPackage contains extra files NOT in manifest:");                    for (Iterator mi = packageFiles.iterator(); mi.hasNext(); )                        msg.append("\n\t"+(String)mi.next());                }                throw new PackageValidationException(msg.toString());            }            /* 3. crosswalk the metadata             */            // get mdref'd streams from "callback" object.            MdrefManager callback = new MdrefManager(mdBundle);            chooseItemDmd(context, item, manifest, callback, manifest.getItemDmds());            // crosswalk content bitstreams too.            for (Iterator ei = fileIdToBitstream.entrySet().iterator();                 ei.hasNext();)            {                Map.Entry ee = (Map.Entry)ei.next();                manifest.crosswalkBitstream(context, (Bitstream)ee.getValue(),                                        (String)ee.getKey(), callback);            }            // Take a second pass over files to correct names of derived files            // (e.g. thumbnails, extracted text) to what DSpace expects:            for (Iterator mi = manifestContentFiles.iterator(); mi.hasNext(); )            {                Element mfile = (Element)mi.next();                String bundleName = manifest.getBundleName(mfile);                if (!bundleName.equals(Constants.CONTENT_BUNDLE_NAME))                {                    Element origFile = manifest.getOriginalFile(mfile);                    if (origFile != null)                    {                        String ofileId = origFile.getAttributeValue("ID");                        Bitstream obs = (Bitstream)fileIdToBitstream.get(ofileId);                        String newName = makeDerivedFilename(bundleName, obs.getName());                        if (newName != null)                        {                            String mfileId = mfile.getAttributeValue("ID");                            Bitstream bs = (Bitstream)fileIdToBitstream.get(mfileId);                            bs.setName(newName);                            bs.update();                        }                    }                }            }            // Sanity-check the resulting metadata on the Item:            PackageUtils.checkMetadata(item);            /* 4. Set primary bitstream; same Bundle             */            Element pbsFile = manifest.getPrimaryBitstream();            if (pbsFile != null)            {                Bitstream pbs = (Bitstream)fileIdToBitstream.get(pbsFile.getAttributeValue("ID"));                if (pbs == null)                    log.error("Got Primary Bitstream file ID="+pbsFile.getAttributeValue("ID")+                             ", but found no corresponding bitstream.");                else                {                    Bundle bn[] = pbs.getBundles();                    if (bn.length > 0)                        bn[0].setPrimaryBitstreamID(pbs.getID());                    else                        log.error("Sanity check, got primary bitstream without any parent bundle.");                }            }            // have subclass manage license since it may be extra package file.            addLicense(context, collection, item, manifest, callback, license );            // subclass hook for final checks and rearrangements            finishItem(context, item);            // commit any changes to bundles            Bundle allBn[] = item.getBundles();            for (int i = 0; i < allBn.length; ++i)            {                allBn[i].update();            }            wi.update();            success = true;            log.info(LogManager.getHeader(context, "ingest",                "Created new Item, db ID="+String.valueOf(item.getID())+                ", WorkspaceItem ID="+String.valueOf(wi.getID())));            return wi;        }        catch (SQLException se)        {            // disable attempt to delete the workspace object, since            // database may have suffered a fatal error and the            // transaction rollback will get rid of it anyway.            wi = null;            // Pass this exception on to the next handler.            throw se;        }        finally        {            // kill item (which also deletes bundles, bitstreams) if ingest fails            if (!success && wi != null)                wi.deleteAll();        }    }    /**     * XXX FIXME Replace is not implemented yet.     */    public Item replace(Context ctx, Item item, InputStream pckage, PackageParameters params)        throws PackageException, UnsupportedOperationException,               CrosswalkException, AuthorizeException,               SQLException, IOException    {        throw new UnsupportedOperationException("The replace operation is not implemented.");    }    // return name of derived file as if MediaFilter created it, or null    private String makeDerivedFilename(String bundleName, String origName)    {        // get the MediaFilter that would create this bundle:        String mfNames[] = PluginManager.getAllPluginNames(MediaFilter.class);        for (int i = 0; i < mfNames.length; ++i)        {            MediaFilter mf = (MediaFilter)PluginManager.getNamedPlugin(MediaFilter.class, mfNames[i]);            if (bundleName.equals(mf.getBundleName()))                return mf.getFilteredName(origName);        }        return null;    }    /**     * Profile-specific tests to validate manifest.  The implementation     * can access the METS document through the <code>manifest</code>     * variable, an instance of <code>METSManifest</code>.     * @throws MetadataValidationException if there is a fatal problem with the METS document's conformance to the expected profile.     */    abstract void checkManifest(METSManifest manifest)        throws MetadataValidationException;    /**     * Hook for subclass to modify the test of the package's     * integrity, and add other tests. E.g. evaluate a PGP signature of     * the manifest in a separate file.     * <p>     * The <code>packageFiles</code> contains "extra" files that were in     * the package but were not referenced by the METS manifest (either as     * content or metadata (mdRefs)).     * The implementation of this method should look for any "extra" files     * uses (e.g. a checksum or cryptographic signature for the manifest     * itself) and remove them from the Set.     * <p>     * The <code>missingFiles</code> set is for     * any files     * referenced by the manifest but not found in the package.     * The implementation can check it for "false positives", or add     * other missing files it knows of.     * <p>     * If either  of the Sets <code>missingFiles</code>     * or <code>packageFiles</code>     * is not empty, the ingest will fail.     *     * @param packageFiles files in package but not referenced by METS     * @param missingFiles files referenced by manifest but not in package     *     */    abstract public void checkPackageFiles(Set packageFiles, Set missingFiles,                                           METSManifest manifest)        throws PackageValidationException, CrosswalkException;    /**     * Select the <code>dmdSec</code> element(s) to apply to the     * Item.  The implementation is responsible for choosing which     * (if any) of the metadata sections to crosswalk to get the     * descriptive metadata for the item being ingested.  It is     * responsible for calling the crosswalk, using the manifest's helper     * i.e. <code>manifest.crosswalkItem(context,item,dmdElement,callback);</code>     * (The final argument is a reference to itself since the     * class also implements the <code>METSManifest.MdRef</code> interface     * to fetch package files referenced by mdRef elements.)     * <p>     * Note that <code>item</code> and <code>manifest</code> are available     * as protected fields from the superclass.     *     * @param context the DSpace context     * @param dmds array of Elements, each a METS dmdSec that applies to the Item as a whole.     *     */    abstract public void chooseItemDmd(Context context, Item item,                                       METSManifest manifest, MdrefManager cb,                                       Element dmds[])        throws CrosswalkException,               AuthorizeException, SQLException, IOException;    /**     * Add license(s) to Item based on contents of METS and other policies.     * The implementation of this method controls exactly what licenses     * are added to the new item, including the DSpace deposit license.     * It is given the collection (which is the source of a default deposit     * license), an optional user-supplied deposit license (in the form of     * a String), and the METS manifest.  It should invoke     * <code>manifest.getItemRightsMD()</code> to get an array of     * <code>rightsMd</code> elements which might contain other license     * information of interest, e.g. a Creative Commons license.     * <p>     * This framework does not add any licenses by default.     *     * @param context the DSpace context     * @param collection DSpace Collection to which the item is being submitted.     * @param license optional user-supplied Deposit License text (may be null)     */    abstract public void addLicense(Context context, Collection collection,                                    Item item, METSManifest manifest,                                    MdrefManager callback, String license)        throws PackageValidationException, CrosswalkException,               AuthorizeException, SQLException, IOException;    /**     * Hook for final "finishing" operations on the new Item.     * This method is called when the new Item is otherwise complete and     * ready to be returned.  The implementation should use this     * opportunity to make whatever final checks and modifications are     * necessary.     *     * @param context the DSpace context     */    abstract public void finishItem(Context context, Item item)        throws PackageValidationException, CrosswalkException,         AuthorizeException, SQLException, IOException;}

⌨️ 快捷键说明

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