Package org.restlet.resource

Examples of org.restlet.resource.FileRepresentation


                        }

                        output = rl.getTextRepresentation();
                    } else {
                        // Return the file content
                        output = new FileRepresentation(file, metadataService
                                .getDefaultMediaType(), getTimeToLive());
                        updateMetadata(metadataService, file.getName(), output);
                    }
                }
            }
View Full Code Here


                        }

                        output = rl.getTextRepresentation();
                    } else {
                        // Return the file content
                        output = new FileRepresentation(file, metadataService
                                .getDefaultMediaType(), getTimeToLive());
                        updateMetadata(metadataService, file.getName(), output);
                    }
                }
            }
View Full Code Here

                resp.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                return;
            }

            MediaType mimetype = new MediaType(new MimetypesFileTypeMap().getContentType(f));
            resp.setEntity(new FileRepresentation(f, mimetype, 10));
    }
View Full Code Here

  @Test
  public void shouldNotFindFilesOutsideTheRepository()
      throws Exception
  {
    Request request = createRequest("/any-rpm.rpm", TESTREPO, VERSION);
    FileRepresentation representation = (FileRepresentation) resource.get(null, request, null, null);
    Assert.assertFalse(representation.getFile().exists());
  }
View Full Code Here

                        }

                        output = rl.getTextRepresentation();
                    } else {
                        // Return the file content
                        output = new FileRepresentation(file, metadataService
                                .getDefaultMediaType(), getTimeToLive());
                        updateMetadata(metadataService, file.getName(), output);
                    }
                }
            }
View Full Code Here

    }

    @Override
    public Representation getRepresentation(MediaType defaultMediaType,
            int timeToLive) {
        return new FileRepresentation(getFile(), defaultMediaType, timeToLive);
    }
View Full Code Here

                        }

                        output = rl.getTextRepresentation();
                    } else {
                        // Return the file content
                        output = new FileRepresentation(file, metadataService
                                .getDefaultMediaType(), getTimeToLive());
                        updateMetadata(metadataService, file.getName(), output);
                    }
                } else {
                    // We look for the possible variant which has the same
                    // extensions in a distinct order.
                    // 1- set up base name as the longest part of the name
                    // without known extensions (beginning from the left)
                    String baseName = getBaseName(file, metadataService);
                    Set<String> extensions = getExtensions(file,
                            metadataService);
                    // 2- loooking for resources with the same base name
                    File[] files = file.getParentFile().listFiles();
                    File uniqueVariant = null;

                    if (files != null) {
                        for (File entry : files) {
                            if (baseName.equals(getBaseName(entry,
                                    metadataService))) {
                                Set<String> entryExtensions = getExtensions(
                                        entry, metadataService);
                                if (entryExtensions.containsAll(extensions)
                                        && extensions
                                                .containsAll(entryExtensions)) {
                                    // The right representation has been found.
                                    uniqueVariant = entry;
                                    break;
                                }
                            }
                        }
                    }
                    if (uniqueVariant != null) {
                        // Return the file content
                        output = new FileRepresentation(uniqueVariant,
                                metadataService.getDefaultMediaType(),
                                getTimeToLive());
                        updateMetadata(metadataService, file.getName(), output);
                    }
                }
View Full Code Here

                Status.CLIENT_ERROR_NOT_FOUND);
        }

        //TODO: set different content type?
        //TODO: not sure about this time to live parameter... 
        getResponse().setEntity(new FileRepresentation(script, MediaType.TEXT_PLAIN, 10));
    }
View Full Code Here

        return false;
    }

    @Override   
    public void handleGet() {  
        getResponse().setEntity(new FileRepresentation(getTemplateFile(), MEDIATYPE_FTL, 0));
    }
View Full Code Here

TOP

Related Classes of org.restlet.resource.FileRepresentation

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.