コード例 #1
0
  /**
   * Processes ?include directive
   *
   * @param include
   */
  @NbBundle.Messages({
    "ERR_missingIncludeName=Missing include name",
    "# {0} - attribute name",
    "ERR_unexpectedIncludeAttribute=Unexpected attribute in fx:include: {0}"
  })
  private FxNode handleFxInclude(Attributes atts, String localName) {
    String include = null;

    for (int i = 0; i < atts.getLength(); i++) {
      String attName = atts.getLocalName(i);
      if (FX_ATTR_REFERENCE_SOURCE.equals(attName)) {
        include = atts.getValue(i);
      } else {
        String qName = atts.getQName(i);
        addAttributeError(
            qName, "unexpected-include-attribute", ERR_unexpectedIncludeAttribute(qName), qName);
      }
    }
    if (include == null) {
      // must be some text, otherwise = error
      addAttributeError(
          ContentLocator.ATTRIBUTE_TARGET, "missing-included-name", ERR_missingIncludeName());

      FxNode n = accessor.createErrorElement(localName);
      initElement(n);
      addError("invalid-fx-element", ERR_invalidFxElement(localName), localName);
      return n;
    }
    // guide: fnames starting with slash are treated relative to the classpath
    FxInclude fxInclude = accessor.createInclude(include);
    return fxInclude;
  }
コード例 #2
0
  @NbBundle.Messages({
    "# {0} - attribute local name",
    "ERR_unexpectedReferenceAttribute=Unexpected attribute in fx:reference or fx:copy: {0}",
    "ERR_missingReferenceSource=Missing 'source' attribute in fx:reference or fx:copy"
  })
  private FxNode handleFxReference(Attributes atts, boolean copy) {
    String refId = null;
    String id = null;

    for (int i = 0; i < atts.getLength(); i++) {
      String ns = atts.getURI(i);
      String name = atts.getLocalName(i);
      if (!FXML_FX_NAMESPACE.equals(ns)) {
        if (FX_ATTR_REFERENCE_SOURCE.equals(name) && refId == null) {
          refId = atts.getValue(i);
        } else if (!copy) {
          // error, references do not support normal attributes
          addAttributeError(
              atts.getQName(i),
              "invalid-reference-attribute",
              ERR_unexpectedReferenceAttribute(name),
              name);
        }
      } else {
        if (FX_ID.equals(name) && id == null) {
          id = atts.getValue(i);
        } else {
          // error, unexpected attribute
          addAttributeError(
              atts.getQName(i),
              "invalid-reference-attribute",
              ERR_unexpectedReferenceAttribute(name),
              name);
        }
      }
    }

    FxObjectBase ref = accessor.createCopyReference(copy, refId);
    if (refId == null || "".equals(refId)) {
      // error, no source attribute found
      addError("missing-reference-source", ERR_missingReferenceSource());
      accessor.makeBroken(ref);
    }
    return ref;
  }