Package org.fcrepo.server.storage.types

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


                    .getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME));
            transformer.transform(new StreamSource(in), new StreamResult(out));

            byte [] bytes = out.toByteArray();
            in = new ByteArrayInputStream(bytes);
            return new MIMETypedStream("text/html", in, null, bytes.length);
        } catch (TransformerException e) {
            throw new DisseminationException("[DefaultDisseminatorImpl] had an error "
                    + "in transforming xml for viewItemIndex. "
                    + "Underlying exception was: " + e.getMessage());
        }
View Full Code Here


            transformer.setParameter("fedora", context
                    .getEnvironmentValue(Constants.FEDORA_APP_CONTEXT_NAME));
            transformer.transform(new StreamSource(in), new StreamResult(out));
            byte[] bytes = out.toByteArray();
            in = new ByteArrayInputStream(bytes);
            return new MIMETypedStream("text/html", in, null,bytes.length);
        } catch (TransformerException e) {
            throw new DisseminationException("[DefaultDisseminatorImpl] had an error "
                    + "in transforming xml for viewDublinCore. "
                    + "Underlying exception was: " + e.getMessage());
        }
View Full Code Here

                    + "\"  . The "
                    + "Reason was \""
                    + uee.getMessage()
                    + "\"  .");
        }
        return new MIMETypedStream("text/html", in, null,in.available());
    }
View Full Code Here

     */
    private  final String getFilenameFromRels(Context context, String pid, String dsid, String MIMETYPE) throws Exception {
        String filename = "";

        // read rels directly from RELS-INT - can't use Management.getRelationships as this requires auth
        MIMETypedStream relsInt;
        try {
            relsInt = m_apiAService.getDatastreamDissemination(context, pid, "RELS-INT", null);
        } catch (DatastreamNotFoundException e) {
            return ""; // no RELS-INT - so no filename
        }
        Set<RelationshipTuple> relsIntTuples = RDFRelationshipReader.readRelationships(relsInt.getStream());

        // find the tuple specifying the filename
        int matchingTuples = 0;
        for ( RelationshipTuple tuple : relsIntTuples ) {
            if (tuple.subject.equals(Constants.FEDORA.uri + pid + "/" + dsid) && tuple.predicate.equals(FILENAME_REL)) {
View Full Code Here

            if (controlGroup.equals("X")) {
                ds = new DatastreamXMLMetadata();
                ds.DSInfoType = ""; // field is now deprecated
                try {
                    InputStream in;
                    MIMETypedStream mimeTypedStream = null;
                    if (dsLocation.startsWith(DatastreamManagedContent.UPLOADED_SCHEME)) {
                        in = getTempStream(dsLocation);
                    } else {
                        ContentManagerParams params = new ContentManagerParams(dsLocation);
                        params.setContext(context);
                        mimeTypedStream = m_contentManager.getExternalContent(params);
                        in = mimeTypedStream.getStream();
                    }
                    // set and validate the content
                    DatastreamXMLMetadata dsm = (DatastreamXMLMetadata) ds;
                    dsm.xmlContent = getEmbeddableXML(in);
                    dsm.DSSize = dsm.xmlContent.length;
                    ValidationUtility.validateReservedDatastream(PID.getInstance(pid),
                                                                 dsID,
                                                                 dsm);
                    if (mimeTypedStream != null) {
                        mimeTypedStream.close();
                    }
                } catch (Exception e) {
                    String extraInfo;
                    if (e.getMessage() == null) {
                        extraInfo = "";
View Full Code Here

                            }
                        }
                    }

                    // add the content stream
                    MIMETypedStream content = new MIMETypedStream(null, new ByteArrayInputStream(byteContent), null, byteContent.length);
                    newDS.putContentStream(content);

                    // checksum only needs recalc if we added a header
                    // note getChecksum() caters for checksum type set to disabled
                    if (addXMLHeader) {
View Full Code Here

                                    pid + "+" + dmc.DatastreamID + "+" +
                                            dmc.DSVersionID;
                            // if it's a url, we need to grab content for this
                            // version
                            if (URL_PROTOCOL.matcher(dmc.DSLocation).matches()) {
                                MIMETypedStream mimeTypedStream;
                                if (dmc.DSLocation
                                        .startsWith(DatastreamManagedContent.UPLOADED_SCHEME)) {
                                    mimeTypedStream =
                                            new MIMETypedStream(
                                                    null,
                                                    m_management
                                                            .getTempStream(dmc.DSLocation),
                                                    null, dmc.DSSize);
                                    logger.info("Getting managed datastream from internal uploaded " +
                                            "location: " +
                                            dmc.DSLocation +
                                            " for " + pid);
                                } else if (dmc.DSLocation
                                        .startsWith(DatastreamManagedContent.COPY_SCHEME)) {
                                    // make a copy of the pre-existing content
                                    mimeTypedStream =
                                            new MIMETypedStream(
                                                    null,
                                                    m_permanentStore.retrieveDatastream(dmc.DSLocation
                                                                    .substring(7)),
                                                    null, dmc.DSSize);
                                } else if (dmc.DSLocation
                                        .startsWith(DatastreamManagedContent.TEMP_SCHEME)) {
                                    File file =
                                            new File(dmc.DSLocation
                                                    .substring(7));
                                    logger.info("Getting base64 decoded datastream spooled from archive for datastream " +
                                            dsID + " (" + pid + ")");
                                    try {
                                        InputStream str =
                                                new FileInputStream(file);
                                        mimeTypedStream =
                                                new MIMETypedStream(dmc.DSMIME,
                                                        str, null, file
                                                                .length());
                                    } catch (FileNotFoundException fnfe) {
                                        logger.error(
                                                "Unable to read temp file created for datastream from archive for " +
                                                        pid + " / " + dsID,
                                                fnfe);
                                        throw new StreamIOException(
                                                "Error reading from temporary file created for binary content for " +
                                                        pid + " / " + dsID);
                                    }
                                } else {
                                    ContentManagerParams params =
                                            new ContentManagerParams(
                                                    DOTranslationUtility
                                                            .makeAbsoluteURLs(dmc.DSLocation
                                                                    .toString()),
                                                    dmc.DSMIME, null, null);
                                    params.setContext(context);
                                    mimeTypedStream =
                                            m_contentManager
                                                    .getExternalContent(params);
                                    logger.info("Getting managed datastream from remote location: " +
                                            dmc.DSLocation +
                                            " (" +
                                            pid +
                                            " / " + dsID + ")");
                                }
                                Map<String, String> dsHints =
                                        m_hintProvider
                                                .getHintsForAboutToBeStoredDatastream(
                                                        obj, dmc.DatastreamID);
                                if (obj.isNew()) {
                                    dmc.DSSize =
                                            m_permanentStore.addDatastream(
                                                    internalId, mimeTypedStream
                                                            .getStream(),
                                                    dsHints);
                                } else {
                                    // object already existed...so we may need
                                    // to call
                                    // replace if "add" indicates that it was
                                    // already there
                                    try {
                                        dmc.DSSize =
                                                m_permanentStore.addDatastream(
                                                        internalId,
                                                        mimeTypedStream
                                                                .getStream(),
                                                        dsHints);
                                    } catch (ObjectAlreadyInLowlevelStorageException oailse) {
                                        dmc.DSSize =
                                                m_permanentStore.replaceDatastream(
                                                                internalId,
                                                                mimeTypedStream
                                                                        .getStream(),
                                                                dsHints);
                                    }
                                }
                                if (mimeTypedStream != null) {
                                    mimeTypedStream.close();
                                    if (dmc.DSLocation
                                            .startsWith(DatastreamManagedContent.TEMP_SCHEME)) {
                                        // delete the temp file created to store
                                        // the binary content from archive
                                        File file =
View Full Code Here

            Property[] headerArray =
                    toPropertyArray(response.getResponseHeaders());
            if (mimeType == null || mimeType.equals("")) {
                mimeType = DEFAULT_MIMETYPE;
            }
            return new MIMETypedStream(mimeType, response, headerArray, length);
        } catch (Exception e) {
            throw new GeneralException("Error getting " + url, e);
        }
    }
View Full Code Here

            // if mimeType was not given, try to determine it automatically
            if (mimeType == null || mimeType.equalsIgnoreCase("")){
                mimeType = determineMimeType(cFile);
            }
            return new MIMETypedStream(mimeType,fileUrl.openStream(),null,cFile.length());
        }
        catch(AuthzException ae){
            logger.error(ae.getMessage(),ae);
            throw new HttpServiceNotFoundException("Policy blocked datastream resolution",ae);
        }
View Full Code Here

TOP

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

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.