@Override
  public void handleControlStart(
      String uri,
      String localname,
      String qName,
      Attributes attributes,
      String staticId,
      final String effectiveId,
      XFormsSingleNodeControl xformsControl)
      throws SAXException {

    final String groupElementName = getContainingElementName();
    final String xhtmlPrefix = handlerContext.findXHTMLPrefix();
    final String groupElementQName = XMLUtils.buildQName(xhtmlPrefix, groupElementName);

    final ElementHandlerController controller = handlerContext.getController();

    // Get classes
    // TODO: should use getContainerAttributes() instead?
    final StringBuilder classes = getInitialClasses(uri, localname, attributes, null);
    handleMIPClasses(classes, getPrefixedId(), xformsControl);

    final ContentHandler contentHandler = controller.getOutput();

    // Start xhtml:fieldset element if needed
    if (!handlerContext.isNewXHTMLLayout())
      contentHandler.startElement(
          XMLConstants.XHTML_NAMESPACE_URI,
          groupElementName,
          groupElementQName,
          getAttributes(attributes, classes.toString(), effectiveId));

    // Output an xhtml:legend element if and only if there is an xforms:label element. This help
    // with
    // styling in particular.
    final boolean hasLabel = XFormsControl.hasLabel(containingDocument, getPrefixedId());
    if (hasLabel) {

      // Handle label classes
      reusableAttributes.clear();
      reusableAttributes.addAttribute(
          "", "class", "class", ContentHandlerHelper.CDATA, getLabelClasses(xformsControl));
      // The id should never be need on <legend>
      //            reusableAttributes.addAttribute("", "id", "id", ContentHandlerHelper.CDATA,
      // getLHHACId(effectiveId, LHHAC_CODES.get(LHHAC.LABEL)));

      // Output xhtml:legend with label content
      final String legendQName = XMLUtils.buildQName(xhtmlPrefix, "legend");
      contentHandler.startElement(
          XMLConstants.XHTML_NAMESPACE_URI, "legend", legendQName, reusableAttributes);
      {
        final String labelValue = getLabelValue(xformsControl);
        if (StringUtils.isNotEmpty(labelValue))
          contentHandler.characters(labelValue.toCharArray(), 0, labelValue.length());
      }
      contentHandler.endElement(XMLConstants.XHTML_NAMESPACE_URI, "legend", legendQName);
    }
  }
예제 #2
0
  public void execute(
      XFormsActionInterpreter actionInterpreter,
      Element actionElement,
      Scope actionScope,
      boolean hasOverriddenContext,
      Item overriddenContext) {

    final XFormsContainingDocument containingDocument = actionInterpreter.containingDocument();

    // Resolve all attributes as AVTs
    final String dialogStaticOrEffectiveId = actionInterpreter.resolveAVT(actionElement, "dialog");
    final String neighborEffectiveId;
    {
      final String neighborStaticOrEffectiveId =
          actionInterpreter.resolveAVT(actionElement, "neighbor");
      final XFormsControl neighbor =
          (XFormsControl)
              ((neighborStaticOrEffectiveId != null)
                  ? actionInterpreter.resolveOrFindByEffectiveId(
                      actionElement, neighborStaticOrEffectiveId)
                  : null);
      neighborEffectiveId = (neighbor != null) ? neighbor.getEffectiveId() : null;
    }
    final boolean constrainToViewport;
    {
      final String constrain = actionInterpreter.resolveAVT(actionElement, "constrain");
      constrainToViewport = !"false".equals(constrain);
    }

    if (dialogStaticOrEffectiveId != null) {
      // Dispatch xxforms-dialog-open event to dialog
      final Object controlObject =
          actionInterpreter.resolveOrFindByEffectiveId(actionElement, dialogStaticOrEffectiveId);
      if (controlObject instanceof XXFormsDialogControl) {
        final XXFormsDialogControl targetDialog = (XXFormsDialogControl) controlObject;

        // Remove focus if any
        containingDocument.setClientFocusEffectiveControlId(null);

        final XFormsEvent newEvent =
            new XXFormsDialogOpenEvent(
                containingDocument, targetDialog, neighborEffectiveId, constrainToViewport);
        addContextAttributes(actionInterpreter, actionElement, newEvent);
        targetDialog.getXBLContainer(containingDocument).dispatchEvent(newEvent);

        // Check if form author has set focus while dialog was opening, and if not focus on dialog
        final String currentFocusEffectiveId =
            containingDocument.getClientFocusControlEffectiveId();
        if (currentFocusEffectiveId == null && targetDialog.isVisible())
          targetDialog
              .getXBLContainer()
              .dispatchEvent(new XFormsFocusEvent(containingDocument, targetDialog));

      } else {
        final IndentedLogger indentedLogger = actionInterpreter.indentedLogger();
        if (indentedLogger.isDebugEnabled())
          indentedLogger.logDebug(
              "xxforms:show",
              "dialog does not refer to an existing xxforms:dialog element, ignoring action",
              "dialog id",
              dialogStaticOrEffectiveId);
      }
    }
  }