Esempio n. 1
0
  private FxNode processEventHandlerAttribute(String event, String content) {
    EventHandler eh;

    if (content != null && content.startsWith(EVENT_HANDLER_METHOD_PREFIX)) {
      eh = accessor.asMethodRef(accessor.createEventHandler(event));
      accessor.addContent(eh, content.substring(1));

    } else {
      eh = accessor.createEventHandler(event);
      if (content != null && content.length() > 0) {
        accessor.addContent(eh, content);
      }
    }
    return eh;
  }
Esempio n. 2
0
 private FxNode handleEventContent(CharSequence content) {
   EventHandler eh = (EventHandler) nodeStack.peek();
   if (eh.isScript() && !eh.hasContent()) {
     if (content.length() == 0) {
       throw new UnsupportedOperationException();
     } else {
       if (content.charAt(0) == '#') {
         content = content.subSequence(1, content.length());
         eh = accessor.asMethodRef(eh);
       }
     }
   }
   accessor.addContent(eh, content);
   return eh;
 }
Esempio n. 3
0
 @NbBundle.Messages({
   "ERR_mixedContentNotAllowed=Mixed content is not allowed in property elements"
 })
 private FxNode handlePropertyContent(CharSequence seq) {
   FxNode node = nodeStack.peek();
   if (!(node instanceof PropertySetter)) {
     addError("unexpected-characters", ERR_unexpectedCharacters());
     return null;
   }
   // if the property has already received some bean instances, report
   // invalid content
   PropertySetter ps = (PropertySetter) node;
   if (ps.getValues() != null) {
     addError("mixed-content-not-allowed", ERR_mixedContentNotAllowed());
   }
   accessor.addContent((PropertySetter) node, seq);
   return node;
 }
Esempio n. 4
0
  private FxNode handleInstanceContent(CharSequence seq) {
    // find among properties as setter, which is marked as implicit. If there's none, create one.
    PropertySetter defaultSetter = null;

    for (PropertyValue p : current.getProperties()) {
      if (p instanceof PropertySetter) {
        PropertySetter ps = (PropertySetter) p;
        if (ps.isImplicit()) {
          defaultSetter = ps;
        }
      }
    }

    if (defaultSetter == null) {
      defaultSetter = accessor.createProperty(null, true);
      i(defaultSetter).startAt(contentLocator.getElementOffset());
      attachProperty(defaultSetter);
      attachChildNode(defaultSetter);
    }
    accessor.addContent(defaultSetter, seq);
    return defaultSetter;
  }
Esempio n. 5
0
  @NbBundle.Messages({
    "# {0} - attribute name",
    "ERR_lowercasePropertyName=Invalid property name: {0}. Property name, or the last component of a static property name must start with lowercase.",
    "# {0} - attribute name",
    "ERR_invalidReservedPropertyName=Unknown name in FXML reserved namespace: {0}",
    "# {0} - attribute qname",
    "# {1} - tag name",
    "ERR_unsupportedAttribute=Unsupported attribute {0} on {1}"
  })
  private void processInstanceAttributes(Attributes atts) {
    for (int i = 0; i < atts.getLength(); i++) {
      String uri = atts.getURI(i);
      String name = atts.getLocalName(i);
      String qname = atts.getQName(i);

      PropertySetter ps = null;

      FxNode node;

      if (qname.startsWith("xmlns")) { // NOI18N
        // FIXME - xmlns attributes will be represented as FxNodes :-/
        continue;
      }

      if (FXML_FX_NAMESPACE.equals(uri)) {
        if (!(FX_ID.equals(name)
            || FX_CONTROLLER.equals(name)
            || FX_VALUE.equals(name)
            || FX_FACTORY.contains(name))) {
          addAttributeError(
              qname,
              "error-unsupported-attribute",
              ERR_unsupportedAttribute(qname, tagName),
              qname,
              tagName);
        }
        continue;
      }

      if (current instanceof FxInstanceCopy) {
        if (FxXmlSymbols.FX_ATTR_REFERENCE_SOURCE.equals(name) && uri == null) {
          // ignore source in fx:copy
          continue;
        }
      }

      // if the name begins with "on", it's an event handler.
      if (name.startsWith(EVENT_HANDLER_PREFIX) && name.length() > EVENT_HANDLER_PREFIX_LEN) {
        String en =
            Character.toLowerCase(name.charAt(EVENT_HANDLER_PREFIX_LEN))
                + name.substring(EVENT_HANDLER_PREFIX_LEN + 1);
        node = processEventHandlerAttribute(en, atts.getValue(i));
        // special hack for fx:copy or fx:reference
      } else {
        // FIXME - error detection for static property
        int stProp = FxXmlSymbols.findStaticProperty(name);
        if (stProp == -2) {
          // report error, not a well formed property name.
          addAttributeError(qname, "invalid-property-name", ERR_lowercasePropertyName(name), name);
          node = accessor.makeBroken(accessor.createProperty(name, false));
        } else if (stProp == -1) {
          // this is a normal property
          node = ps = accessor.createProperty(name, false);
        } else {
          // it is a static property
          node =
              ps =
                  accessor.createStaticProperty(
                      name.substring(stProp + 1), name.substring(0, stProp));
        }
        if (ps != null) {
          accessor.addContent(ps, atts.getValue(i));
          node = ps;
        }
      }
      initAttribute(node, qname);
      attachProperty(ps);
      attachChildNode(node);
    }
  }