class FileService extends BasicService implements OwnerAPISupport<File> {

	@GET
	@Path("/files/{fileId}/references")
	@Produces(MediaType.APPLICATION_JSON)
	public FileReferences getReferences(@PathParam("fileId") long fileId) {
		File existingFile = getExistingFile(fileId, true);
		FileReferences refs = new FileReferences();

		List<Page> pages = PageDAO.getPagesByFileOrWithTemplate(existingFile);
		for (Page page : pages) {
			if (page.getPageType() == PageType.TEMPLATE) {
				if (page.getFile() != null && new TemplateHelper(page.getFile().getParameters())
						.containsFile(existingFile, page.getTemplateValues())) {
					if (this.isAdmin() || inAdminOwners(page.getOwners())) {
						refs.addUserPage(page);
					} else {
						refs.setForeignPages(refs.getForeignPages() + 1);
					}
				}
			} else {
				if (this.isAdmin() || inAdminOwners(page.getOwners())) {
					refs.addUserPage(page);
				} else {
					refs.setForeignPages(refs.getForeignPages() + 1);
				}
			}
		}

		return refs;
	}

}