Пример #1
0
  @Override
  protected void handleControlEnd(
      String uri,
      String localname,
      String qName,
      Attributes attributes,
      String staticId,
      String effectiveId,
      XFormsControl control)
      throws SAXException {

    handlerContext.popCaseContext();

    final ElementHandlerController controller = handlerContext.getController();
    if (!handlerContext.isNoScript()) {
      currentOutputInterceptor.flushCharacters(true, true);

      // Restore output
      controller.setOutput(currentSavedOutput);

      final boolean isMustGenerateBeginEndDelimiters =
          !handlerContext.isFullUpdateTopLevelControl(effectiveId);
      if (isMustGenerateBeginEndDelimiters) {
        if (currentOutputInterceptor.getDelimiterNamespaceURI() != null) {
          // Output end delimiter
          currentOutputInterceptor.outputDelimiter(
              currentSavedOutput,
              currentOutputInterceptor.getDelimiterNamespaceURI(),
              currentOutputInterceptor.getDelimiterPrefix(),
              currentOutputInterceptor.getDelimiterLocalName(),
              "xforms-case-begin-end",
              "xforms-case-end-" + XFormsUtils.namespaceId(containingDocument, effectiveId));
        } else {
          // Output start and end delimiter using xhtml:span
          final String xhtmlPrefix = handlerContext.findXHTMLPrefix();
          currentOutputInterceptor.outputDelimiter(
              currentSavedOutput,
              XMLConstants.XHTML_NAMESPACE_URI,
              xhtmlPrefix,
              "span",
              "xforms-case-begin-end",
              "xforms-case-begin-" + XFormsUtils.namespaceId(containingDocument, effectiveId));
          currentOutputInterceptor.outputDelimiter(
              currentSavedOutput,
              XMLConstants.XHTML_NAMESPACE_URI,
              xhtmlPrefix,
              "span",
              "xforms-case-begin-end",
              "xforms-case-end-" + XFormsUtils.namespaceId(containingDocument, effectiveId));
        }
      }
    } else if (!isVisible) {
      // Case not visible, restore output
      controller.setOutput(currentSavedOutput);
    }
  }
Пример #2
0
  @Override
  protected void handleControlStart(
      String uri,
      String localname,
      String qName,
      Attributes attributes,
      String staticId,
      final String effectiveId,
      XFormsControl control)
      throws SAXException {

    final String xhtmlPrefix = handlerContext.findXHTMLPrefix();
    final String spanQName = XMLUtils.buildQName(xhtmlPrefix, "span");

    // Determine whether this case is visible
    final XFormsCaseControl caseControl =
        (XFormsCaseControl) containingDocument.getControls().getObjectByEffectiveId(effectiveId);
    if (!handlerContext.isTemplate() && caseControl != null) {
      // This case is visible if it is selected or if the switch is read-only and we display
      // read-only as static
      isVisible = caseControl.isVisible();
    } else {
      isVisible = false;
    }

    final ElementHandlerController controller = handlerContext.getController();
    currentSavedOutput = controller.getOutput();

    // Place interceptor if needed
    if (!handlerContext.isNoScript()) {

      final boolean isMustGenerateBeginEndDelimiters =
          !handlerContext.isFullUpdateTopLevelControl(effectiveId);

      // Classes on top-level elements and characters and on the first delimiter
      final String elementClasses;
      {
        final StringBuilder classes = new StringBuilder();
        appendControlUserClasses(attributes, control, classes);
        // Don't add MIP classes as they can conflict with classes of nested content if used outside
        // <tr>, etc.
        elementClasses = classes.toString();
      }

      currentOutputInterceptor =
          new OutputInterceptor(
              currentSavedOutput,
              spanQName,
              new OutputInterceptor.Listener() {

                // Classes on first delimiter
                private final String firstDelimiterClasses;

                {
                  final StringBuilder classes = new StringBuilder("xforms-case-begin-end");
                  if (elementClasses.length() > 0) {
                    classes.append(' ');
                    classes.append(elementClasses);
                  }
                  firstDelimiterClasses = classes.toString();
                }

                public void generateFirstDelimiter(OutputInterceptor outputInterceptor)
                    throws SAXException {
                  if (isMustGenerateBeginEndDelimiters) {
                    // Delimiter: begin case
                    outputInterceptor.outputDelimiter(
                        currentSavedOutput,
                        outputInterceptor.getDelimiterNamespaceURI(),
                        outputInterceptor.getDelimiterPrefix(),
                        outputInterceptor.getDelimiterLocalName(),
                        firstDelimiterClasses,
                        "xforms-case-begin-"
                            + XFormsUtils.namespaceId(containingDocument, effectiveId));
                  }
                }
              });

      final String controlClasses;
      {
        final StringBuilder classes =
            new StringBuilder(isVisible ? "xforms-case-selected" : "xforms-case-deselected");
        if (elementClasses.length() > 0) {
          classes.append(' ');
          classes.append(elementClasses);
        }
        controlClasses = classes.toString();
      }

      currentOutputInterceptor.setAddedClasses(controlClasses);

      controller.setOutput(new DeferredXMLReceiverImpl(currentOutputInterceptor));
    } else if (!isVisible) {
      // Case not visible, set output to a black hole
      controller.setOutput(new DeferredXMLReceiverAdapter());
    }

    handlerContext.pushCaseContext(isVisible);
  }