/** * Default constructor. Note that the parent application is retrieved using * the {@link Application#getCurrent()} method if available or is null. */ public Role() { this(Application.getCurrent(), null, null); }
/** * Returns the parent application if it exists, or null. * * @return The parent application if it exists, or null. */ public Application getApplication() { return Application.getCurrent(); }
/** * Returns the parent application if it exists, or null. * * @return The parent application if it exists, or null. */ public Application getApplication() { return Application.getCurrent(); }
/** * Returns the parent application if it exists, or null. * * @return The parent application if it exists, or null. */ public Application getApplication() { return Application.getCurrent(); }
/** * Constructor. Note that the parent application is retrieved using the * {@link Application#getCurrent()} method. * * @param name * The name. * @deprecated Use {@link Role#Role(Application, String)} instead. */ @Deprecated public Role(String name) { this(Application.getCurrent(), name, null); }
/** * Constructor. Note that the parent application is retrieved using the * {@link Application#getCurrent()} method. * * @param name * The name. * @param description * The description. * @deprecated Use {@link Role#Role(Application, String, String)} instead. */ @Deprecated public Role(String name, String description) { this(Application.getCurrent(), name, description); }
public static Context getCurrentApplicationContext() { Application application = Application.getCurrent(); if (application == null) { return null; } return application.getContext(); }
/** * Constructor. */ public ConverterProvider() { Application application = Application.getCurrent(); if (application != null) { this.converterService = application.getConverterService(); } if (this.converterService == null) { this.converterService = new ConverterService(); } }
/** * Returns the converter service. * * @return The converter service. * @deprecated Since 1.1, the ConverterService is deprecated, with no * replacement as it doesn't fit well with content negotiation. * Most users prefer to handle those conversion in Resource * subclasses. */ @Deprecated private org.restlet.service.ConverterService getConverterService() { org.restlet.service.ConverterService result = null; final Application application = Application.getCurrent(); if (application != null) { result = application.getConverterService(); } else { result = new org.restlet.service.ConverterService(); } return result; }
/** * Returns the connector service associated to a request. * * @return The connector service associated to a request. */ public static org.restlet.service.ConnectorService getConnectorService() { org.restlet.service.ConnectorService result = null; org.restlet.Application application = org.restlet.Application .getCurrent(); if (application != null) { result = application.getConnectorService(); } else { result = new org.restlet.service.ConnectorService(); } return result; }
/** * Returns the parent application. If it wasn't set, it attempts to retrieve * the current one via {@link org.restlet.Application#getCurrent()} if it * exists, or instantiates a new one as a last resort. * * @return The parent application if it exists, or a new one. */ public org.restlet.Application getApplication() { org.restlet.Application result = this.application; if (result == null) { result = org.restlet.Application.getCurrent(); if (result == null) { result = new org.restlet.Application(getContext()); } this.application = result; } return result; }
/** * Returns a boolean indicating whether the authenticated user is included * in the specified logical "role". If the user has not been authenticated, * the method returns <code>false</code>. * * @param roleName * a <code>String</code> specifying the name of the role * @return a <code>boolean</code> indicating whether the user making the * request belongs to a given role; <code>false</code> if the user * has not been authenticated * @see SecurityContext#isUserInRole(String) */ public boolean isUserInRole(String roleName) { Role role = Application.getCurrent().getRole(roleName); return (role != null) && this.request.getClientInfo().getRoles().contains(role); }
public void execute(final Runnable runnable) { // Save the thread local variables final Application currentApplication = Application.getCurrent(); final Context currentContext = Context.getCurrent(); final Integer currentVirtualHost = VirtualHost.getCurrent(); final Response currentResponse = Response.getCurrent(); executorService.execute(new Runnable() { public void run() { // Copy the thread local variables Response.setCurrent(currentResponse); Context.setCurrent(currentContext); VirtualHost.setCurrent(currentVirtualHost); Application.setCurrent(currentApplication); try { // Run the user task runnable.run(); } finally { // Reset the thread local variables Response.setCurrent(null); Context.setCurrent(null); VirtualHost.setCurrent(-1); Application.setCurrent(null); } } }); }
@Override public Representation getRepresentation(Status status, Request request, Response response) { // Create the data model Map<String, String> dataModel = new ConcurrentHashMap<String, String>(); dataModel.put("applicationName", Application.getCurrent().getName()); dataModel.put("statusDescription", response.getStatus() .getDescription()); dataModel.put("statusReasonPhrase", response.getStatus() .getReasonPhrase()); // Load the FreeMarker template Representation mailFtl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/MailStatus.ftl").get(); // Wraps the bean with a FreeMarker representation return new TemplateRepresentation(mailFtl, dataModel, MediaType.TEXT_HTML); }
@Override public Representation getRepresentation(Status status, Request request, Response response) { // Create the data model Map<String, String> dataModel = new TreeMap<String, String>(); dataModel.put("applicationName", Application.getCurrent().getName()); dataModel.put("statusReasonPhrase", response.getStatus() .getReasonPhrase()); dataModel.put("statusDescription", response.getStatus() .getDescription()); // Load the FreeMarker template Representation mailFtl = new ClientResource( LocalReference.createClapReference(getClass().getPackage()) + "/MailStatus.ftl").get(); // Wraps the bean with a FreeMarker representation return new TemplateRepresentation(mailFtl, dataModel, MediaType.TEXT_HTML); }
/** * In addition to the default behavior, it saves the current application * instance into the current thread. * * @param request * The request to handle. * @param response * The response to update. */ @Override public void handle(Request request, Response response) { Application current = Application.getCurrent(); // Save the current application Application.setCurrent(getHelped()); // Actually handle call try { super.handle(request, response); } finally { // restaure the current application Application.setCurrent(current); } }
/** * Returns the preferred variant according to the client preferences * specified in the request. * * @return The preferred variant. */ public Variant getPreferredVariant() { Variant result = null; final List<Variant> variants = getVariants(); if ((variants != null) && (!variants.isEmpty())) { Language language = null; // Compute the preferred variant. Get the default language // preference from the Application (if any). final Application app = Application.getCurrent(); if (app != null) { language = app.getMetadataService().getDefaultLanguage(); } result = getRequest().getClientInfo().getPreferredVariant(variants, language); } return result; }
/** * Returns a reader from a writer representation.Internally, it uses a * writer thread and a pipe stream. * * @param representation * The representation to read from. * @return The character reader. * @throws IOException */ public static Reader getReader(final WriterRepresentation representation) throws IOException { final PipedWriter pipedWriter = new PipedWriter(); final PipedReader pipedReader = new PipedReader(pipedWriter); final Application application = Application.getCurrent(); // Gets a thread that will handle the task of continuously // writing the representation into the input side of the pipe application.getTaskService().execute(new Runnable() { public void run() { try { representation.write(pipedWriter); pipedWriter.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped reader.", ioe); } } }); return pipedReader; }
/** * Returns a readable byte channel based on the given representation's * content and its write(WritableByteChannel) method. Internally, it uses a * writer thread and a pipe channel. * * @param representation * the representation to get the {@link OutputStream} from. * @return A readable byte channel. * @throws IOException */ public static ReadableByteChannel getChannel( final Representation representation) throws IOException { final Pipe pipe = Pipe.open(); final Application application = Application.getCurrent(); // Get a thread that will handle the task of continuously // writing the representation into the input side of the pipe application.getTaskService().execute(new Runnable() { public void run() { try { final WritableByteChannel wbc = pipe.sink(); representation.write(wbc); wbc.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped channel.", ioe); } } }); return pipe.source(); }
final Application application = Application.getCurrent();