Example usage for org.apache.wicket Application get

List of usage examples for org.apache.wicket Application get

Introduction

In this page you can find the example usage for org.apache.wicket Application get.

Prototype

public static Application get() 

Source Link

Document

Get Application for current thread.

Usage

From source file:org.brixcms.web.nodepage.BrixNodeWebPage.java

License:Apache License

@Override
protected void configureResponse() {
    super.configureResponse();
    String mimeType = getMimeType(getModelObject());
    String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
    ((WebResponse) getResponse()).setContentType(mimeType + "; charset=" + encoding);

    // TODO figure out how to handle last modified for pages.
    // lastmodified depends on both the page and the tiles, maybe tiles
    // can contribute lastmodified dates and we take the latest...
    // response.setLastModifiedTime(Time.valueOf(node.getObject().getLastModified()));

}

From source file:org.cast.cwm.admin.AdminHeaderPanel.java

License:Open Source License

public AdminHeaderPanel(String id) {
    super(id);/*  ww w  . j a  v  a 2s.  c o  m*/

    String appNameHeader = "";
    if (Application.get() instanceof CwmApplication) {
        appNameHeader = CwmApplication.get().getAppAndInstanceId();
    }

    add(new Label("appName", appNameHeader));
    add(new BookmarkablePageLink<WebPage>("homeLink", Application.get().getHomePage()));
    add(new Label("name", cwmSessionService.getUser().getFullName()));
    add(new LogoutLink("logoutLink"));
}

From source file:org.cast.cwm.admin.AdminPage.java

License:Open Source License

protected String getPageTitleBase() {
    StringBuffer t = new StringBuffer();
    if (Application.get() instanceof CwmApplication) {
        t.append(CwmApplication.get().getAppId());
        t.append("/");
    }//  w ww.jav  a  2s.co m
    t.append(configuration.getString("instanceId", "?"));
    return t.toString();
}

From source file:org.cast.cwm.admin.UserContentLogPage.java

License:Open Source License

public UserContentLogPage(PageParameters parameters) {
    super(parameters);

    addFilterForm();//from   w w w . j ava 2s  . c  om

    AuditDataProvider<UserContent, DefaultRevisionEntity> provider = getDataProvider();

    List<IDataColumn<AuditTriple<UserContent, DefaultRevisionEntity>>> columns = makeColumns();
    // Annoying to have to make a new List here; DataTable should use <? extends IColumn>.
    ArrayList<IColumn<AuditTriple<UserContent, DefaultRevisionEntity>, String>> colList = new ArrayList<IColumn<AuditTriple<UserContent, DefaultRevisionEntity>, String>>(
            columns);
    DataTable<AuditTriple<UserContent, DefaultRevisionEntity>, String> table = new DataTable<AuditTriple<UserContent, DefaultRevisionEntity>, String>(
            "table", colList, provider, ITEMS_PER_PAGE);

    table.addTopToolbar(new HeadersToolbar<String>(table, provider));
    table.addBottomToolbar(new NavigationToolbar(table));
    table.addBottomToolbar(new NoRecordsToolbar(table, new Model<String>("No revisions found")));
    add(table);

    CSVDownload<AuditTriple<UserContent, DefaultRevisionEntity>> download = new CSVDownload<AuditTriple<UserContent, DefaultRevisionEntity>>(
            columns, provider);
    add(new ResourceLink<Object>("downloadLink", download));

    // Look for a configuration variable with site's URL, called either cwm.url or app.url.
    // If it is set, it is used to make URLs absolute in the downloaded file
    if (Application.get() instanceof CwmApplication) {
        IAppConfiguration config = CwmApplication.get().getConfiguration();
        urlPrefix = config.getString("cwm.url", config.getString("app.url", ""));
    }
}

From source file:org.cast.cwm.components.DeployJava.java

License:Open Source License

/**
 * Constructor that will load a certain jar and class as an applet.  Will do its best
 * to search for a jar file beginning with "jarName" in the /WEB-INF/lib folder
 * and add it as a shared resource for this application, if necessary.
 * //w  w  w.  j  ava2 s .com
 * Usage Example:  new DeployJava("appletId", "awesome-applet", "org.example.Applet")
 * 
 * The above example will find /WEB-INF/lib/awesome-applet-1.0-SNAPSHOT.jar and add it
 * as a shared resource under the DeployJava.class.
 * 
 * @param id
 * @param jarName
 * @param className
 */
public DeployJava(String id, String jarName, String className) {
    super(id);
    if (Application.get().getConfigurationType().equals(RuntimeConfigurationType.DEVELOPMENT))
        setArchive(getSharedArchiveURL(jarName) + "?" + System.currentTimeMillis());
    else
        setArchive(getSharedArchiveURL(jarName));
    setCode(className);
}

From source file:org.cast.cwm.components.DeployJava.java

License:Open Source License

/**
 * Provides a URL to a shared resource for the given jarFile.  If a resource
 * does not exist, it searches the /WEB-INF/lib folder for a file that starts with 
 * the provided name and adds the resource first.
 * /*from w w w .j a  v  a  2 s. c  o m*/
 * @param jarName
 * @return
 */
public String getSharedArchiveURL(final String jarName) {
    SharedResources sr = Application.get().getSharedResources();

    // If this jarName is not listed as a shared resource, add it as one.
    if (sr.get(DeployJava.class, jarName, null, null, null, false) == null) {
        ServletContext sc = WebApplication.get().getServletContext();
        String path = "/WEB-INF/lib";
        File jar = findMatchingFile(new Folder(sc.getRealPath(path)), jarName);
        if (jar == null) {
            path = "/WEB-INF/classes";
            jar = findMatchingFile(new Folder(sc.getRealPath(path)), jarName);
        }
        if (jar == null) {
            log.error("No JAR found matching {}, looked in {} and {}", jarName, sc.getRealPath("/WEB-INF/lib"),
                    sc.getRealPath("/WEB-INF/classes"));
        } else {
            log.debug("Adding JAR to Shared Resources: {}", jar.getAbsolutePath());
            ContextRelativeResource resource = new ContextRelativeResource(path + "/" + jar.getName());
            sr.add(DeployJava.class, jarName, null, null, null, resource);
        }
    }

    return urlFor(new PackageResourceReference(DeployJava.class, jarName), null).toString();
}

From source file:org.cast.cwm.CwmApplication.java

License:Open Source License

public static CwmApplication get() {
    return (CwmApplication) Application.get();
}

From source file:org.cast.cwm.data.behavior.AudioUploadBehavior.java

License:Open Source License

@Override
public void onRequest() {
    HttpServletRequest req = ((ServletWebRequest) getComponent().getRequest()).getContainerRequest();
    FileUpload upload = new FileUpload(
            new DiskFileItemFactory(Application.get().getResourceSettings().getFileCleaner()));
    try {//from www  .  j a  v a 2 s  .c o  m
        boolean saved = false;
        List<FileItem> fileItems = upload.parseRequest(new ServletRequestContext(req));
        for (FileItem item : fileItems) {
            if (item.getFieldName().equals("data")) {
                String base64data = item.getString();
                String expectedPrefix = "data:audio/mp3;base64,";
                if (base64data.startsWith(expectedPrefix)) {
                    byte[] data = DatatypeConverter
                            .parseBase64Binary(base64data.substring(expectedPrefix.length()));
                    log.debug("Saving audio data: {}", item);
                    // Note, recorder reports audio/mp3 mime type, but audio/mpeg is more standard
                    BinaryFileData bfd = new BinaryFileData("audio data", "audio/mpeg", data);
                    mContent.getObject().setPrimaryFile(bfd);
                    cwmService.flushChanges();
                    saved = true;
                } else {
                    log.error("Uploaded audio data does not start with expected prefix");
                }
            }
        }
        sendResponse(saved);
    } catch (FileUploadException e) {
        e.printStackTrace();
        sendResponse(false);
    }
}

From source file:org.cast.cwm.data.component.LogoutLink.java

License:Open Source License

@Override
public void onClick() {
    AuthDataSessionBase.get().signOut();
    setResponsePage(Application.get().getHomePage());
}

From source file:org.cast.cwm.dav.DavResource.java

License:Open Source License

/**
 * @see org.apache.wicket.request.resource.AbstractResource#newResourceResponse(org.apache.wicket.request.resource.IResource.Attributes)
 *///ww  w  .j  a v a  2  s.  co m
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
    final ResourceResponse response = new ResourceResponse();

    // Set last modified time so that response can determine if data needs to be written.
    response.setLastModified(lastModifiedTime());

    if (response.dataNeedsToBeWritten(attributes)) {
        DavResourceStream resourceStream = new DavResourceStream();
        final byte[] bytes;
        try {
            bytes = IOUtils.toByteArray(resourceStream.getInputStream());
            response.setContentLength(bytes.length);
            response.setLastModified(lastModified);
            if (Application.exists())
                response.setContentType(Application.get().getMimeType(path));

            response.setWriteCallback(new WriteCallback() {
                @Override
                public void writeData(Attributes attributes) {
                    attributes.getResponse().write(bytes);
                }
            });
        } catch (IOException e) {
            log.error("I/O Exception while trying to read DAV resource");
            e.printStackTrace();
            response.setError(404);
        } catch (ResourceStreamNotFoundException e) {
            log.error("DAV resource not found: " + path);
            response.setError(404);
        } finally {
            try {
                resourceStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    return response;
}