List of usage examples for org.apache.wicket Application get
public static Application get()
From source file:org.wicketstuff.mergedresources.resources.CompressedMergedResource.java
License:Apache License
protected void setHeaders(WebResponse response) { super.setHeaders(response); if (!Application.get().getResourceSettings().getDisableGZipCompression()) { response.setHeader("Vary", "Accept-Encoding"); }// w w w .j a v a 2 s. co m response.setHeader("Cache-control", "public"); }
From source file:org.wicketstuff.minis.model.ReplacingResourceModel.java
License:Apache License
/** * Replaces all resource keys found in the given resourceKey with their localized values * // w ww .ja va2 s .co m * @param component * the component to look for the resourceKey and all relating resource keys * @return the localized String */ private String getReplacedResourceString(Component component) { String resourceKeyValue = Application.get().getResourceSettings().getLocalizer().getString(resourceKey, component, null, null, null, (IModel<String>) null); StringBuffer output = new StringBuffer(); Matcher matcher = ReplacingResourceModel.PLACEHOLDER_PATTERN.matcher(resourceKeyValue); // Search for placeholder to replace while (matcher.find()) { String replacedPlaceHolder = Application.get().getResourceSettings().getLocalizer() .getString(matcher.group(1), component, null, null, null, (IModel<String>) null); matcher.appendReplacement(output, replacedPlaceHolder); } matcher.appendTail(output); return output.toString(); }
From source file:org.wicketstuff.objectautocomplete.ObjectAutoCompleteBehavior.java
License:Apache License
@Override protected void onRequest(final String input, RequestCycle requestCycle) { IRequestHandler target = new IRequestHandler() { public void respond(IRequestCycle requestCycle) { WebResponse response = (WebResponse) requestCycle.getResponse(); // Determine encoding final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding(); response.setContentType("text/xml; charset=" + encoding); // Make sure it is not cached by a response.disableCaching();/*from w w w. j a v a 2 s .c om*/ Iterator<O> comps = getChoices(input); if (responseRenderer != null) { // there is a dedicated renderer configured responseRenderer.onRequest(comps, response, input); } else { renderer.renderHeader(response); int renderedObjects = 0; while (comps.hasNext()) { final O comp = comps.next(); renderer.render(comp, response, input); renderedObjects++; } renderer.renderFooter(response, renderedObjects); } } public void detach(IRequestCycle requestCycle) { } }; requestCycle.scheduleRequestHandlerAfterCurrent(target); }
From source file:org.wicketstuff.openlayers.AjaxOpenLayersMap.java
License:Apache License
public static void onPageRenderHead(IHeaderResponse response, String pathToOpenLayersJS) { if (pathToOpenLayersJS == null || pathToOpenLayersJS.trim().length() == 0) { pathToOpenLayersJS = "http://openlayers.org/api/"; } else {/*from w w w .j a v a2 s . c o m*/ pathToOpenLayersJS = pathToOpenLayersJS.trim(); if (!pathToOpenLayersJS.endsWith("/")) { pathToOpenLayersJS = pathToOpenLayersJS + "/"; } } pathToOpenLayersJS = pathToOpenLayersJS + "OpenLayers.js"; response.render(JavaScriptHeaderItem.forUrl(pathToOpenLayersJS)); // TODO Import all other JS files which will be used later on CoreLibrariesContributor.contributeAjax(Application.get(), response); response.render(JavaScriptHeaderItem .forReference(new JavaScriptResourceReference(AjaxOpenLayersMap.class, "wicket-openlayersmap.js"))); }
From source file:org.wicketstuff.openlayers.OpenLayersMap.java
License:Apache License
/** * @see org.apache.wicket.Component#onRender() *//* ww w .j a v a 2 s . c o m*/ @Override protected void onRender() { super.onRender(); RuntimeConfigurationType configurationType = Application.get().getConfigurationType(); if (configurationType.equals(RuntimeConfigurationType.DEVELOPMENT) && !Application.get().getMarkupSettings().getStripWicketTags()) { log.warn("Application is in DEVELOPMENT mode && Wicket tags are not stripped," + " Firefox 3.0 will not render the OMap." + " Change to DEPLOYMENT mode || turn on Wicket tags stripping." + " See:" + " http://www.nabble.com/Gmap2-problem-with-Firefox-3.0-to18137475.html."); } }
From source file:org.wicketstuff.poi.datatable.export.AbstractExcelDataExporter.java
License:Apache License
/** * Populates a cell of exported data. This can be overridden to provide custom cell population behavior, or to decorate the * cell./*from w ww.ja v a 2 s. com*/ * * @param <T> The type of each exported row. * @param cell The {@link Cell} to be populated. * @param rowModel The {@link IModel} of the row. * @param column The {@link IExportableColumn} for which this cell if being populated. * @param rowIndex The zero based index of this row in the data set. If headers are exported. then the row index in the * spreadsheet will be one more than this, because the first row of the spreadsheet contains headers. * @param columnIndex The zero based index of the column. * @param workbook The {@link Workbook} in which the cell is created. This is included to than it may be used to create * formatting objects etc. */ @SuppressWarnings("unchecked") protected <T> void populateCell(Cell cell, IModel<T> rowModel, IExportableColumn<T, ?> column, int rowIndex, int columnIndex, Workbook workbook) { IModel<?> cellModel = column.getDataModel(rowModel); if (cellModel != null) { Object cellValue = cellModel.getObject(); if (cellValue != null) { if (cellValue instanceof Boolean) { cell.setCellValue(((Boolean) cellValue).booleanValue()); } else if (cellValue instanceof Number) { cell.setCellValue(((Number) cellValue).doubleValue()); } else if (cellValue instanceof Date) { cell.setCellValue((Date) cellValue); } else { Class<?> c = cellValue.getClass(); String s; IConverter converter = Application.get().getConverterLocator().getConverter(c); if (converter == null) { s = cellValue.toString(); } else { s = converter.convertToString(cellValue, Session.get().getLocale()); } cell.setCellValue(s); } } } }
From source file:org.wicketstuff.poi.excel.TableParser.java
License:Apache License
/** * Mock a request to table component and return its response. * * @param tableComponent/*w w w .j a v a 2s . c o m*/ * @return */ private BufferedWebResponse doRequest(Component tableComponent) { originalResponse = RequestCycle.get().getResponse(); BufferedWebResponse mockResponse = new BufferedWebResponse(null); RequestCycle.get().setResponse(mockResponse); Application.get().getComponentPreOnBeforeRenderListeners().add(PathSetupListener.INSTANCE); Page page = tableComponent.getPage(); page.startComponentRender(tableComponent); tableComponent.prepareForRender(); tableComponent.render(); return mockResponse; }
From source file:org.wicketstuff.poi.excel.TableParser.java
License:Apache License
private void afterParse(Component tableComponent) { tableComponent.getPage().endComponentRender(tableComponent); Application.get().getComponentPreOnBeforeRenderListeners().remove(PathSetupListener.INSTANCE); RequestCycle.get().setResponse(originalResponse); originalResponse = null;/* w w w.ja v a 2s .c o m*/ }
From source file:org.wicketstuff.push.cometd.CometdPushBehavior.java
License:Apache License
/** * Parse the web.xml to find cometd context Path. This context path will be cache for all the * application/*from w ww . j a va2s . com*/ * * @return cometd context path */ private static String guessCometdServletPath() { final ServletContext servletContext = ((WebApplication) Application.get()).getServletContext(); final InputStream is = servletContext.getResourceAsStream("/WEB-INF/web.xml"); /* * get the servlet name from class assignable to org.mortbay.cometd.CometdServlet */ try { final XmlPullParser parser = new XmlPullParser(); parser.parse(is); String urlPattern = null; while (true) { XmlTag elem; // go down until servlet is found do elem = parser.nextTag(); while (elem != null && !(elem.getName().equals("servlet") && elem.isOpen())); // stop if elem is null if (elem == null) break; // get the servlet name for org.mortbay.cometd.CometdServlet String servletName = null, servletClassName = null; do { elem = parser.nextTag(); if (elem.isOpen()) parser.setPositionMarker(); else if (elem.isClose() && elem.getName().equals("servlet-name")) servletName = parser.getInputFromPositionMarker(elem.getPos()).toString(); else if (elem.isClose() && elem.getName().equals("servlet-class")) servletClassName = parser.getInputFromPositionMarker(elem.getPos()).toString(); } while (servletClassName == null || !CometdServlet.class.isAssignableFrom(Class.forName(servletClassName))); if (servletName == null) break; // go down until servlet-mapping is found do elem = parser.nextTag(); while (elem != null && !(elem.getName().equals("servlet-mapping") && elem.isOpen())); // stop if elem is null if (elem == null) break; // get the servlet name for org.mortbay.cometd.CometdServlet String servletNameMapping = null; do { elem = parser.nextTag(); if (elem.isOpen()) parser.setPositionMarker(); else if (elem.isClose() && elem.getName().equals("servlet-name")) servletNameMapping = parser.getInputFromPositionMarker(elem.getPos()).toString(); } while (!servletName.equals(servletNameMapping)); // and the urlPattern do { elem = parser.nextTag(); if (elem.isOpen()) parser.setPositionMarker(); else if (elem.isClose() && elem.getName().equals("url-pattern")) urlPattern = parser.getInputFromPositionMarker(elem.getPos()).toString(); } while (urlPattern == null); // all it is found break; } if (urlPattern == null) throw new ServletException("Error searching for cometd Servlet"); // Check for leading '/' and trailing '/*'. if (!urlPattern.startsWith("/") || !urlPattern.endsWith("/*")) throw new ServletException("Url pattern for cometd should start with / and finish with /*"); // Strip trailing '/*'. return servletContext.getContextPath() + urlPattern.substring(0, urlPattern.length() - 2); } catch (final Exception ex) { final String path = servletContext.getContextPath() + "/cometd"; LOG.warn("Error finding filter cometd servlet in web.xml using default path " + path, ex); return path; } }
From source file:org.wicketstuff.push.cometd.CometdPushBehavior.java
License:Apache License
/** * Javascript allowing cometd to be initialized on commetd * /*from www. j a v a 2s.com*/ * @return javascript to initialize cometd on client side */ private String _renderInitScript() { final Map<String, Object> params = new HashMap<String, Object>(); params.put("isServerWebSocketTransport", CometdPushService.get().isWebSocketTransportAvailable()); params.put("cometdServletPath", getCometdServletPath()); params.put("logLevel", Application.get().getConfigurationType() == RuntimeConfigurationType.DEVELOPMENT ? "info" : "error"); return TEMPLATE_INIT.asString(params); }