Package org.restlet.data

Examples of org.restlet.data.Disposition


            setExpirationDate(new Date(System.currentTimeMillis()
                    + (1000L * timeToLive)));
        }

        setMediaType(mediaType);
        Disposition disposition = new Disposition();
        disposition.setFilename(file.getName());
        this.setDisposition(disposition);
    }
View Full Code Here


        super(header);
    }

    @Override
    public Disposition readValue() throws IOException {
        Disposition result = null;
        String type = readToken();

        if (type.length() > 0) {
            result = new Disposition();
            result.setType(type);

            if (skipParameterSeparator()) {
                Parameter param = readParameter();

                while (param != null) {
                    result.getParameters().add(param);

                    if (skipParameterSeparator()) {
                        param = readParameter();
                    } else {
                        param = null;
View Full Code Here

    public ZipEntryRepresentation(MediaType mediaType, ZipFile zipFile,
            ZipEntry entry) {
        super(mediaType);
        this.zipFile = zipFile;
        this.entry = entry;
        Disposition disposition = new Disposition();
        disposition.setFilename(entry.getName());
        this.setDisposition(disposition);
        setSize(entry.getSize());
        setModificationDate(new Date(entry.getTime()));
    }
View Full Code Here

* @author Kevin Conaway
*/
public class HttpCallTestCase extends RestletTestCase {

    public void testFormatContentDisposition() {
        Disposition disposition = new Disposition();
        assertEquals("", DispositionWriter.write(disposition));

        disposition = new Disposition(Disposition.TYPE_ATTACHMENT);
        assertEquals("attachment", DispositionWriter.write(disposition));
        disposition.setFilename("");
        assertEquals("attachment; filename=", DispositionWriter
                .write(disposition));
        disposition.setFilename("test.txt");
        assertEquals("attachment; filename=test.txt", DispositionWriter
                .write(disposition));
        disposition.setFilename("file with space.txt");
        assertEquals("attachment; filename=\"file with space.txt\"",
                DispositionWriter.write(disposition));

        disposition.setType(Disposition.TYPE_INLINE);
        assertEquals("inline; filename=\"file with space.txt\"",
                DispositionWriter.write(disposition));

        disposition.getParameters().clear();
        Calendar c = new GregorianCalendar(Locale.ENGLISH);
        c.set(Calendar.YEAR, 2009);
        c.set(Calendar.MONTH, 10);
        c.set(Calendar.DAY_OF_MONTH, 11);
        c.set(Calendar.AM_PM, Calendar.AM);
        c.set(Calendar.HOUR, 10);
        c.set(Calendar.MINUTE, 11);
        c.set(Calendar.SECOND, 12);
        c.set(Calendar.MILLISECOND, 13);
        c.setTimeZone(TimeZone.getTimeZone("GMT"));
        disposition.setCreationDate(c.getTime());
        assertEquals("inline; creation-date=\"Wed, 11 Nov 09 10:11:12 GMT\"",
                DispositionWriter.write(disposition));

    }
View Full Code Here

                DispositionWriter.write(disposition));

    }

    public void testParseContentDisposition() throws IOException {
        Disposition disposition = new DispositionReader(
                "attachment; fileName=\"file.txt\"").readValue();
        assertEquals("file.txt", disposition.getParameters().getFirstValue(
                "fileName"));

        disposition = new DispositionReader("attachment; fileName=file.txt")
                .readValue();
        assertEquals("file.txt", disposition.getParameters().getFirstValue(
                "fileName"));

        disposition = new DispositionReader(
                "attachment; filename=\"file with space.txt\"").readValue();
        assertEquals("file with space.txt", disposition.getParameters()
                .getFirstValue("filename"));

        disposition = new DispositionReader("attachment; filename=\"\"")
                .readValue();
        assertEquals("", disposition.getParameters().getFirstValue("filename"));

        disposition = new DispositionReader("attachment; filename=")
                .readValue();
        assertNull(disposition.getParameters().getFirstValue("filename"));

        disposition = new DispositionReader("attachment; filenam").readValue();
        assertNull(disposition.getParameters().getFirstValue("filename"));

        disposition = new DispositionReader(
                "attachment; modification-date=\"Wed, 11 Nov 09 22:11:12 GMT\"")
                .readValue();
        String str = disposition.getParameters().getFirstValue(
                "modification-date");
        assertEquals("Wed, 11 Nov 09 22:11:12 GMT", str);

    }
View Full Code Here

         Representation rep = new FileRepresentation(zipFile,MediaType.APPLICATION_ZIP) {
            public void release() {
               zipFile.delete();
            }
         };
         Disposition disposition = new Disposition();
         disposition.setFilename("backup.zip");
         rep.setDisposition(disposition);
         return rep;
      } catch (Exception ex) {
         getContext().getLogger().log(Level.SEVERE,"Cannot perform backup to due to exception: "+ex.getMessage(),ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

TOP

Related Classes of org.restlet.data.Disposition

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.