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

📄 metsmanifest.java

📁 DSPACE的源码 dspace-1.4-source
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            /*            XMLOutputter outputPretty = new XMLOutputter(Format.getPrettyFormat());            log.debug("Got METS DOCUMENT:");            log.debug(outputPretty.outputString(metsDocument));              */        }        catch (JDOMException je)        {            throw new MetadataValidationException("Error validating METS in "                    + is.toString(),  je);        }        return new METSManifest(builder, metsDocument.getRootElement());    }    /**     * Gets name of the profile to which this METS document conforms.     * @return value the PROFILE attribute of mets element, or null if none.     */    public String getProfile()    {        return mets.getAttributeValue("PROFILE");    }    /**     * Gets all <code>file</code> elements which make up     *   the item's content.     * @return a List of <code>Element</code>s.     */    public List getContentFiles()        throws MetadataValidationException    {        if (contentFiles != null)            return contentFiles;        Element fileSec = mets.getChild("fileSec", metsNS);        if (fileSec == null)            throw new MetadataValidationException("Invalid METS Manifest: DSpace requires a fileSec element, but it is missing.");        contentFiles = new ArrayList();        Iterator fgi = fileSec.getChildren("fileGrp", metsNS).iterator();        while (fgi.hasNext())        {            Element fg = (Element)fgi.next();            Iterator fi = fg.getChildren("file", metsNS).iterator();            while (fi.hasNext())            {                Element f = (Element)fi.next();                contentFiles.add(f);            }        }        return contentFiles;    }    /**     * Gets list of all <code>mdRef</code> elements in the METS     *   document.  Used by ingester to e.g. check that all     *   required files are present.     * @return a List of <code>Element</code>s.     */    public List getMdFiles()        throws MetadataValidationException    {        if (mdFiles == null)        {            try            {                // Use a special namespace with known prefix                // so we get the right prefix.                XPath xpath = XPath.newInstance("descendant::mets:mdRef");                xpath.addNamespace(metsNS);                mdFiles = xpath.selectNodes(mets);            }            catch (JDOMException je)            {                throw new MetadataValidationException("Failed while searching for mdRef elements in manifest: ", je);            }        }        return mdFiles;    }    /**     * Get the "original" file element for a derived file.     * Finds the original from which this was derived by matching the GROUPID     * attribute that binds it to its original.  For instance, the file for     * a thumbnail image would have the same GROUPID as its full-size version.     * <p>     * NOTE: This pattern of relating derived files through the GROUPID     * attribute is peculiar to the DSpace METS SIP profile, and may not be     * generally useful with other sorts of METS documents.     * @param file METS file element of derived file     * @return file Element of original or null if none found.     */    public Element getOriginalFile(Element file)    {        String groupID = file.getAttributeValue("GROUPID");        if (groupID == null || groupID.equals(""))            return null;        try        {            XPath xpath = XPath.newInstance("mets:fileSec/mets:fileGrp[@USE=\"CONTENT\"]/mets:file[@GROUPID=\""+groupID+"\"]");            xpath.addNamespace(metsNS);            List oFiles = xpath.selectNodes(mets);            if (oFiles.size() > 0)            {                log.debug("Got ORIGINAL file for derived="+file.toString());                return (Element)oFiles.get(0);            }            else                return null;        }        catch (JDOMException je)        {            log.warn("Got exception on XPATH looking for Original file, "+je.toString());            return null;        }    }    // translate bundle name from METS to DSpace; METS may be "CONTENT"    // or "ORIGINAL" for the DSPace "ORIGINAL", rest are left alone.    private static String normalizeBundleName(String in)    {        if (in.equals("CONTENT"))            return Constants.CONTENT_BUNDLE_NAME;        else if (in.equals("MANIFESTMD"))            return Constants.METADATA_BUNDLE_NAME;        return in;    }    /**     * Get the DSpace bundle name corresponding to the <code>USE</code> attribute of the file group enclosing this <code>file</code> element.     * @return DSpace bundle name     * @throws MetadataValidationException when there is no USE attribute on the enclosing fileGrp.     */    public static String getBundleName(Element file)        throws MetadataValidationException    {        Element fg = file.getParentElement();        String fgUse = fg.getAttributeValue("USE");        if (fgUse == null)            throw new MetadataValidationException("Invalid METS Manifest: every fileGrp element must have a USE attribute.");        return normalizeBundleName(fgUse);    }    /**     * Get the "local" file name of this <code>file</code> or <code>mdRef</code> element.     * By "local" we mean the reference to the actual resource containing     * the data for this file, e.g. a relative path within a Zip or tar archive     * if the METS is serving as a manifest for that sort of package.     * @return "local" file name (i.e.  relative to package or content     *  directory) corresponding to this <code>file</code> or <code>mdRef</code> element.     * @throws MetadataValidationException when there is not enough information to find a resource identifier.     */    public static String getFileName(Element file)        throws MetadataValidationException    {        Element ref;        if (file.getName().equals("file"))        {            ref = file.getChild("FLocat", metsNS);            if (ref == null)            {                // check for forbidden FContent child first:                if (file.getChild("FContent", metsNS) == null)                    throw new MetadataValidationException("Invalid METS Manifest: Every file element must have FLocat child.");                else                    throw new MetadataValidationException("Invalid METS Manifest: file element has forbidden FContent child, only FLocat is allowed.");            }        }        else if (file.getName().equals("mdRef"))            ref = file;        else            throw new MetadataValidationException("getFileName() called with recognized element type: "+file.toString());        String loctype = ref.getAttributeValue("LOCTYPE");        if (loctype != null && loctype.equals("URL"))        {            String result = ref.getAttributeValue("href", xlinkNS);            if (result == null)                throw new MetadataValidationException("Invalid METS Manifest: FLocat/mdRef is missing the required xlink:href attribute.");            return result;        }        throw new MetadataValidationException("Invalid METS Manifest: FLocat/mdRef does not have LOCTYPE=\"URL\" attribute.");    }    /**     * Returns file element corresponding to primary bitstream.     * There is <i>ONLY</i> a primary bitstream if the first <code>div</code> under     * first </code>structMap</code> has an </code>fptr</code>.     *     * @return file element of Item's primary bitstream, or null if there is none.     */    public Element getPrimaryBitstream()        throws MetadataValidationException    {        Element firstDiv = getFirstDiv();        Element fptr = firstDiv.getChild("fptr", metsNS);        if (fptr == null)            return null;        String id = fptr.getAttributeValue("FILEID");        if (id == null)            throw new MetadataValidationException("fptr for Primary Bitstream is missing the required FILEID attribute.");        Element result = getElementByXPath("descendant::mets:file[@ID=\""+id+"\"]", false);        if (result == null)            throw new MetadataValidationException("Cannot find file element for Primary Bitstream: looking for ID="+id);        return result;    }    /** Get the metadata type from within a *mdSec element.     * @return metadata type name.     */    public String getMdType(Element mdSec)        throws MetadataValidationException    {        Element md = mdSec.getChild("mdRef", metsNS);        if (md == null)            md = mdSec.getChild("mdWrap", metsNS);        if (md == null)            throw new MetadataValidationException("Invalid METS Manifest: ?mdSec element has neither mdRef nor mdWrap child.");        String result = md.getAttributeValue("MDTYPE");        if (result != null && result.equals("OTHER"))            result = md.getAttributeValue("OTHERMDTYPE");        if (result == null)            throw new MetadataValidationException("Invalid METS Manifest: "+md.getName()+" has no MDTYPE or OTHERMDTYPE attribute.");        return result;    }    /**     *  Returns MIME type of metadata content, if available.     *  @return MIMEtype word, or null if none is available.     */    public String getMdContentMimeType(Element mdSec)        throws MetadataValidationException    {        Element mdWrap = mdSec.getChild("mdWrap", metsNS);        if (mdWrap != null)        {            String mimeType = mdWrap.getAttributeValue("MIMETYPE");            if (mimeType == null && mdWrap.getChild("xmlData", metsNS) != null)            mimeType = "text/xml";            return mimeType;        }        Element mdRef = mdSec.getChild("mdRef", metsNS);        if (mdRef != null)            return mdRef.getAttributeValue("MIMETYPE");        return null;    }    /**     * Return contents of *md element as List of XML Element objects.     * Gets content, dereferecing mdRef if necessary, or decoding and parsing     * a binData that contains XML.     * @return contents of metadata section, or empty list if no XML content is available.     * @throws MetadataValidationException if METS is invalid, or there is an error parsing the XML.     */    public List getMdContentAsXml(Element mdSec, Mdref callback)        throws MetadataValidationException, IOException, SQLException, AuthorizeException    {        try        {            Element mdRef = null;            Element mdWrap = mdSec.getChild("mdWrap", metsNS);            if (mdWrap != null)            {                Element xmlData = mdWrap.getChild("xmlData", metsNS);                if (xmlData == null)                {                    Element bin = mdWrap.getChild("binData", metsNS);                    if (bin == null)                        throw new MetadataValidationException("Invalid METS Manifest: mdWrap element with neither xmlData nor binData child.");                    // if binData is actually XML, return it; otherwise ignore.                    else                    {                        String mimeType = mdWrap.getAttributeValue("MIMETYPE");                        if (mimeType != null && mimeType.equalsIgnoreCase("text/xml"))                        {                            byte value[] = Base64.decodeBase64(bin.getText().getBytes());                            Document mdd = parser.build(new ByteArrayInputStream(value));                            List result = new ArrayList(1);                            result.add(mdd.getRootElement());                            return result;                        }                        else                        {                            log.warn("Ignoring binData section because MIMETYPE is not XML, but: "+mimeType);                            return new ArrayList(0);                        }                   }                }                else

⌨️ 快捷键说明

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