Package org.dspace.content.crosswalk

Examples of org.dspace.content.crosswalk.MetadataValidationException


                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
                {
                    return xmlData.getChildren();
                }
            }
            else if ((mdRef = mdSec.getChild("mdRef", metsNS)) != null)
            {
                String mimeType = mdRef.getAttributeValue("MIMETYPE");
                if (mimeType != null && mimeType.equalsIgnoreCase("text/xml"))
                {
                    Document mdd = parser.build(callback.getInputStream(mdRef));
                    List result = new ArrayList(1);
                    result.add(mdd.getRootElement());
                    return result;
                }
                else
                {
                    log.warn("Ignoring mdRef section because MIMETYPE is not XML, but: "+mimeType);
                    return new ArrayList(0);
                }
            }
            else
                throw new MetadataValidationException("Invalid METS Manifest: ?mdSec element with neither mdRef nor mdWrap child.");
        }
        catch (JDOMException je)
        {
            throw new MetadataValidationException("Error parsing or validating metadata section in mdRef or binData within "+mdSec.toString(), je);
        }

    }
View Full Code Here


            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.");

                else
                {
                    byte value[] = Base64.decodeBase64(bin.getText().getBytes());
                    return new ByteArrayInputStream(value);
                }
            }
            else
            {
                XMLOutputter outputPretty = new XMLOutputter(Format.getPrettyFormat());
                return new ByteArrayInputStream(
                        outputPretty.outputString(xmlData.getChildren()).getBytes());
            }
        }
        else if ((mdRef = mdSec.getChild("mdRef", metsNS)) != null)
        {
            return callback.getInputStream(mdRef);
        }
        else
            throw new MetadataValidationException("Invalid METS Manifest: ?mdSec element with neither mdRef nor mdWrap child.");
    }
View Full Code Here

    private Element getFirstDiv()
        throws MetadataValidationException
    {
        Element sm = mets.getChild("structMap", metsNS);
        if (sm == null)
            throw new MetadataValidationException("METS document is missing the required structMap element.");

        Element result = sm.getChild("div", metsNS);
        if (result == null)
            throw new MetadataValidationException("METS document is missing the required first div element in first structMap.");

        log.debug("Got firstDiv result="+result.toString());
        return (Element)result;
    }
View Full Code Here

            if (result == null && nullOk)
                return null;
            else if (result instanceof Element)
                return (Element)result;
            else
                throw new MetadataValidationException("METSManifest: Failed to resolve XPath, path=\""+path+"\"");
        }
        catch (JDOMException je)
        {
            throw new MetadataValidationException("METSManifest: Failed to resolve XPath, path=\""+path+"\"", je);
        }
    }
View Full Code Here

    {
        // div@DMDID is actually IDREFS, a space-separated list of IDs:
        Element firstDiv = getFirstDiv();
        String dmds = firstDiv.getAttributeValue("DMDID");
        if (dmds == null)
            throw new MetadataValidationException("Invalid METS: Missing reference to Item descriptive metadata, first div on first structmap must have a DMDID attribute.");
        String dmdID[] = dmds.split("\\s+");
        Element result[] = new Element[dmdID.length];

        for (int i = 0; i < dmdID.length; ++i)
            result[i] = getElementByXPath("mets:dmdSec[@ID=\""+dmdID[i]+"\"]", false);
View Full Code Here

    {
        String type = getMdType(dmd);
        IngestionCrosswalk xwalk = getCrosswalk(type);

        if (xwalk == null)
            throw new MetadataValidationException("Cannot process METS Manifest: "+
                "No crosswalk found for MDTYPE="+type);
        crosswalkMdContent(dmd, callback, xwalk, context, item);
    }
View Full Code Here

        throws MetadataValidationException,
               CrosswalkException, IOException, SQLException, AuthorizeException
    {
        Element file = getElementByXPath("descendant::mets:file[@ID=\""+fileId+"\"]", false);
        if (file == null)
            throw new MetadataValidationException("Failed in Bitstream crosswalk, Could not find file element with ID="+fileId);

        // In DSpace METS SIP spec, admin metadata is only "highly
        // recommended", not "required", so it is OK if there is no ADMID.
        String amds = file.getAttributeValue("ADMID");
        if (amds == null)
        {
            log.warn("Got no bitstream ADMID, file@ID="+fileId);
            return;
        }
        String amdID[] = amds.split("\\s+");
        for (int i = 0; i < amdID.length; ++i)
        {
            List techMDs = getElementByXPath("mets:amdSec[@ID=\""+amdID[i]+"\"]", false).
                                 getChildren("techMD", metsNS);
            Iterator ti = techMDs.iterator();
            while (ti.hasNext())
            {
                Element techMD = (Element)ti.next();
                if (techMD != null)
                {
                    String type = getMdType(techMD);
                    IngestionCrosswalk xwalk = getCrosswalk(type);
                    log.debug("Got bitstream techMD of type="+type+", for file ID="+fileId);
                    
                    if (xwalk == null)
                        throw new MetadataValidationException("Cannot process METS Manifest: "+
                            "No crosswalk found for techMD MDTYPE="+type);
                    crosswalkMdContent(techMD, callback, xwalk, context, bitstream);
                }
            }
        }
View Full Code Here

        {
            return handle.substring(4);
        }
        else
        {
            throw new MetadataValidationException("Item has no valid Handle (OBJID)");
        }
    }
View Full Code Here

            parser.parse();
            cos = parser.getDocument();

            // sanity check: PDFBox breaks on encrypted documents, so give up.
            if(cos.getEncryptionDictionary() != null)
                throw new MetadataValidationException("This packager cannot accept an encrypted PDF document.");

            /* PDF to DC "crosswalk":
             *
             * NOTE: This is not in a crosswalk plugin because (a) it isn't
             * useful anywhere else, and more importantly, (b) the source
             * data is not XML so it doesn't fit the plugin's interface.
             *
             * pattern of crosswalk -- PDF dict entries to DC:
             *   Title -> title.null
             *   Author -> contributor.author
             *   CreationDate -> date.created
             *   ModDate -> date.created
             *   Creator -> description.provenance (application that created orig)
             *   Producer -> description.provenance (convertor to pdf)
             *   Subject -> description.abstract
             *   Keywords -> subject.other
             *    date is java.util.Calendar
             */
            PDDocument pd = new PDDocument(cos);
            PDDocumentInformation docinfo = pd.getDocumentInformation();
            String title = docinfo.getTitle();

            // sanity check: item must have a title.
            if (title == null)
                throw new MetadataValidationException("This PDF file is unacceptable, it does not have a value for \"Title\" in its Info dictionary.");
            log.debug("PDF Info dict title=\""+title+"\"");
            item.addDC("title", null, "en", title);
            String value;
            Calendar date;
            if ((value = docinfo.getAuthor()) != null)
View Full Code Here

        throws MetadataValidationException
    {
        String profile = manifest.getProfile();
        if (profile == null)
        {
            throw new MetadataValidationException("Cannot accept METS with no PROFILE attribute!");
        }
        else if (!profile.startsWith(PROFILE_START))
        {
            throw new MetadataValidationException("METS has unacceptable PROFILE value, profile=" + profile);
        }
    }
View Full Code Here

TOP

Related Classes of org.dspace.content.crosswalk.MetadataValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.