Example usage for org.apache.commons.mail ByteArrayDataSource ByteArrayDataSource

List of usage examples for org.apache.commons.mail ByteArrayDataSource ByteArrayDataSource

Introduction

In this page you can find the example usage for org.apache.commons.mail ByteArrayDataSource ByteArrayDataSource.

Prototype

public ByteArrayDataSource(final String data, final String aType) throws IOException 

Source Link

Document

Create a datasource from a String.

Usage

From source file:org.jlibrary.core.axis.client.AxisRepositoryDelegate.java

public void importRepository(Ticket ticket, byte[] content, String name)
        throws RepositoryException, SecurityException {

    try {//w  ww.j a  v a  2 s.c  o m
        call.removeAllParameters();

        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName("importRepository");
        call.addParameter("ticket", XMLType.XSD_ANY, ParameterMode.IN);
        call.addParameter("content", XMLType.SOAP_BASE64BINARY, ParameterMode.IN);
        call.addParameter("name", XMLType.XSD_STRING, ParameterMode.IN);

        DataHandler handler = new DataHandler(new ByteArrayDataSource(content, "application/octet-stream"));
        call.addAttachmentPart(handler);

        call.setReturnType(XMLType.AXIS_VOID);
        call.invoke(new Object[] { ticket, new byte[] {}, name });

    } catch (Exception e) {
        // I don't know if there is a better way to do this
        AxisFault fault = (AxisFault) e;
        if (fault.getFaultString().indexOf("SecurityException") != -1) {
            throw new SecurityException(fault.getFaultString());
        } else if (fault.getFaultString().indexOf("RepositoryAlreadyExistsException") != -1) {
            throw new RepositoryAlreadyExistsException();
        } else {
            throw new RepositoryException(fault.getFaultString());
        }
    }
}

From source file:org.jlibrary.core.axis.client.AxisRepositoryDelegate.java

/**
 * @see org.jlibrary.core.repository.def.ResourcesModule#createResource(org.jlibrary.core.entities.Ticket, org.jlibrary.core.properties.ResourceNodeProperties)
 *//* w w  w  .  jav  a  2  s.c  o  m*/
public ResourceNode createResource(Ticket ticket, ResourceNodeProperties properties)
        throws RepositoryException, SecurityException {
    try {
        call.removeAllParameters();

        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName("createResource");

        call.addParameter("ticket", XMLType.XSD_ANY, ParameterMode.IN);
        call.addParameter("properties", XMLType.XSD_ANY, ParameterMode.IN);

        call.setReturnType(XMLType.XSD_ANY);

        // Change the binary property for an attachment
        byte[] content = (byte[]) properties.getProperty(ResourceNodeProperties.RESOURCE_CONTENT).getValue();
        if (content != null) {
            properties.setProperty(ResourceNodeProperties.RESOURCE_CONTENT, null);
            DataHandler handler = new DataHandler(new ByteArrayDataSource(content, "application/octet-stream"));
            call.addAttachmentPart(handler);
        }
        return (ResourceNode) call.invoke(new Object[] { ticket, properties });

    } catch (Exception e) {
        // I don't know if there is a better way to do this
        AxisFault fault = (AxisFault) e;
        if (fault.getFaultString().indexOf("SecurityException") != -1) {
            throw new SecurityException(fault.getFaultString());
        } else {
            throw new RepositoryException(fault.getFaultString());
        }
    }
}

From source file:org.jlibrary.core.axis.client.AxisRepositoryDelegate.java

public ResourceNode updateResourceNode(Ticket ticket, ResourceNodeProperties properties)
        throws RepositoryException, SecurityException {

    try {// w  ww. j a  v  a  2s.c  o  m
        call.removeAllParameters();

        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName("updateResourceNode");
        call.addParameter("ticket", XMLType.XSD_ANY, ParameterMode.IN);
        call.addParameter("properties", XMLType.XSD_ANY, ParameterMode.IN);

        call.setReturnType(XMLType.XSD_ANY);

        // Change the binary property for an attachment
        byte[] content = (byte[]) properties.getProperty(ResourceNodeProperties.RESOURCE_CONTENT).getValue();
        if (content != null) {
            properties.setProperty(ResourceNodeProperties.RESOURCE_CONTENT, null);
            DataHandler handler = new DataHandler(new ByteArrayDataSource(content, "application/octet-stream"));
            call.addAttachmentPart(handler);
        }
        return (ResourceNode) call.invoke(new Object[] { ticket, properties });

    } catch (Exception e) {
        // I don't know if there is a better way to do this
        AxisFault fault = (AxisFault) e;
        if (fault.getFaultString().indexOf("SecurityException") != -1) {
            throw new SecurityException(fault.getFaultString());
        } else {
            throw new RepositoryException(fault.getFaultString());
        }
    }
}

From source file:org.jlibrary.core.axis.client.AxisRepositoryDelegate.java

public Node updateContent(Ticket ticket, String docId, byte[] content)
        throws SecurityException, RepositoryException {
    try {/*  w ww . jav  a 2s  .c  o  m*/
        call.removeAllParameters();

        call.setTargetEndpointAddress(new java.net.URL(endpoint));
        call.setOperationName("updateContent");
        call.addParameter("ticket", XMLType.XSD_ANY, ParameterMode.IN);
        call.addParameter("docId", XMLType.XSD_STRING, ParameterMode.IN);
        call.addParameter("content", XMLType.SOAP_BASE64BINARY, ParameterMode.IN);

        DataHandler handler = new DataHandler(new ByteArrayDataSource(content, "application/octet-stream"));
        call.addAttachmentPart(handler);

        call.setReturnType(XMLType.XSD_ANY);
        Node node = (Node) call.invoke(new Object[] { ticket, docId, content });
        return node;

    } catch (Exception e) {
        // I don't know if there is a better way to do this
        AxisFault fault = (AxisFault) e;
        if (fault.getFaultString().indexOf("SecurityException") != -1) {
            throw new SecurityException(fault.getFaultString());
        } else if (fault.getFaultString().indexOf("RepositoryAlreadyExistsException") != -1) {
            throw new RepositoryAlreadyExistsException();
        } else {
            throw new RepositoryException(fault.getFaultString());
        }
    }
}

From source file:org.jlibrary.core.repository.axis.AxisRepositoryService.java

private void createAttachment(byte[] content) throws IOException {
    // We will add the content as attachment instead         
    MessageContext context = MessageContext.getCurrentContext();
    Message message = context.getResponseMessage();
    DataHandler handler = new DataHandler(new ByteArrayDataSource(content, "application/octet-stream"));
    javax.xml.soap.AttachmentPart attachment = message.createAttachmentPart(handler);
    message.addAttachmentPart(attachment);
}