private <T> RequestMatcher existMatcher(RequestExtractor<T> extractor, TextContainer container) {
    if ("true".equals(container.getText())) {
      return exist(extractor);
    }

    if ("false".equals(container.getText())) {
      return not(exist(extractor));
    }

    throw new RuntimeException(String.format("Unknown exist parameter: [%s]", container.getText()));
  }
  private RequestMatcher createSingleTextMatcher(String name, TextContainer container) {
    if (container.isRawText()) {
      return createSingleMatcher(name, container.getText());
    }

    if ("exist".equals(container.getOperation())) {
      return existMatcher(Extractors.extractor(name), container);
    }

    return createRequestMatcherWithResource(
        container.getOperation(), createResource(name, container.getText()));
  }
  @Override
  public void startElement(
      String uri,
      String localName,
      String qName,
      Attributes attributes,
      QuestionnaireHandler handler)
      throws SAXException {

    TextContainer t = new TextContainer();
    t.setID(attributes.getValue("", "id"));
    texts.put(localName, t);
    handler.pushNode(t);
  }
  private ResponseHandler createResponseHandler(
      Map.Entry<String, TextContainer> pair, String targetMethodName) {
    TextContainer container = pair.getValue();
    try {
      if (container.isForTemplate()) {
        Method method = Moco.class.getMethod(targetMethodName, String.class, Resource.class);
        return (ResponseHandler) method.invoke(null, pair.getKey(), template(container.getText()));
      }

      Method method = Moco.class.getMethod(targetMethodName, String.class, String.class);
      return (ResponseHandler) method.invoke(null, pair.getKey(), container.getText());
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
  private <T> RequestMatcher getRequestMatcher(
      RequestExtractor<T> extractor, TextContainer container) {
    if (container.isRawText()) {
      return eq(extractor, container.getText());
    }

    if ("exist".equals(container.getOperation())) {
      return existMatcher(extractor, container);
    }

    try {
      Method operationMethod =
          Moco.class.getMethod(container.getOperation(), RequestExtractor.class, String.class);
      Object result = operationMethod.invoke(null, extractor, container.getText());
      return RequestMatcher.class.cast(result);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
Exemple #6
0
  /**
   * Translate this element and all contained elements into SAX events. The events should be routed
   * to the contentHandler found in the WingContext.
   *
   * @param contentHandler (Required) The registered contentHandler where SAX events should be
   *     routed too.
   * @param lexicalHandler (Required) The registered lexicalHandler where lexical events (such as
   *     CDATA, DTD, etc) should be routed too.
   * @param namespaces (Required) SAX Helper class to keep track of namespaces able to determine the
   *     correct prefix for a given namespace URI.
   */
  public void toSAX(
      ContentHandler contentHandler, LexicalHandler lexicalHandler, NamespaceSupport namespaces)
      throws SAXException {
    AttributeMap attributes = new AttributeMap();
    attributes.put(A_RETURN_VALUE, this.returnValue);

    startElement(contentHandler, namespaces, E_OPTION, attributes);
    super.toSAX(contentHandler, lexicalHandler, namespaces);
    endElement(contentHandler, namespaces, E_OPTION);
  }
Exemple #7
0
  /**
   * Translate into SAX events.
   *
   * @param contentHandler (Required) The registered contentHandler where SAX events should be
   *     routed too.
   * @param lexicalHandler (Required) The registered lexicalHandler where lexical events (such as
   *     CDATA, DTD, etc) should be routed too.
   * @param namespaces (Required) SAX Helper class to keep track of namespaces able to determine the
   *     correct prefix for a given namespace URI.
   */
  public void toSAX(
      ContentHandler contentHandler, LexicalHandler lexicalHandler, NamespaceSupport namespaces)
      throws SAXException {
    AttributeMap attributes = new AttributeMap();
    if (this.target != null) attributes.put(A_TARGET, target);
    if (this.rend != null) attributes.put(A_RENDER, rend);

    startElement(contentHandler, namespaces, E_TRAIL, attributes);
    super.toSAX(contentHandler, lexicalHandler, namespaces);
    endElement(contentHandler, namespaces, E_TRAIL);
  }
  private Resource resourceFrom(String name, TextContainer container) {
    if (container.isRawText()) {
      return invokeTarget(name, container.getText(), Resource.class);
    }

    if (container.isForTemplate()) {
      if ("version".equalsIgnoreCase(name)) {
        return version(template(container.getText()));
      }

      if (container.hasProperties()) {
        return template(
            invokeTarget(name, container.getText(), ContentResource.class), container.getProps());
      }

      return template(invokeTarget(name, container.getText(), ContentResource.class));
    }

    throw new IllegalArgumentException(format("unknown operation [%s]", container.getOperation()));
  }
Exemple #9
0
 public Font getFont() {
   // TODO MDM This is inefficient... should cache value
   return Fonts.fromStyle(container.getStyle());
 }
Exemple #10
0
 public boolean hasFocus() {
   return container.hasFocus();
 }
Exemple #11
0
 public HorizontalAlignmentValue getHorizontalAlignment() {
   return container.getStyle().getCompiledHorizontalAlignment();
 }
Exemple #12
0
 public VerticalAlignmentValue getVerticalAlignment() {
   return container.getStyle().getCompiledVerticalAlignment();
 }
Exemple #13
0
 /** dispose() */
 public void dispose() {
   super.dispose();
 }