List of usage examples for org.apache.wicket Component getPath
public final String getPath()
From source file:com.fortuityframework.wicket.WicketEventListenerLocator.java
License:Apache License
/** * Called by the FortuityComponentInstantiationListener when a new component * has been created. Scans the component's class structure and adds handlers * for any event response method in the component * // ww w . jav a 2 s.c om * @param component * The component that was added */ synchronized void onComponentAdded(Component component) { Class<?> componentClass = component.getClass(); for (Method m : componentClass.getMethods()) { OnFortuityEvent metadata = m.getAnnotation(OnFortuityEvent.class); if (metadata != null) { if (m.getParameterTypes().length == 1 && m.getParameterTypes()[0] == EventContext.class) { Class<? extends Event<?>>[] events = getEvents(metadata); for (Class<? extends Event<?>> event : events) { if (!listeners.containsKey(event)) { listeners.put(event, new HashSet<ComponentEventListener>()); } listeners.get(event).add(new ComponentEventListener(component, m)); } } else { log.error("Fortuity event listener has incorrect parameter sequence for method " + m.toGenericString() + " on component " + component.getPath() + " of page " + component.getPage().toString()); } } } }
From source file:com.francetelecom.clara.cloud.presentation.utils.PaasWicketTester.java
License:Apache License
public String lookupPath(final MarkupContainer markupContainer, final String path) { // try to look it up directly if (markupContainer.get(path) != null) return path; // if that fails, traverse the component hierarchy looking for it final List<Component> candidates = new ArrayList<Component>(); markupContainer.visitChildren(new IVisitor<Component, List<Component>>() { Set<Component> visited = new HashSet<Component>(); @Override/*from w w w . ja v a 2 s.c o m*/ public void component(Component c, IVisit<List<Component>> visit) { if (!visited.contains(c)) { visited.add(c); if (c.getId().equals(path)) { candidates.add(c); } else { if (c.getPath().endsWith(path)) { candidates.add(c); } } } } }); // if its unambiguous, then return the full path if (candidates.isEmpty()) { fail("path: '" + path + "' not found for " + Classes.simpleName(markupContainer.getClass())); return null; } else if (candidates.size() == 1) { String pathToContainer = markupContainer.getPath(); String pathToComponent = candidates.get(0).getPath(); return pathToComponent.replaceFirst(pathToContainer + ":", ""); } else { String message = "path: '" + path + "' is ambiguous for " + Classes.simpleName(markupContainer.getClass()) + ". Possible candidates are: "; for (Component c : candidates) { message += "[" + c.getPath() + "]"; } fail(message); return null; } }
From source file:de.flapdoodle.wicket.detach.FieldInspectingDetachListener.java
License:Apache License
@Override public void onDetach(Component component) { Class<? extends Component> clazz = component.getClass(); if (false)/*from w ww. j a va 2 s. co m*/ log.debug("detaching {} ", typeName(clazz)); List<Field> fields = getAllFields(clazz); Map<Object, Boolean> hitMap = new IdentityHashMap<Object, Boolean>(); checkFields(typeName(clazz) + "[path=" + component.getPath() + "]", hitMap, component, fields); }
From source file:de.flapdoodle.wicket.serialize.java.printer.AbstractPrettyStacktracePrinter.java
License:Apache License
protected String toPrettyPrintedStack(List<TraceSlot> localTraceStack, String type, String message) { StringBuilder result = new StringBuilder(); StringBuilder spaces = new StringBuilder(); result.append("Unable to serialize class: "); result.append(type);/*from w w w . java2 s . c o m*/ result.append("\nField hierarchy is:"); for (Iterator<TraceSlot> i = localTraceStack.listIterator(); i.hasNext();) { spaces.append(" "); TraceSlot slot = i.next(); result.append("\n").append(spaces).append(slot.fieldDescription); result.append(" [class=").append(slot.object.getClass().getName()); if (slot.object.getClass().isAnonymousClass()) { result.append(", superclass=").append(slot.object.getClass().getSuperclass().getName()); } if (slot.object instanceof Component) { Component component = (Component) slot.object; result.append(", path=").append(component.getPath()); } result.append("]"); } result.append(" <----- " + message); return result.toString(); }
From source file:de.inren.frontend.application.security.InRenAuthorizationStrategy.java
License:Apache License
@Override public boolean isActionAuthorized(Component component, Action action) { if (!(SecuredPage.class.isAssignableFrom(component.getClass()))) { return true; }/*from ww w . ja v a 2 s . co m*/ log.info("isActionAuthorized : " + component.getPath() + " action:" + action.getName()); for (ComponentAccess componentAccess : componentAccessService.getComponentAccessList()) { if (component.getClass().getSimpleName().equalsIgnoreCase(componentAccess.getName())) { log.info("Found componentAccess=" + componentAccess); BasicAuthenticationSession s = ((BasicAuthenticationSession) Session.get()); User u = s.getUser(); log.info("User u=" + u); if (u != null) { log.info("user rights are: " + u.getGrantedRoles()); Role role = hasRole(u.getGrantedRoles(), componentAccess.getGrantedRoles()); log.info("role check result = " + role); if (isActionAllowed(action, role)) { return true; } } } } // TODO nur Test return false; }
From source file:de.micromata.genome.junittools.wicket.TpsbWicketTools.java
License:Apache License
/** * Internal finder.// www . j a va2s . c om * * @param <X> the generic type * @param tester the tester * @param startComponent the start component * @param componentClass the component class * @param matcher the matcher * @return the list */ private static <X extends Component> List<X> internalFinder(WicketTester tester, MarkupContainer startComponent, Class<X> componentClass, final Matcher<Component> matcher) { final List<X> results = new LinkedList<X>(); Page lastRenderedPage = tester.getLastRenderedPage(); if (lastRenderedPage == null) { throw new IllegalStateException("You must call #goToPage before you can find components."); } if (componentClass == null) { componentClass = (Class<X>) Component.class; } final Class<? extends Component> searchComponent = componentClass; IVisitor<Component, Object> visitor = new IVisitor<Component, Object>() { @Override public void component(Component object, IVisit<Object> visit) { if (LOG.isDebugEnabled() == true) { LOG.debug("candite for wicket internalFinder: " + object.getClass().getSimpleName() + "|" + object.getId() + "|" + object.getPath()); } if (searchComponent.isAssignableFrom(object.getClass()) == true) { if (matcher.match(object) == true) { if (matcher instanceof TpsbWicketMatchSelector) { results.add((X) ((TpsbWicketMatchSelector) matcher).selectMatched(object)); } else { results.add((X) object); } } } } }; if (startComponent == null) { lastRenderedPage.visitChildren(visitor); } else { startComponent.visitChildren(visitor); } return results; }
From source file:de.micromata.genome.junittools.wicket.TpsbWicketTools.java
License:Apache License
/** * Find components for property model property. * //from ww w . j a va2 s .c o m * @param <X> the generic type * @param tester the tester * @param startComponent the start component * @param componentClass the component class * @param property the property * @return the list * @deprecated use TpsbWicketMatchSelector */ @Deprecated public static <X extends Component> List<X> _findComponentsForPropertyModelProperty(WicketTester tester, final MarkupContainer startComponent, final Class<X> componentClass, final String property) { final List<X> results = new LinkedList<X>(); Page lastRenderedPage = tester.getLastRenderedPage(); if (lastRenderedPage == null) { throw new IllegalStateException("You must call #goToPage before you can find components."); } if (componentClass == null || property == null) { throw new IllegalArgumentException("You must provide not null arguments."); } IVisitor<Component, Object> visitor = new IVisitor<Component, Object>() { @Override public void component(Component object, IVisit<Object> visit) { if (LOG.isDebugEnabled() == true) { LOG.debug("candite for wicket internalFinder: " + object.getClass().getSimpleName() + "|" + object.getId() + "|" + object.getPath()); } if (componentClass.isAssignableFrom(object.getClass()) == true) { IModel<?> defaultModel = object.getDefaultModel(); if (defaultModel instanceof AbstractPropertyModel == true) { AbstractPropertyModel propertyModel = (AbstractPropertyModel) defaultModel; if (StringUtils.equals(property, propertyModel.getPropertyExpression()) == true) { results.add((X) object); } } } } }; if (startComponent == null) { lastRenderedPage.visitChildren(visitor); } else { startComponent.visitChildren(visitor); } return results; }
From source file:fiftyfive.wicket.css.IterationCssBehavior.java
License:Apache License
/** * Assume that the component is a {@link ListItem}, * {@link LoopItem}, or {@link Item}// www .j a va 2 s .co m * and get its index. Note that the index begins from zero. * * @throws UnsupportedOperationException if the component is not one of the three supported * types */ protected int getIndex(Component component) { if (component instanceof ListItem) { return ((ListItem) component).getIndex(); } if (component instanceof LoopItem) { return ((LoopItem) component).getIndex(); } if (component instanceof Item) { return ((Item) component).getIndex(); } throw new UnsupportedOperationException(String.format( "Don't know how to find the index of component %s (%s). " + "Only list.ListItem, list.LoopItem and repeater.Item are supported. " + "Perhaps you attached IterationCssBehavior to the wrong component?", component.getPath(), component.getClass())); }
From source file:fiftyfive.wicket.css.IterationCssBehavior.java
License:Apache License
/** * Assume that the component has an immediate parent of {@link ListView}, {@link Loop}, or * {@link RepeatingView} and use what we know about those implementations to infer the * size of the list that is being iterated. Note that in the case of pagination, this is the * size of the visible items (i.e the current page), not the total size that includes other * pages.// ww w .jav a 2s. c o m * * @throws UnsupportedOperationException if the parent component is not one of the three * supported types */ protected int getSize(Component component) { MarkupContainer parent = component.getParent(); if (parent instanceof ListView) { return ((ListView) parent).getViewSize(); } if (parent instanceof Loop) { return ((Loop) parent).getIterations(); } if (parent instanceof RepeatingView) { // TODO: more efficent way? int size = 0; Iterator iter = parent.iterator(); while (iter.hasNext()) { iter.next(); size++; } return size; } throw new IllegalStateException(String.format( "Don't know how to find the size of the repeater that contains component " + "%s (%s). " + "Only list.ListItem, list.LoopItem and repeater.Item are supported. " + "Perhaps you attached IterationCssBehavior to the wrong component?", component.getPath(), component.getClass())); }
From source file:name.martingeisse.admin.util.StatelessUtil.java
License:Open Source License
/** * Dumps the stateful components in the component hierarchy, starting at * the specified component./* ww w . j a v a 2s .co m*/ * * @param root the component to start at */ public static void dumpStatefulComponents(final Component root) { ParameterUtil.ensureNotNull(root, "root"); if (!root.isStateless()) { System.out.println("stateful component: " + root.getPath()); } if (root instanceof MarkupContainer) { final MarkupContainer container = (MarkupContainer) root; for (final Component child : container) { dumpStatefulComponents(child); } } }