Package org.dspace.content.crosswalk

Examples of org.dspace.content.crosswalk.MetadataValidationException


             * log.debug(outputPretty.outputString(metsDocument));
             ****/
        }
        catch (JDOMException je)
        {
            throw new MetadataValidationException("Error validating METS in "
                    + is.toString(),  je);
        }

        return new METSManifest(builder, metsDocument.getRootElement(), configName);
    }
View Full Code Here


                xpath.addNamespace(metsNS);
                mdFiles = xpath.selectNodes(mets);
            }
            catch (JDOMException je)
            {
                throw new MetadataValidationException("Failed while searching for mdRef elements in manifest: ", je);
            }
        }
        return mdFiles;
    }
View Full Code Here

            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);
    }
View Full Code Here

            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.");
    }
View Full Code Here

            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;
    }
View Full Code Here

        {
            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;
    }
View Full Code Here

                StringBuffer sb = new StringBuffer();
                for (Iterator mi = mdc.iterator(); mi.hasNext();)
                {
                    sb.append(", ").append(((Content)mi.next()).toString());
                }
                throw new MetadataValidationException("Cannot parse METS with "+mdSec.getQualifiedName()+" element that contains more than one child, size="+String.valueOf(mdc.size())+", ID="+id+"Kids="+sb.toString());
            }
            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<Element> result = new ArrayList<Element>(1);
                            result.add(mdd.getRootElement());
                            return result;
                        }
                        else
                        {
                            log.warn("Ignoring binData section because MIMETYPE is not XML, but: "+mimeType);
                            return new ArrayList<Element>(0);
                        }
                   }
                }
                else
                {
                    return xmlData.getChildren();
                }
            }
            else
            {
                mdRef = mdSec.getChild("mdRef", metsNS);
                if (mdRef != null)
                {
                    String mimeType = mdRef.getAttributeValue("MIMETYPE");
                    if (mimeType != null && mimeType.equalsIgnoreCase("text/xml"))
                    {
                        Document mdd = parser.build(callback.getInputStream(mdRef));
                        List<Element> result = new ArrayList<Element>(1);
                        result.add(mdd.getRootElement());
                        return result;
                    }
                    else
                    {
                        log.warn("Ignoring mdRef section because MIMETYPE is not XML, but: "+mimeType);
                        return new ArrayList<Element>(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

            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
        {
            mdRef = mdSec.getChild("mdRef", metsNS);
            if (mdRef != null)
            {
                return callback.getInputStream(mdRef);
            }
            else
            {
                throw new MetadataValidationException("Invalid METS Manifest: ?mdSec element with neither mdRef nor mdWrap child.");
            }
        }
    }
View Full Code Here

    {
        //get first <structMap>
        Element sm = mets.getChild("structMap", metsNS);
        if (sm == null)
        {
            throw new MetadataValidationException("METS document is missing the required structMap element.");
        }

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

        if (log.isDebugEnabled())
        {
            log.debug("Got getObjStructDiv result=" + result.toString());
View Full Code Here

            }
        }

        if (parentStructMap == null)
        {
            throw new MetadataValidationException("METS document is missing the required structMap[@LABEL='Parent'] element.");
        }

        //get first <div>
        Element linkDiv = parentStructMap.getChild("div", metsNS);
        if (linkDiv == null)
        {
            throw new MetadataValidationException("METS document is missing the required first div element in structMap[@LABEL='Parent'].");
        }

        //the link is in the <mptr> in the @xlink:href attribute
        Element mptr = linkDiv.getChild("mptr", metsNS);
        if (mptr != null)
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.