List of usage examples for org.apache.wicket Component getLocalizer
public final Localizer getLocalizer()
From source file:gr.abiss.calipso.util.PdfUtils.java
License:Open Source License
public static byte[] getPdf(CalipsoService calipso, Item item, String template, Component callerComponent) { ByteArrayOutputStream os = new ByteArrayOutputStream(); String html = null;/*from w w w . j a va 2 s . c o m*/ try { Localizer localizer = callerComponent.getLocalizer(); if (template != null) { // template exists, use it Reader templateReader = new StringReader(template); // create a Velocity context object and add the asset final VelocityContext context = new VelocityContext(); context.put("item", item); context.put("calipso", calipso); // create a writer for capturing the Velocity output StringWriter writer = new StringWriter(); // execute the velocity script and capture the output in writer Velocity.evaluate(context, writer, item.getRefId(), templateReader); // get the output as a string html = writer.getBuffer().toString(); } else { // no template exists, just output manual HTML to feed xhtmlrenderer StringBuffer htmlBuffer = getDefaultHeader(); htmlBuffer.append("<h1>").append( localizer.getString(item.getSpace().getNameTranslationResourceKey(), callerComponent)) .append(": ").append(item.getRefId()).append("</h1>"); // htmlBuffer.append("<table cellspacing='0'>"); // htmlBuffer.append("<tr><th>") // .append(localizer.getString("asset.form.inventoryCode", callerComponent)) // .append("</th><td>") // .append(asset.getInventoryCode()); // htmlBuffer.append("</td></tr>"); // if(MapUtils.isNotEmpty(asset.getCustomAttributes())){ // Map<AssetTypeCustomAttribute,String> attrs = asset.getCustomAttributes(); // for(Entry<AssetTypeCustomAttribute, String> entry : attrs.entrySet()){ // AssetTypeCustomAttribute customAttr = entry.getKey(); // htmlBuffer.append("<tr><th>") // .append(localizer.getString(customAttr.getNameTranslationResourceKey(), callerComponent)) // .append("</th><td>"); // // if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_SELECT) // || customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_OPTIONS_TREE)) { // htmlBuffer.append(XmlUtils.escapeHTML(localizer.getString(customAttr.getLookupValue().getNameTranslationResourceKey(), null))); // } // else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_USER)) { // User user = customAttr.getUserValue(); // htmlBuffer.append(user!=null?XmlUtils.escapeHTML(user.getFullName()):""); // } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_ORGANIZATION)) { // Organization org = customAttr.getOrganizationValue(); // htmlBuffer.append(org!=null?XmlUtils.escapeHTML(org.getName()):""); // } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_ASSET)) { // Asset innerAsset = customAttr.getAssetValue(); // htmlBuffer.append(innerAsset!=null?XmlUtils.escapeHTML(innerAsset.getInventoryCode()):""); // } else if (customAttr.getFormType().equals(AssetTypeCustomAttribute.FORM_TYPE_COUNTRY)) { // Country country = customAttr.getCountryValue(); // htmlBuffer.append(country!=null?localizer.getString("country."+country.getId(), callerComponent):""); // } else { // htmlBuffer.append(XmlUtils.escapeHTML(entry.getValue())); // } // htmlBuffer.append("</td></tr>"); // } // } // htmlBuffer.append("</table>"); htmlBuffer.append("</body></html>"); html = htmlBuffer.toString(); } } catch (Exception e) { logger.error("Failed to creare PDF for item, html: \n" + html, e); } // convert HTML string to PDF and store it in the buffer output stream writePdf(calipso, os, html); return os.toByteArray(); }
From source file:gr.abiss.calipso.wicket.components.formfields.CustomAttributeLookupValueConverter.java
License:Open Source License
public CustomAttributeLookupValueConverter(Collection<CustomAttributeLookupValue> values, Component owner) { this.valuesMap = new HashMap<String, CustomAttributeLookupValue>(); this.owner = owner; if (values != null) { for (CustomAttributeLookupValue value : values) { this.valuesMap.put(owner.getLocalizer().getString(value.getNameTranslationResourceKey(), owner), value);// ww w . j a v a2 s. c o m } } }
From source file:gr.abiss.calipso.wicket.components.formfields.LanguagePaletteChoiceRenderer.java
License:Open Source License
public LanguagePaletteChoiceRenderer(Component formComponent) { this.formComponent = formComponent; this.localizer = formComponent.getLocalizer(); }
From source file:gr.abiss.calipso.wicket.components.formfields.MultipleValuesTextField.java
License:Open Source License
/** * Return the value a raw HTML <code><table></code> with headings and summary. The original input is HTML escaped. * @param input/*from www.j a v a 2 s . com*/ * @return */ public static String toHtmlSafeTable(String input, FieldConfig fieldConfig, Localizer localizer, Component callerComponent) { String escapedInput = XmlUtils.escapeHTML(HtmlUtils.htmlUnescape(input)); StringBuffer html = new StringBuffer(); List<String> escapedLines = MultipleValuesTextField.getValueRows(escapedInput);// HtmlUtils.htmlEscape(input)); final FieldSummaryHelper helper = new FieldSummaryHelper(fieldConfig); if (CollectionUtils.isNotEmpty(escapedLines)) { html.append("<table cellspacing=\"1\" cellpadding=\"0\" class=\"custom-attribute-tabular\">"); if (fieldConfig != null && localizer != null && callerComponent != null) { List<FieldConfig> configs = fieldConfig.getSubFieldConfigs(); if (CollectionUtils.isNotEmpty(configs)) { html.append("<thead><tr>"); int styleMinWidth = ((100 / configs.size()) / 3) * 2; for (FieldConfig config : configs) { html.append("<th style=\"min-width:" + styleMinWidth + "%\">"); html.append(localizer.getString(config.getLabelKey(), callerComponent)); html.append("</th>"); } html.append("</tr></thead>"); } } html.append("<tbody>"); int lineIndex = 1; for (String line : escapedLines) { List<String> escapedLineSubvalues = MultipleValuesTextField.getValueRowSubvalues(line); if (CollectionUtils.isNotEmpty(escapedLineSubvalues)) { int styleWidth = 100 / escapedLineSubvalues.size(); html.append(lineIndex % 2 == 0 ? "<tr class=\"even\">" : "<tr class=\"odd\">"); int cellIndex = 0; for (String subValue : escapedLineSubvalues) { FieldConfig subconfig = fieldConfig != null && CollectionUtils.isNotEmpty(fieldConfig.getSubFieldConfigs()) ? fieldConfig.getSubFieldConfigs().get(cellIndex) : FieldConfig.FALLBACK_SUBCONFIG; html.append("<td ").append(subconfig.isNumberType() ? " class=\"right\">" : ">"); html.append(helper.parseFormat(subconfig, subValue, callerComponent != null ? callerComponent.getSession().getLocale() : Locale.ENGLISH)); html.append("</td>"); helper.updateSummary(subconfig, subValue); cellIndex++; } html.append("</tr>"); } lineIndex++; } html.append("</tbody>"); if (fieldConfig != null && CollectionUtils.isNotEmpty(fieldConfig.getSubFieldConfigs())) { html.append("<tfoot>"); html.append( (helper.getSummaryEntriesCount()) % 2 == 0 ? "<tr class=\"even\">" : "<tr class=\"odd\">"); for (FieldConfig subConfig : fieldConfig.getSubFieldConfigs()) { html.append("<td").append(subConfig.isNumberType() ? " class=\"right\">" : ">"); if (callerComponent != null && StringUtils.isNotBlank(subConfig.getSummary())) { html.append( callerComponent.getLocalizer().getString(subConfig.getSummary(), callerComponent)) .append(": "); } html.append(helper.getCalculatedSummary(subConfig)); html.append("</td>"); } html.append("</tr></tfoot>"); } html.append("</table>"); } // String html = escapedInput.replaceAll("\\n", "<br />") // .replaceAll(MultipleValuesTextField.SEPARATOR_LINE_SUBVALUE_REGEXP, " "); return html.toString(); }
From source file:gr.abiss.calipso.wicket.components.renderers.AssetTypeRenderer.java
License:Open Source License
public AssetTypeRenderer(Component localizerBearer) { this.localizerBearer = localizerBearer; this.localizer = localizerBearer.getLocalizer(); }
From source file:gr.abiss.calipso.wicket.ComponentUtils.java
License:Open Source License
/** * localization helper/*from w w w .ja va 2s . c o m*/ */ public static String localize(Component c, String key) { return c.getLocalizer().getString(key, null); }
From source file:info.jtrac.wicket.BasePage.java
License:Apache License
public static Map<Name, String> getLocalizedLabels(Component c) { Map<Name, String> map = new EnumMap<Name, String>(Name.class); for (Name name : Name.values()) { map.put(name, c.getLocalizer().getString("item_list." + name.getText(), null)); }//www . j a v a2s . c om return map; }
From source file:info.jtrac.wicket.ComponentUtils.java
License:Apache License
public static String localize(Component c, String key, Object... params) { // integer params cause problems, go with String only StringResourceModel m = new StringResourceModel(key, null, null, params); m.setLocalizer(c.getLocalizer()); return m.getString(); }
From source file:org.modelibra.wicket.util.LocalizedText.java
License:Apache License
/** * Obtains a localized text by asking the component's localizer. If the text * is not found, the method returns the text key. Do not use this method in * component constructor.//from www . j a v a 2s .c o m * * @param comp * the component requesting the text * @param textKey * @return text */ public static String getText(Component comp, String textKey) { String text; text = comp.getLocalizer().getString(textKey, comp); return text; }