Package org.fcrepo.server.storage.types

Examples of org.fcrepo.server.storage.types.XMLDatastreamProcessor


        Datastream relsDatastream = GetDatastream(dsId, null);
        if (relsDatastream == null) {
            // relationship does not exist
            return false;
        } else { // (relsExt != null)
            XMLDatastreamProcessor dsxml = new XMLDatastreamProcessor(relsDatastream);
            InputStream relsDatastreamIS = relsDatastream.getContentStream();

            TripleIterator iter = null;
            FilteredTripleIterator newIter = null;
            try {
                iter = TripleIteratorFactory.defaultInstance().fromStream(relsDatastreamIS, RDFFormat.RDF_XML);

                newIter = new FilteredTripleIterator(iter, toPurge, false);
                ByteArrayOutputStream out = new ByteArrayOutputStream();

                newIter.toStream(out, RDFFormat.RDF_XML, false);

                if (newIter.wasChangeMade()) {
                    XMLDatastreamProcessor newdsxml = dsxml.newVersion();
                    Datastream newds = newdsxml.getDatastream();
                    // TODO: setting of this on DatastreamAsXML
                    // TODO: wrap original datastream in handler class
                    newdsxml.setDSMDClass(dsxml.getDSMDClass());
                    newds.DatastreamID = dsId;
                    newds.DatastreamAltIDs = relsDatastream.DatastreamAltIDs;
                    newds.DSFormatURI = relsDatastream.DSFormatURI;
                    newds.DSMIME = relsDatastream.DSMIME;
                    // newds.DSControlGrp = "X"; set by XMLDatastreamProcessor
                    newds.DSInfoType = relsDatastream.DSInfoType;
                    newds.DSState = relsDatastream.DSState;
                    newds.DSVersionable = relsDatastream.DSVersionable;
                    newds.DSVersionID = newDatastreamID(dsId);
                    newds.DSLabel = relsDatastream.DSLabel;
                    newds.DSCreateDT = Server.getCurrentDate(m_context);

                    newds.DSLocation = null;
                    newds.DSLocationType = null;
                    newds.DSChecksumType = relsDatastream.DSChecksumType;
                    newdsxml.setXMLContent(out.toByteArray());
                    newds.DSSize = newdsxml.getXMLContent().length;

                    ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
                                                                 newds.DatastreamID,
                                                                 newds);
                    addDatastream(newds, newds.DSVersionable);
View Full Code Here


                                   String datatype) throws ServerException {

        Triple toAdd =
                createTriple(subject, relationship, object, isLiteral, datatype);
        Datastream relsDatastream = GetDatastream(dsId, null);
        XMLDatastreamProcessor dsxml = null;
        if (relsDatastream == null) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            Map<String, String> map = new HashMap<String, String>();
            // namespaces for RELS-EXT
            if (dsId.equals("RELS-EXT")) {
                map.put(RELS_EXT.prefix, RELS_EXT.uri);
                map.put(MODEL.prefix, MODEL.uri);
            }
            map.put(RDF.prefix, RDF.uri);

            try {
                TripleIterator triples =
                        new FilteredTripleIterator(map, toAdd, true);
                triples.toStream(out, RDFFormat.RDF_XML, false);
            } catch (TrippiException e) {
                throw new GeneralException(e.getMessage(), e);
            }

            dsxml = new XMLDatastreamProcessor(dsId);
            Datastream newds = dsxml.getDatastream();
            newds.DatastreamAltIDs = new String[0];
            // formats for internal datastreams
            if (dsId.equals("RELS-EXT")) {
                newds.DSFormatURI = RELS_EXT1_0.uri;
            } else {
                if (dsId.equals("RELS-INT"))
                    newds.DSFormatURI = RELS_INT1_0.uri;
            }
            newds.DSMIME = "application/rdf+xml";
            //newds.DSControlGrp = "X"; set by XMLDatastreamProcessor instead
            newds.DSInfoType = null;
            newds.DSState = "A";
            newds.DSVersionable = false;
            newds.DSVersionID = dsId + ".0";
            newds.DSLabel = "Relationships";
            newds.DSCreateDT = Server.getCurrentDate(m_context);
            newds.DSLocation = null;
            newds.DSLocationType = null;
            newds.DSChecksumType = Datastream.getDefaultChecksumType();
            dsxml.setXMLContent(out.toByteArray());
            newds.DSSize = dsxml.getXMLContent().length;

            ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
                                                         newds.DatastreamID,
                                                         newds);
            addDatastream(newds, false);
        } else { // (relsDatastream != null)
            dsxml = new XMLDatastreamProcessor(relsDatastream);
            FilteredTripleIterator newIter = null;
            try {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                TripleIterator iter =
                        TripleIteratorFactory.defaultInstance().fromStream(relsDatastream.getContentStream(),
                                                  RDFFormat.RDF_XML);
                newIter = new FilteredTripleIterator(iter, toAdd, true);
                newIter.toStream(out, RDFFormat.RDF_XML, false);

                if (newIter.wasChangeMade()) {
                    XMLDatastreamProcessor newdsxml = dsxml.newVersion();
                    Datastream newds = newdsxml.getDatastream();

                    // TODO: only for XML Metadata datastream
                    newdsxml.setDSMDClass(dsxml.getDSMDClass());

                    newds.DatastreamID = relsDatastream.DatastreamID;
                    newds.DatastreamAltIDs = relsDatastream.DatastreamAltIDs;
                    newds.DSFormatURI = relsDatastream.DSFormatURI;
                    newds.DSMIME = relsDatastream.DSMIME;
                    // newds.DSControlGrp = "X"; set by XMLDatastreamProcessor
                    newds.DSInfoType = relsDatastream.DSInfoType;
                    newds.DSState = relsDatastream.DSState;
                    newds.DSVersionable = relsDatastream.DSVersionable;
                    newds.DSVersionID = newDatastreamID(dsId);
                    newds.DSLabel = relsDatastream.DSLabel;
                    newds.DSCreateDT = Server.getCurrentDate(m_context);
                    newds.DSLocation = null;
                    newds.DSLocationType = null;
                    newds.DSChecksumType = relsDatastream.DSChecksumType;
                    newdsxml.setXMLContent(out.toByteArray());
                    newds.DSSize = newdsxml.getXMLContent().length;

                    ValidationUtility.validateReservedDatastream(PID.getInstance(m_obj.getPid()),
                                                                 newds.DatastreamID,
                                                                 newds);
                    addDatastream(newds, newds.DSVersionable);
View Full Code Here

            if (orig == null) {
                throw new DatastreamNotFoundException("Object " + pid + " has no datastream "
                                                      + datastreamId + " to modify");
            }

            XMLDatastreamProcessor origxml = new XMLDatastreamProcessor(orig);

            // if provided, check request lastModifiedDate against the datastream,
            // rejecting the request if the datastream's mod date is more recent.
            if (lastModifiedDate != null) {
                if (lastModifiedDate.before(orig.DSCreateDT)) {
                    String dsDate = DateUtility.convertDateToXSDString(w.getLastModDate());
                    String reqDate = DateUtility.convertDateToXSDString(lastModifiedDate);
                    String msg = String.format("%s/%s lastModifiedDate (%s) " +
                                               "is more recent than the " +
                                               "request (%s)", pid,
                                               datastreamId, dsDate, reqDate);
                    throw new DatastreamLockedException(msg);
                }
            }

            // some forbidden scenarios...
            if (orig.DSState.equals("D")) {
                throw new GeneralException("Changing attributes on deleted datastreams is forbidden.");
            }
            if (!orig.DSControlGrp.equals("X") && !orig.DSControlGrp.equals("M")) {
                throw new GeneralException("Only content of inline XML and managed content"
                                           + " datastreams may be modified by value.\n"
                                           + "Use modifyDatastreamByReference instead.");
            }

            // A NULL INPUT PARM MEANS NO CHANGE TO DS ATTRIBUTE...
            // if input parms are null, the ds attribute should not be changed,
            // so set the parm values to the existing values in the datastream.
            if (dsLabel == null) {
                dsLabel = orig.DSLabel;
            }
            if (mimeType == null) {
                mimeType = orig.DSMIME;
            }
            if (formatURI == null) {
                formatURI = orig.DSFormatURI;
            }
            if (altIDs == null) {
                altIDs = orig.DatastreamAltIDs;
            }
            if (checksumType == null) {
                checksumType = orig.DSChecksumType;
            } else {
                checksumType = Datastream.validateChecksumType(checksumType);
            }
            if (dsContent != null && "DC".equals(datastreamId)){
                DCFields audited = new DCFields(dsContent);
                try {
                    dsContent = new ByteArrayInputStream(audited.getAsXML(pid).getBytes("UTF-8"));
                } catch (UnsupportedEncodingException uee) {
                    // safely ignore... we know UTF-8 works
                }
            }

            // create new datastream (version) based on existing one
            XMLDatastreamProcessor newdsxml = origxml.newVersion();
            Datastream newds = newdsxml.getDatastream();
            newdsxml.setDSMDClass(origxml.getDSMDClass());
            if (dsContent == null) {
                // If the dsContent input stream parm is null,
                // that means "do not change the content".
                // Accordingly, here we just make a copy of the old content.
                newdsxml.setXMLContent(origxml.getXMLContent());
            } else {
                // set and validate the content
                newdsxml.setXMLContent(getEmbeddableXML(dsContent));
                ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                             orig.DatastreamID,
                                                             newds);
            }
View Full Code Here

    private static void populateDC(Context ctx, DigitalObject obj, DOWriter w,
            Date nowUTC) throws IOException, ServerException {
        logger.debug("Adding/Checking default DC datastream");
        Datastream dc = w.GetDatastream("DC", null);
        DCFields dcf;
        XMLDatastreamProcessor dcxml = null;

        if (dc == null) {
            dcxml = new XMLDatastreamProcessor("DC");
            dc = dcxml.getDatastream();
            //dc.DSMDClass=DatastreamXMLMetadata.DESCRIPTIVE;
            dc.DatastreamID = "DC";
            dc.DSVersionID = "DC1.0";
            //dc.DSControlGrp = "X"; set by XMLDatastreamProcessor instead
            dc.DSCreateDT = nowUTC;
            dc.DSLabel = "Dublin Core Record for this object";
            dc.DSMIME = "text/xml";
            dc.DSFormatURI = OAI_DC2_0.uri;
            dc.DSSize = 0;
            dc.DSState = "A";
            dc.DSVersionable = true;
            dcf = new DCFields();
            if (obj.getLabel() != null && !obj.getLabel().equals("")) {
                dcf.titles().add(new DCField(obj.getLabel()));
            }
            w.addDatastream(dc, dc.DSVersionable);
        } else {
            dcxml = new XMLDatastreamProcessor(dc);
            // note: context may be required to get through authz as content
            // could be filesystem file (or URL)
            dcf =
                    new DCFields(new ByteArrayInputStream(dcxml
                            .getXMLContent(ctx)));
        }
        // set the value of the dc datastream according to what's in the
        // DCFields object
        // ensure one of the dc:identifiers is the pid
        try {
            dcxml.setXMLContent(dcf.getAsXML(obj.getPid()).getBytes("UTF-8"));
        } catch (UnsupportedEncodingException uee) {
            // safely ignore... we know UTF-8 works
        }
    }
View Full Code Here

TOP

Related Classes of org.fcrepo.server.storage.types.XMLDatastreamProcessor

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.