Example usage for org.apache.wicket MarkupContainer getString

List of usage examples for org.apache.wicket MarkupContainer getString

Introduction

In this page you can find the example usage for org.apache.wicket MarkupContainer getString.

Prototype

public final String getString(final String key) 

Source Link

Usage

From source file:com.olegchir.flussonic_userlinks.wicket.IncludeResolver.IncludeResolver.java

License:Apache License

/**
 * Handles resolving the wicket:include tag. If a filename is specified this
 * file will be looked up. If a key is specified it's value is looked up
 * using the resource mechanism. The looked up value will then be used as
 * filename.//ww w  .j  av  a 2  s. c om
 *
 */
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {

    if ((tag instanceof WicketTag) && tagname.equalsIgnoreCase(tag.getName())) {
        WicketTag wtag = (WicketTag) tag;

        String fileName = StringUtils.trimToNull(wtag.getAttribute("file"));
        String fileKey = StringUtils.trimToNull(wtag.getAttribute("key"));

        if (null != fileKey) {
            if (null != fileName) {
                throw new MarkupException("Wrong format of: you must not use file and key attribtue at once");
            }
            fileName = StringUtils.trimToNull(container.getString(fileKey));
            if (null == fileName) {
                throw new MarkupException("The key inside could not be resolved");
            }

        } else if (null == fileName) {
            throw new MarkupException("Wrong format of: specify the file or key attribute");
        }

        final String id = "_" + tagname + "_" + container.getPage().getAutoIndex();
        IncludeContainer ic = new IncludeContainer(id, fileName, fileKey, markupStream);
        ic.setRenderBodyOnly(container.getApplication().getMarkupSettings().getStripWicketTags());
        //            container.autoAdd(ic, markupStream);

        return ic;

    }
    return null;
}

From source file:org.projectforge.web.wicket.WicketPageTestBase.java

License:Open Source License

/**
 * Searches FormComponents (model object), LabeledWebmarkupContainers (label model) and ContentMenuEntryPanels (label).
 * @param container/*from ww  w  . j  a v a 2  s.  c om*/
 * @param label i18n key of the label or label (for buttons).
 * @return Found component with the given label or null if no such component found.
 * @see FormComponent#getModelObject()
 * @see LabeledWebMarkupContainer#getLabel()
 * @see ContentMenuEntryPanel#getLabel()
 */
public Component findComponentByLabel(final MarkupContainer container, final String label) {
    String str = label;
    try {
        str = container.getString(label);
    } catch (final MissingResourceException ex) {
        // OK
    }
    final String locLabel = str;
    final Component[] component = new Component[1];
    container.visitChildren(new IVisitor<Component, Void>() {
        @Override
        public void component(final Component object, final IVisit<Void> visit) {
            if (object instanceof AbstractLink) {
                final MarkupContainer parent = object.getParent();
                if (parent instanceof ContentMenuEntryPanel) {
                    if (labelEquals(((ContentMenuEntryPanel) parent).getLabel(), label, locLabel) == true) {
                        component[0] = object;
                        visit.stop();
                    }
                } else if (object.getId().equals(locLabel) == true) {
                    component[0] = object;
                    visit.stop();
                }
            } else {
                if (object instanceof LabeledWebMarkupContainer) {
                    final IModel<String> labelModel = ((LabeledWebMarkupContainer) object).getLabel();
                    if (labelModel != null) {
                        if (labelEquals(labelModel.getObject(), label, locLabel) == true) {
                            component[0] = object;
                            visit.stop();
                        }
                    }
                }
                if (object instanceof FormComponent<?>) {
                    final Object modelObject = ((FormComponent<?>) object).getModelObject();
                    if (modelObject instanceof String) {
                        if (labelEquals((String) modelObject, label, locLabel) == true) {
                            component[0] = object;
                            visit.stop();
                        }
                    }
                }
            }
        }
    });
    return component[0];
}

From source file:org.projectforge.web.wicket.WicketUtils.java

License:Open Source License

/**
 * Add JavaScript function showDeleteEntryQuestionDialog(). Depending on BaseDao.isHistorizable() a delete or mark-as-deleted question
 * will be displayed. Usage in markup: &lt;script wicket:id="showDeleteEntryQuestionDialog"&gt;[...]&lt;/script&gt;
 * @param parent//from  w  w w.j a  v a  2s .  com
 * @param dao
 */
public static void addShowDeleteRowQuestionDialog(final MarkupContainer parent, final BaseDao<?> dao) {
    final StringBuffer buf = new StringBuffer();
    buf.append("function showDeleteEntryQuestionDialog() {\n").append("  return window.confirm('");
    if (dao.isHistorizable() == true) {
        buf.append(parent.getString("question.markAsDeletedQuestion"));
    } else {
        buf.append(parent.getString("question.deleteQuestion"));
    }
    buf.append("');\n}\n");
    parent.add(new Label("showDeleteEntryQuestionDialog", buf.toString()).setEscapeModelStrings(false)
            .add(AttributeModifier.replace("type", "text/javascript")));
}

From source file:org.projectforge.web.wicket.WicketUtils.java

License:Open Source License

/**
 * @param parent Only for i18n needed.//w  ww  . ja v a  2 s . c o m
 * @param startTime Start time or null.
 * @param stopTime Stop time or null.
 * @return The weeks of year range for the given start an stop time.
 */
public static String getCalendarWeeks(final MarkupContainer parent, final Date startTime, final Date stopTime) {
    int fromWeek = -1;
    int toWeek = -1;
    if (startTime != null) {
        fromWeek = DateHelper.getWeekOfYear(startTime);
    }
    if (stopTime != null) {
        toWeek = DateHelper.getWeekOfYear(stopTime);
    }
    if (fromWeek < 0 && toWeek < 0) {
        return "";
    }
    final StringBuffer buf = new StringBuffer();
    buf.append(parent.getString("calendar.weekOfYearShortLabel")).append(" ");
    if (fromWeek >= 0) {
        buf.append(StringHelper.format2DigitNumber(fromWeek));
        if (toWeek == -1) {
            buf.append("-");
        } else if (toWeek != fromWeek) {
            buf.append("-").append(StringHelper.format2DigitNumber(toWeek));
        }
    } else {
        buf.append("-").append(StringHelper.format2DigitNumber(toWeek));
    }
    return buf.toString();
}