Example usage for javax.activation DataHandler getInputStream

List of usage examples for javax.activation DataHandler getInputStream

Introduction

In this page you can find the example usage for javax.activation DataHandler getInputStream.

Prototype

public InputStream getInputStream() throws IOException 

Source Link

Document

Get the InputStream for this object.

Usage

From source file:de.kp.ames.web.function.dms.DmsDQM.java

/**
 * @param item/*www .  j  ava  2 s .  c om*/
 * @return
 * @throws Exception
 */
public FileUtil getDocument(String item) throws Exception {

    DocumentCacheManager cacheManager = DocumentCacheManager.getInstance();
    DmsDocument cacheEntry = (DmsDocument) cacheManager.getFromCache(item);

    FileUtil file = null;
    if (cacheEntry == null) {

        ExtrinsicObjectImpl eo = (ExtrinsicObjectImpl) getRegistryObjectById(item);
        if (eo == null)
            throw new Exception("[DmsDQM] A document with id <" + item + "> does not exist.");

        String mimetype = eo.getMimeType();
        String fileName = eo.getDisplayName();

        DataHandler handler = eo.getRepositoryItem();
        InputStream stream = handler.getInputStream();

        file = new FileUtil(stream, mimetype);
        file.setFilename(fileName);

    } else {
        file = cacheEntry.asFile();
        file.setFilename(cacheEntry.getName());

    }

    return file;
}

From source file:org.wso2.am.admin.clients.localentry.LocalEntriesAdminClient.java

/**
 * Add Local entry by DataHandler/*from w w w .  j  ava2s .co  m*/
 *
 * @param dh
 * @return
 * @throws java.io.IOException
 * @throws LocalEntryAdminException
 * @throws javax.xml.stream.XMLStreamException
 */
public boolean addLocalEntery(DataHandler dh) throws IOException, LocalEntryAdminException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement localEntryElem = builder.getDocumentElement();
    return (localEntryAdminServiceStub.addEntry(localEntryElem.toString()));
}

From source file:org.wso2.am.admin.clients.endpoint.EndPointAdminClient.java

public boolean addEndPoint(DataHandler dh)
        throws EndpointAdminEndpointAdminException, IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement endPointElem = builder.getDocumentElement();
    return endpointAdminStub.addEndpoint(endPointElem.toString());
}

From source file:org.wso2.am.admin.clients.endpoint.EndPointAdminClient.java

public boolean addDynamicEndPoint(String key, DataHandler dh)
        throws EndpointAdminEndpointAdminException, IOException, XMLStreamException {
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement endPointElem = builder.getDocumentElement();
    return endpointAdminStub.addDynamicEndpoint(key, endPointElem.toString());
}

From source file:de.kp.ames.web.function.dms.DmsDQM.java

/**
 * @param item/*w w w. ja  v a2  s . c o  m*/
 * @return
 * @throws Exception
 */
public ImageUtil getImage(String item) throws Exception {

    ImageCacheManager cacheManager = ImageCacheManager.getInstance();
    DmsImage cacheEntry = (DmsImage) cacheManager.getFromCache(item);

    BufferedImage image = null;
    String fileName = null;
    String mimetype = null;

    if (cacheEntry == null) {

        ExtrinsicObjectImpl eo = (ExtrinsicObjectImpl) getRegistryObjectById(item);
        if (eo == null)
            throw new Exception("[DmsDQM] An image with id <" + item + "> does not exist.");

        mimetype = eo.getMimeType();
        fileName = eo.getDisplayName();

        if ((mimetype != null) && mimetype.startsWith("image")) {

            DataHandler handler = eo.getRepositoryItem();
            image = ImageIO.read(handler.getInputStream());

            ImageUtil imageUtil = new ImageUtil(GraphicsUtil.createSource(image), mimetype);
            imageUtil.setFileName(fileName);
            return imageUtil;
        } else {
            return null;
        }

    } else {

        image = cacheEntry.getImage();
        mimetype = cacheEntry.getMimetype();
        fileName = cacheEntry.getName();

        ImageUtil imageUtil = new ImageUtil(GraphicsUtil.createSource(image), mimetype);
        imageUtil.setFileName(fileName);
        return imageUtil;

    }

}

From source file:org.wso2.carbon.admin.service.AdminServiceGovernanceService.java

public void addService(String sessionCookie, DataHandler dh)
        throws RegistryExceptionException, IOException, XMLStreamException {
    new AuthenticateStub().authenticateStub(sessionCookie, addServicesServiceStub);
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement serviceElem = builder.getDocumentElement();
    addServicesServiceStub.addService(serviceElem.toString());
    log.info("Service Added");

}

From source file:org.linagora.linshare.core.facade.webservice.user.impl.DocumentFacadeImpl.java

@Override
public DocumentDto addDocumentXop(DocumentAttachement doca) throws BusinessException {
    File tempFile = null;/*from w ww.ja v a  2  s . c o  m*/
    try {
        User actor = checkAuthentication();
        DataHandler dh = doca.getDocument();
        InputStream in = dh.getInputStream();
        String fileName = doca.getFilename();
        String comment = (doca.getComment() == null) ? "" : doca.getComment();
        tempFile = File.createTempFile("linshare-xop-", ".tmp");
        IOUtils.transferTo(in, tempFile);
        DocumentEntry res = documentEntryService.create(actor, actor, tempFile, fileName, comment, false, null);
        return new DocumentDto(res);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        deleteTempFile(tempFile);
        throw new BusinessException(BusinessErrorCode.FILE_INVALID_INPUT_TEMP_FILE,
                "Can not generate temp file from input stream.");
    }
}

From source file:org.wso2.esb.integration.common.clients.localentry.AdminServiceLocalEntryAdminService.java

public void addLocalEntry(String sessionCookie, DataHandler dh)
        throws LocalEntryAdminException, IOException, XMLStreamException {
    AuthenticateStub.authenticateStub(sessionCookie, localEntryAdminServiceStub);
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement localEntryElem = builder.getDocumentElement();
    localEntryAdminServiceStub.addEntry(localEntryElem.toString());

}

From source file:org.wso2.esb.integration.common.clients.mediation.MassageStoreAdminClient.java

public void addMessageStore(DataHandler dh)
        throws IOException, LocalEntryAdminException, XMLStreamException, Exception {
    messageStoreAdminServiceStub = this.setMessageStoreStubStub();
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement localEntryElem = builder.getDocumentElement();
    messageStoreAdminServiceStub.addMessageStore(localEntryElem.toString());
}

From source file:org.wso2.carbon.admin.service.AdminServiceEndPointAdmin.java

public void addEndPoint(String sessionCookie, DataHandler dh)
        throws EndpointAdminEndpointAdminException, IOException, XMLStreamException {
    new AuthenticateStub().authenticateStub(sessionCookie, endpointAdminStub);
    XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(dh.getInputStream());
    //create the builder
    StAXOMBuilder builder = new StAXOMBuilder(parser);
    OMElement endPointElem = builder.getDocumentElement();

    endpointAdminStub.addEndpoint(endPointElem.toString());
}