/** * Returns true if the user represented by the current request plays the named role. * * @param role the named role to test. * @return true if the user plays the role. */ public boolean isUserInRole(String role) { ServletInvocation invocation = getInvocation(); if (invocation == null) { if (getRequest() != null) return getRequest().isUserInRole(role); else return false; } HashMap<String, String> roleMap = invocation.getSecurityRoleMap(); if (roleMap != null) { String linkRole = roleMap.get(role); if (linkRole != null) role = linkRole; } String runAs = getRunAs(); if (runAs != null) return runAs.equals(role); WebApp webApp = getWebApp(); Principal user = getUserPrincipal(); if (user == null) { if (log.isLoggable(Level.FINE)) log.fine(this + " no user for isUserInRole"); return false; } RoleMapManager roleManager = webApp != null ? webApp.getRoleMapManager() : null; if (roleManager != null) { Boolean result = roleManager.isUserInRole(role, user); if (result != null) { if (log.isLoggable(Level.FINE)) log.fine(this + " userInRole(" + role + ")->" + result); return result; } } Login login = webApp == null ? null : webApp.getLogin(); boolean inRole = login != null && login.isUserInRole(user, role); if (log.isLoggable(Level.FINE)) { if (login == null) log.fine(this + " no Login for isUserInRole"); else if (user == null) log.fine(this + " no user for isUserInRole"); else if (inRole) log.fine(this + " " + user + " is in role: " + role); else log.fine(this + " failed " + user + " in role: " + role); } return inRole; }
/** * Sends a specific <tt>Request</tt> to the STUN server associated with this * <tt>StunCandidateHarvest</tt>. * * @param request the <tt>Request</tt> to send to the STUN server associated with this * <tt>StunCandidateHarvest</tt> * @param firstRequest <tt>true</tt> if the specified <tt>request</tt> should be sent as the first * request in the terms of STUN; otherwise, <tt>false</tt> * @return the <tt>TransactionID</tt> of the STUN client transaction through which the specified * <tt>Request</tt> has been sent to the STUN server associated with this * <tt>StunCandidateHarvest</tt> * @param transactionID the <tt>TransactionID</tt> of <tt>request</tt> because <tt>request</tt> * only has it as a <tt>byte</tt> array and <tt>TransactionID</tt> is required for the * <tt>applicationData</tt> property value * @throws StunException if anything goes wrong while sending the specified <tt>Request</tt> to * the STUN server associated with this <tt>StunCandidateHarvest</tt> */ protected TransactionID sendRequest( Request request, boolean firstRequest, TransactionID transactionID) throws StunException { if (!firstRequest && (longTermCredentialSession != null)) longTermCredentialSession.addAttributes(request); StunStack stunStack = harvester.getStunStack(); TransportAddress stunServer = harvester.stunServer; TransportAddress hostCandidateTransportAddress = hostCandidate.getTransportAddress(); if (transactionID == null) { byte[] transactionIDAsBytes = request.getTransactionID(); transactionID = (transactionIDAsBytes == null) ? TransactionID.createNewTransactionID() : TransactionID.createTransactionID(harvester.getStunStack(), transactionIDAsBytes); } synchronized (requests) { try { transactionID = stunStack.sendRequest( request, stunServer, hostCandidateTransportAddress, this, transactionID); } catch (IllegalArgumentException iaex) { if (logger.isLoggable(Level.INFO)) { logger.log( Level.INFO, "Failed to send " + request + " through " + hostCandidateTransportAddress + " to " + stunServer, iaex); } throw new StunException(StunException.ILLEGAL_ARGUMENT, iaex.getMessage(), iaex); } catch (IOException ioex) { if (logger.isLoggable(Level.INFO)) { logger.log( Level.INFO, "Failed to send " + request + " through " + hostCandidateTransportAddress + " to " + stunServer, ioex); } throw new StunException(StunException.NETWORK_ERROR, ioex.getMessage(), ioex); } requests.put(transactionID, request); } return transactionID; }
public void dispatchEvent(XEvent xev) { if (eventLog.isLoggable(Level.FINEST)) eventLog.finest(xev.toString()); int type = xev.get_type(); if (isDisposed()) { return; } switch (type) { case VisibilityNotify: handleVisibilityEvent(xev); break; case ClientMessage: handleClientMessage(xev); break; case Expose: case GraphicsExpose: handleExposeEvent(xev); break; case ButtonPress: case ButtonRelease: handleButtonPressRelease(xev); break; case MotionNotify: handleMotionNotify(xev); break; case KeyPress: handleKeyPress(xev); break; case KeyRelease: handleKeyRelease(xev); break; case EnterNotify: case LeaveNotify: handleXCrossingEvent(xev); break; case ConfigureNotify: handleConfigureNotifyEvent(xev); break; case MapNotify: handleMapNotifyEvent(xev); break; case UnmapNotify: handleUnmapNotifyEvent(xev); break; case ReparentNotify: handleReparentNotifyEvent(xev); break; case PropertyNotify: handlePropertyNotify(xev); break; case DestroyNotify: handleDestroyNotify(xev); break; case CreateNotify: handleCreateNotify(xev); break; } }
/** * Called after window creation, descendants should override to initialize Window with * class-specific values and perform post-initialization actions. */ void postInit(XCreateWindowParams params) { if (log.isLoggable(Level.FINE)) log.fine("WM name is " + getWMName()); updateWMName(); // Set WM_CLIENT_LEADER property initClientLeader(); }
public void render(FacesContext context) throws FacesException { if (context.getResponseComplete()) return; Application app = context.getApplication(); ViewHandler view = app.getViewHandler(); beforePhase(context, PhaseId.RENDER_RESPONSE); try { if (log.isLoggable(Level.FINER)) log.finer(context.getViewRoot() + " before render view"); view.renderView(context, context.getViewRoot()); } catch (java.io.IOException e) { if (sendError(context, "renderView", e)) return; throw new FacesException(e); } catch (RuntimeException e) { if (sendError(context, "renderView", e)) return; throw e; } finally { afterPhase(context, PhaseId.RENDER_RESPONSE); logMessages(context); } }
/** * Creates a <tt>ServerReflexiveCandidate</tt> using {@link #hostCandidate} as its base and the * <tt>XOR-MAPPED-ADDRESS</tt> attribute in <tt>response</tt> for the actual * <tt>TransportAddress</tt> of the new candidate. If the message is malformed and/or does not * contain the corresponding attribute, this method simply has no effect. * * @param response the STUN <tt>Response</tt> which is supposed to contain the address we should * use for the new candidate */ protected void createServerReflexiveCandidate(Response response) { TransportAddress addr = getMappedAddress(response); if (addr != null) { ServerReflexiveCandidate srvrRflxCand = createServerReflexiveCandidate(addr); if (srvrRflxCand != null) { try { addCandidate(srvrRflxCand); } finally { // Free srvrRflxCand if it has not been consumed. if (!containsCandidate(srvrRflxCand)) { try { srvrRflxCand.free(); } catch (Exception ex) { if (logger.isLoggable(Level.FINE)) { logger.log( Level.FINE, "Failed to free" + " ServerReflexiveCandidate: " + srvrRflxCand, ex); } } } } } } }
/** * Copies the properties of a specific <tt>DatagramPacket</tt> to another <tt>DatagramPacket</tt>. * The property values are not cloned. * * @param src the <tt>DatagramPacket</tt> which is to have its properties copied to <tt>dest</tt> * @param dest the <tt>DatagramPacket</tt> which is to have its properties set to the value of the * respective properties of <tt>src</tt> */ public static void copy(DatagramPacket src, DatagramPacket dest) { synchronized (dest) { dest.setAddress(src.getAddress()); dest.setPort(src.getPort()); byte[] srcData = src.getData(); if (srcData == null) dest.setLength(0); else { byte[] destData = dest.getData(); if (destData == null) dest.setLength(0); else { int destOffset = dest.getOffset(); int destLength = destData.length - destOffset; int srcLength = src.getLength(); if (destLength >= srcLength) destLength = srcLength; else if (logger.isLoggable(Level.WARNING)) { logger.log(Level.WARNING, "Truncating received DatagramPacket data!"); } System.arraycopy(srcData, src.getOffset(), destData, destOffset, destLength); dest.setLength(destLength); } } } }
@Override public boolean login(boolean isFail) { try { WebApp webApp = getWebApp(); if (webApp == null) { if (log.isLoggable(Level.FINE)) log.finer("authentication failed, no web-app found"); getResponse().sendError(HttpServletResponse.SC_FORBIDDEN); return false; } // If the authenticator can find the user, return it. Login login = webApp.getLogin(); if (login != null) { Principal user = login.login(this, getResponse(), isFail); return user != null; /* if (user == null) return false; setAttribute(AbstractLogin.LOGIN_NAME, user); return true; */ } else if (isFail) { if (log.isLoggable(Level.FINE)) log.finer("authentication failed, no login module found for " + webApp); getResponse().sendError(HttpServletResponse.SC_FORBIDDEN); return false; } else { // if a non-failure, then missing login is fine return false; } } catch (IOException e) { log.log(Level.FINE, e.toString(), e); return false; } }
public void handlePropertyNotify(XEvent xev) { XPropertyEvent msg = xev.get_xproperty(); if (XPropertyCache.isCachingSupported()) { XPropertyCache.clearCache(window, XAtom.get(msg.get_atom())); } if (eventLog.isLoggable(Level.FINER)) { eventLog.log(Level.FINER, "{0}", new Object[] {String.valueOf(msg)}); } }
public void handleConfigureNotifyEvent(XEvent xev) { XConfigureEvent xe = xev.get_xconfigure(); if (insLog.isLoggable(Level.FINER)) { insLog.log(Level.FINER, "Configure, {0}", new Object[] {String.valueOf(xe)}); } x = xe.get_x(); y = xe.get_y(); width = xe.get_width(); height = xe.get_height(); }
public void xRequestFocus() { XToolkit.awtLock(); try { if (focusLog.isLoggable(Level.FINER)) focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow())); XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow()); } finally { XToolkit.awtUnlock(); } }
/** Deserializes the object from XML */ public Serializable fromXml(XmppStreamReader in) throws IOException, XMLStreamException { boolean isFinest = log.isLoggable(Level.FINEST); String type = in.getAttributeValue(null, "type"); DataForm form = new DataForm(type); ArrayList<DataField> fieldList = new ArrayList<DataField>(); ArrayList<DataItem> itemList = new ArrayList<DataItem>(); ArrayList<DataInstructions> instructionsList = new ArrayList<DataInstructions>(); int tag = in.nextTag(); while (tag > 0) { if (isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { form.setFieldList(fieldList); form.setItemList(itemList); form.setInstructionsList(instructionsList); return form; } if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) { fieldList.add(parseField(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "item".equals(in.getLocalName())) { itemList.add(parseItem(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "reported".equals(in.getLocalName())) { form.setReported(parseReported(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "title".equals(in.getLocalName())) { String title = in.getElementText(); form.setTitle(title); skipToEnd(in, "title"); } else if (XMLStreamReader.START_ELEMENT == tag && "instructions".equals(in.getLocalName())) { String value = in.getElementText(); instructionsList.add(new DataInstructions(value)); skipToEnd(in, "instructions"); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } return null; }
public void xSetVisible(boolean visible) { if (log.isLoggable(Level.FINE)) log.fine("Setting visible on " + this + " to " + visible); XToolkit.awtLock(); try { this.visible = visible; if (visible) { XlibWrapper.XMapWindow(XToolkit.getDisplay(), getWindow()); } else { XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), getWindow()); } XlibWrapper.XFlush(XToolkit.getDisplay()); } finally { XToolkit.awtUnlock(); } }
/** * Sets the current device controller to the given value. * * @param aDeviceName the name of the device controller to set, cannot be <code>null</code>. */ public synchronized void setDeviceController(final String aDeviceName) { if (LOG.isLoggable(Level.INFO)) { final String name = (aDeviceName == null) ? "no device" : aDeviceName; LOG.log(Level.INFO, "Setting current device controller to: \"{0}\" ...", name); } final Collection<DeviceController> devices = getDevices(); for (DeviceController device : devices) { if (aDeviceName.equals(device.getName())) { this.currentDevCtrl = device; } } updateActions(); }
/** * Runs the tool denoted by the given name. * * @param aToolName the name of the tool to run, cannot be <code>null</code>; * @param aParent the parent window to use, can be <code>null</code>. */ public void runTool(final String aToolName, final Window aParent) { if (LOG.isLoggable(Level.INFO)) { LOG.log(Level.INFO, "Running tool: \"{0}\" ...", aToolName); } final Tool tool = findToolByName(aToolName); if (tool == null) { JOptionPane.showMessageDialog( aParent, "No such tool found: " + aToolName, "Error ...", JOptionPane.ERROR_MESSAGE); } else { final ToolContext context = createToolContext(); tool.process(aParent, this.dataContainer, context, this); } updateActions(); }
private void logMessages(FacesContext context) { UIViewRoot root = context.getViewRoot(); String viewId = ""; if (root != null) viewId = root.getViewId(); Iterator<FacesMessage> iter = context.getMessages(); while (iter != null && iter.hasNext()) { FacesMessage msg = iter.next(); if (log.isLoggable(Level.FINE)) { if (msg.getDetail() != null) log.fine( viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary() + " " + msg.getDetail()); else log.fine(viewId + " [ " + msg.getSeverity() + "] " + msg.getSummary()); } } }
static void ungrabInput() { XToolkit.awtLock(); try { XBaseWindow grabWindow = XAwtState.getGrabWindow(); if (grabLog.isLoggable(Level.FINE)) { grabLog.log(Level.FINE, "UnGrab input on {0}", new Object[] {String.valueOf(grabWindow)}); } if (grabWindow != null) { grabWindow.ungrabInputImpl(); XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime); XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), CurrentTime); XAwtState.setGrabWindow(null); // we need to call XFlush() here to force ungrab // see 6384219 for details XlibWrapper.XFlush(XToolkit.getDisplay()); } } finally { XToolkit.awtUnlock(); } }
public boolean isRequestRecognizable(DSLAMProviderRequest request) throws IOException { boolean res = false; { Map<String, Object> systemProperties = DSLAMProviderUtil.readSNMPTargetSystemProperties(request); String[] subStrings = getSubStringForDetection(); if (DSLAMProviderUtil.doesTargetSystemPropertiesContain(systemProperties, subStrings)) { res = true; } // Log result: { Logger logger = ProviderLog.getLogger(); Level level = Level.FINE; if (logger.isLoggable(level)) { String message = "The result of request recognition for DSLAM \"" + request.getTarget() + "\" against allocator \"" + getAllocatorName() + "\" is: " + res + " (DSLAM-system-properties=" + systemProperties + ", allocator-sub-strings=" + Arrays.toString(subStrings) + ")!"; logger.log(level, message); } } } return res; }
public void handleClientMessage(XEvent xev) { if (eventLog.isLoggable(Level.FINER)) { XClientMessageEvent msg = xev.get_xclient(); eventLog.finer(msg.toString()); } }
public void handleReparentNotifyEvent(XEvent xev) { if (eventLog.isLoggable(Level.FINER)) { XReparentEvent msg = xev.get_xreparent(); eventLog.finer(msg.toString()); } }
/** * We should always grab both keyboard and pointer to control event flow on popups. This also * simplifies synthetic grab implementation. The active grab overrides activated automatic grab. */ public boolean grabInput() { if (grabLog.isLoggable(Level.FINE)) { grabLog.log(Level.FINE, "Grab input on {0}", new Object[] {String.valueOf(this)}); } XToolkit.awtLock(); try { if (XAwtState.getGrabWindow() == this && XAwtState.isManualGrab()) { grabLog.fine(" Already Grabbed"); return true; } // 6273031: PIT. Choice drop down does not close once it is right clicked to show a popup menu // remember previous window having grab and if it's not null ungrab it. XBaseWindow prevGrabWindow = XAwtState.getGrabWindow(); final int eventMask = (int) (ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask); final int ownerEvents = 1; int ptrGrab = XlibWrapper.XGrabPointer( XToolkit.getDisplay(), getContentWindow(), ownerEvents, eventMask, GrabModeAsync, GrabModeAsync, None, (XWM.isMotif() ? XToolkit.arrowCursor : None), CurrentTime); // Check grab results to be consistent with X server grab if (ptrGrab != GrabSuccess) { XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime); XAwtState.setGrabWindow(null); grabLog.fine(" Grab Failure - mouse"); return false; } int keyGrab = XlibWrapper.XGrabKeyboard( XToolkit.getDisplay(), getContentWindow(), ownerEvents, GrabModeAsync, GrabModeAsync, CurrentTime); if (keyGrab != GrabSuccess) { XlibWrapper.XUngrabPointer(XToolkit.getDisplay(), CurrentTime); XlibWrapper.XUngrabKeyboard(XToolkit.getDisplay(), CurrentTime); XAwtState.setGrabWindow(null); grabLog.fine(" Grab Failure - keyboard"); return false; } if (prevGrabWindow != null) { prevGrabWindow.ungrabInputImpl(); } XAwtState.setGrabWindow(this); grabLog.fine(" Grab - success"); return true; } finally { XToolkit.awtUnlock(); } }
public void setSizeHints(long flags, int x, int y, int width, int height) { if (insLog.isLoggable(Level.FINER)) insLog.finer("Setting hints, flags " + XlibWrapper.hintsToString(flags)); XToolkit.awtLock(); try { XSizeHints hints = getHints(); // Note: if PPosition is not set in flags this means that // we want to reset PPosition in hints. This is necessary // for locationByPlatform functionality if ((flags & XlibWrapper.PPosition) != 0) { hints.set_x(x); hints.set_y(y); } if ((flags & XlibWrapper.PSize) != 0) { hints.set_width(width); hints.set_height(height); } else if ((hints.get_flags() & XlibWrapper.PSize) != 0) { flags |= XlibWrapper.PSize; } if ((flags & XlibWrapper.PMinSize) != 0) { hints.set_min_width(width); hints.set_min_height(height); } else if ((hints.get_flags() & XlibWrapper.PMinSize) != 0) { flags |= XlibWrapper.PMinSize; // Fix for 4320050: Minimum size for java.awt.Frame is not being enforced. // We don't need to reset minimum size if it's already set } if ((flags & XlibWrapper.PMaxSize) != 0) { if (maxBounds != null) { if (maxBounds.width != Integer.MAX_VALUE) { hints.set_max_width(maxBounds.width); } else { hints.set_max_width(XToolkit.getDefaultScreenWidth()); } if (maxBounds.height != Integer.MAX_VALUE) { hints.set_max_height(maxBounds.height); } else { hints.set_max_height(XToolkit.getDefaultScreenHeight()); } } else { hints.set_max_width(width); hints.set_max_height(height); } } else if ((hints.get_flags() & XlibWrapper.PMaxSize) != 0) { flags |= XlibWrapper.PMaxSize; if (maxBounds != null) { if (maxBounds.width != Integer.MAX_VALUE) { hints.set_max_width(maxBounds.width); } else { hints.set_max_width(XToolkit.getDefaultScreenWidth()); } if (maxBounds.height != Integer.MAX_VALUE) { hints.set_max_height(maxBounds.height); } else { hints.set_max_height(XToolkit.getDefaultScreenHeight()); } } else { // Leave intact } } flags |= XlibWrapper.PWinGravity; hints.set_flags(flags); hints.set_win_gravity((int) XlibWrapper.NorthWestGravity); if (insLog.isLoggable(Level.FINER)) insLog.finer( "Setting hints, resulted flags " + XlibWrapper.hintsToString(flags) + ", values " + hints); XlibWrapper.XSetWMNormalHints(XToolkit.getDisplay(), getWindow(), hints.pData); } finally { XToolkit.awtUnlock(); } }
/** * Creates window with parameters specified by <code>params</code> * * @see #init */ private final void create(XCreateWindowParams params) { XToolkit.awtLock(); try { XSetWindowAttributes xattr = new XSetWindowAttributes(); try { checkParams(params); long value_mask = ((Long) params.get(VALUE_MASK)).longValue(); Long eventMask = (Long) params.get(EVENT_MASK); xattr.set_event_mask(eventMask.longValue()); value_mask |= XlibWrapper.CWEventMask; Long border_pixel = (Long) params.get(BORDER_PIXEL); if (border_pixel != null) { xattr.set_border_pixel(border_pixel.longValue()); value_mask |= XlibWrapper.CWBorderPixel; } Long colormap = (Long) params.get(COLORMAP); if (colormap != null) { xattr.set_colormap(colormap.longValue()); value_mask |= XlibWrapper.CWColormap; } Long background_pixmap = (Long) params.get(BACKGROUND_PIXMAP); if (background_pixmap != null) { xattr.set_background_pixmap(background_pixmap.longValue()); value_mask |= XlibWrapper.CWBackPixmap; } Long parentWindow = (Long) params.get(PARENT_WINDOW); Rectangle bounds = (Rectangle) params.get(BOUNDS); Integer depth = (Integer) params.get(DEPTH); Integer visual_class = (Integer) params.get(VISUAL_CLASS); Long visual = (Long) params.get(VISUAL); Boolean overrideRedirect = (Boolean) params.get(OVERRIDE_REDIRECT); if (overrideRedirect != null) { xattr.set_override_redirect(overrideRedirect.booleanValue()); value_mask |= XlibWrapper.CWOverrideRedirect; } Boolean saveUnder = (Boolean) params.get(SAVE_UNDER); if (saveUnder != null) { xattr.set_save_under(saveUnder.booleanValue()); value_mask |= XlibWrapper.CWSaveUnder; } Integer backingStore = (Integer) params.get(BACKING_STORE); if (backingStore != null) { xattr.set_backing_store(backingStore.intValue()); value_mask |= XlibWrapper.CWBackingStore; } Integer bitGravity = (Integer) params.get(BIT_GRAVITY); if (bitGravity != null) { xattr.set_bit_gravity(bitGravity.intValue()); value_mask |= XlibWrapper.CWBitGravity; } if (log.isLoggable(Level.FINE)) { log.fine("Creating window for " + this + " with the following attributes: \n" + params); } window = XlibWrapper.XCreateWindow( XToolkit.getDisplay(), parentWindow.longValue(), bounds.x, bounds.y, // location bounds.width, bounds.height, // size 0, // border depth.intValue(), // depth visual_class.intValue(), // class visual.longValue(), // visual value_mask, // value mask xattr.pData); // attributes if (window == 0) { throw new IllegalStateException( "Couldn't create window because of wrong parameters. Run with NOISY_AWT to see details"); } XToolkit.addToWinMap(window, this); } finally { xattr.dispose(); } } finally { XToolkit.awtUnlock(); } }
public void execute(FacesContext context) throws FacesException { boolean isFiner = log.isLoggable(Level.FINER); if (context.getResponseComplete() || context.getRenderResponse()) return; beforePhase(context, PhaseId.RESTORE_VIEW); try { if (isFiner) log.finer("JSF[] before restore view"); restoreView(context); } finally { afterPhase(context, PhaseId.RESTORE_VIEW); } if (context.getResponseComplete() || context.getRenderResponse()) return; UIViewRoot viewRoot = context.getViewRoot(); beforePhase(context, PhaseId.APPLY_REQUEST_VALUES); try { if (isFiner) log.finer(context.getViewRoot() + " before process decodes"); viewRoot.processDecodes(context); } catch (RuntimeException e) { log.log(Level.WARNING, e.toString(), e); } finally { afterPhase(context, PhaseId.APPLY_REQUEST_VALUES); } // // Process Validations (processValidators) // if (context.getResponseComplete() || context.getRenderResponse()) return; beforePhase(context, PhaseId.PROCESS_VALIDATIONS); try { if (isFiner) log.finer(context.getViewRoot() + " before process validators"); viewRoot.processValidators(context); } finally { afterPhase(context, PhaseId.PROCESS_VALIDATIONS); } // // Update Model Values (processUpdates) // if (context.getResponseComplete() || context.getRenderResponse()) return; beforePhase(context, PhaseId.UPDATE_MODEL_VALUES); try { if (isFiner) log.finer(context.getViewRoot() + " before process updates"); viewRoot.processUpdates(context); } catch (RuntimeException e) { if (sendError(context, "processUpdates", e)) return; } finally { afterPhase(context, PhaseId.UPDATE_MODEL_VALUES); } // // Invoke Application (processApplication) // if (context.getResponseComplete() || context.getRenderResponse()) return; beforePhase(context, PhaseId.INVOKE_APPLICATION); try { if (isFiner) log.finer(context.getViewRoot() + " before process application"); viewRoot.processApplication(context); } finally { afterPhase(context, PhaseId.INVOKE_APPLICATION); } }
/** * DataForm * * <p>XEP-0004: http://www.xmpp.org/extensions/xep-0004.html <code><pre> * namespace = jabber:x:data * * element x { * attribute type, * * instructions*, * title?, * field*, * reported?, * item* * } * * element field { * attribute label?, * attribute type?, * attribute var?, * * desc?, * required?, * value*, * option*, * } * * element item { * field+ * } * * element option { * attribute label?, * * value* * } * * element reported { * field+ * } * * element value { * string * } * </pre></code> */ public class XmppDataFormMarshal extends AbstractXmppMarshal { private static final Logger log = Logger.getLogger(XmppDataFormMarshal.class.getName()); private static final boolean _isFinest = log.isLoggable(Level.FINEST); /** Returns the namespace uri for the XMPP stanza value */ public String getNamespaceURI() { return "jabber:x:data"; } /** Returns the local name for the XMPP stanza value */ public String getLocalName() { return "x"; } /** Returns the java classname of the object */ public String getClassName() { return DataForm.class.getName(); } /** Serializes the object to XML */ public void toXml(XmppStreamWriter out, Serializable object) throws IOException, XMLStreamException { DataForm form = (DataForm) object; out.writeStartElement("", getLocalName(), getNamespaceURI()); out.writeNamespace("", getNamespaceURI()); if (form.getType() != null) out.writeAttribute("type", form.getType()); if (form.getTitle() != null) { out.writeStartElement("title"); out.writeCharacters(form.getTitle()); out.writeEndElement(); // </title> } DataInstructions[] instructions = form.getInstructions(); if (instructions != null) { for (DataInstructions instruction : instructions) { toXml(out, instruction); } } DataField[] fields = form.getField(); if (fields != null) { for (DataField field : fields) { toXml(out, field); } } if (form.getReported() != null) toXml(out, form.getReported()); DataItem[] items = form.getItem(); if (items != null) { for (DataItem item : items) { toXml(out, item); } } out.writeEndElement(); // </form> } private void toXml(XmppStreamWriter out, DataField field) throws IOException, XMLStreamException { out.writeStartElement("field"); if (field.getLabel() != null) out.writeAttribute("label", field.getLabel()); if (field.getType() != null) out.writeAttribute("type", field.getType()); if (field.getVar() != null) out.writeAttribute("var", field.getVar()); if (field.getDesc() != null) { out.writeStartElement("desc"); out.writeCharacters(field.getDesc()); out.writeEndElement(); // </desc> } if (field.isRequired()) { out.writeStartElement("required"); out.writeEndElement(); // </required> } DataValue[] values = field.getValue(); if (values != null) { for (int i = 0; i < values.length; i++) { DataValue value = values[i]; out.writeStartElement("value"); out.writeCharacters(value.getValue()); out.writeEndElement(); // </value> } } DataOption[] options = field.getOption(); if (options != null) { for (int i = 0; i < options.length; i++) { toXml(out, options[i]); } } out.writeEndElement(); // </field> } private void toXml(XmppStreamWriter out, DataOption option) throws IOException, XMLStreamException { out.writeStartElement("option"); if (option.getLabel() != null) out.writeAttribute("label", option.getLabel()); DataValue[] values = option.getValue(); if (values != null) { for (int i = 0; i < values.length; i++) { DataValue value = values[i]; out.writeStartElement("value"); out.writeCharacters(value.getValue()); out.writeEndElement(); // </value> } } out.writeEndElement(); // </option> } private void toXml(XmppStreamWriter out, DataItem item) throws IOException, XMLStreamException { out.writeStartElement("item"); DataField[] fields = item.getField(); if (fields != null) { for (int i = 0; i < fields.length; i++) { toXml(out, fields[i]); } } out.writeEndElement(); // </item> } private void toXml(XmppStreamWriter out, DataReported reported) throws IOException, XMLStreamException { out.writeStartElement("reported"); DataField[] fields = reported.getField(); if (fields != null) { for (int i = 0; i < fields.length; i++) { toXml(out, fields[i]); } } out.writeEndElement(); // </reported> } private void toXml(XmppStreamWriter out, DataInstructions instructions) throws IOException, XMLStreamException { out.writeStartElement("instructions"); if (instructions.getValue() != null) out.writeCharacters(instructions.getValue()); out.writeEndElement(); // </instructions> } /** Deserializes the object from XML */ public Serializable fromXml(XmppStreamReader in) throws IOException, XMLStreamException { boolean isFinest = log.isLoggable(Level.FINEST); String type = in.getAttributeValue(null, "type"); DataForm form = new DataForm(type); ArrayList<DataField> fieldList = new ArrayList<DataField>(); ArrayList<DataItem> itemList = new ArrayList<DataItem>(); ArrayList<DataInstructions> instructionsList = new ArrayList<DataInstructions>(); int tag = in.nextTag(); while (tag > 0) { if (isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { form.setFieldList(fieldList); form.setItemList(itemList); form.setInstructionsList(instructionsList); return form; } if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) { fieldList.add(parseField(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "item".equals(in.getLocalName())) { itemList.add(parseItem(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "reported".equals(in.getLocalName())) { form.setReported(parseReported(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "title".equals(in.getLocalName())) { String title = in.getElementText(); form.setTitle(title); skipToEnd(in, "title"); } else if (XMLStreamReader.START_ELEMENT == tag && "instructions".equals(in.getLocalName())) { String value = in.getElementText(); instructionsList.add(new DataInstructions(value)); skipToEnd(in, "instructions"); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } return null; } /** Deserializes the object from XML */ public DataField parseField(XMLStreamReader in) throws IOException, XMLStreamException { String label = in.getAttributeValue(null, "label"); String type = in.getAttributeValue(null, "type"); String var = in.getAttributeValue(null, "var"); DataField field = new DataField(type, var, label); ArrayList<DataValue> valueList = new ArrayList<DataValue>(); ArrayList<DataOption> optionList = new ArrayList<DataOption>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { field.setValueList(valueList); field.setOptionList(optionList); return field; } if (XMLStreamReader.START_ELEMENT == tag && "desc".equals(in.getLocalName())) { String desc = in.getElementText(); field.setDesc(desc); skipToEnd(in, "desc"); } else if (XMLStreamReader.START_ELEMENT == tag && "option".equals(in.getLocalName())) { optionList.add(parseOption(in)); } else if (XMLStreamReader.START_ELEMENT == tag && "required".equals(in.getLocalName())) { field.setRequired(true); skipToEnd(in, "required"); } else if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) { String value = in.getElementText(); valueList.add(new DataValue(value)); skipToEnd(in, "value"); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "field"); return field; } /** Deserializes the object from XML */ public DataItem parseItem(XMLStreamReader in) throws IOException, XMLStreamException { DataItem item = new DataItem(); ArrayList<DataField> fieldList = new ArrayList<DataField>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { item.setFieldList(fieldList); return item; } if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) { fieldList.add(parseField(in)); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "item"); return item; } /** Deserializes the object from XML */ public DataReported parseReported(XMLStreamReader in) throws IOException, XMLStreamException { DataReported reported = new DataReported(); ArrayList<DataField> fieldList = new ArrayList<DataField>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { reported.setFieldList(fieldList); return reported; } if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) { fieldList.add(parseField(in)); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "reported"); return reported; } /** Deserializes the object from XML */ public DataOption parseOption(XMLStreamReader in) throws IOException, XMLStreamException { String label = in.getAttributeValue(null, "label"); DataOption option = new DataOption(label); ArrayList<DataValue> valueList = new ArrayList<DataValue>(); int tag = in.nextTag(); while (tag > 0) { if (_isFinest) debug(in); if (XMLStreamReader.END_ELEMENT == tag) { option.setValueList(valueList); return option; } if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) { String value = in.getElementText(); valueList.add(new DataValue(value)); skipToEnd(in, "value"); } else if (XMLStreamReader.START_ELEMENT == tag) { log.finer(this + " <" + in.getLocalName() + "> is an unknown tag"); skipToEnd(in, in.getLocalName()); } tag = in.nextTag(); } skipToEnd(in, "option"); return option; } }