Package org.fcrepo.server.utilities

Examples of org.fcrepo.server.utilities.FilteredTripleIterator


            }
            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);
                } else {
                    // relationship already exists
                    return false;
                }
            } catch (TrippiException e) {
                throw new GeneralException(e.getMessage(), e);
            } finally {
                try {
                    if (newIter != null) {
                        newIter.close();
                    }
                } catch (TrippiException e) {
                    throw new GeneralException(e.getMessage(), e);
                }
            }
View Full Code Here


        } 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);
                } else {
                    // relationship does not exist
                    return false;
                }
            } catch (TrippiException e) {
                throw new GeneralException(e.getMessage(), e);
            } finally {
                try {
                    if (newIter != null) {
                        newIter.close(); // also closes the contained iter
                    }
                } catch (TrippiException e) {
                    throw new GeneralException(e.getMessage(), e);
                }
            }
View Full Code Here

TOP

Related Classes of org.fcrepo.server.utilities.FilteredTripleIterator

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.