@NbBundle.Messages({ "# {0} - NS prefix", "ERR_undeclaredElementPrefix=XML namespace prefix ''{0}'' is undeclared" }) @Override public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { this.tagName = localName; FxNode newElement; start = contentLocator.getElementOffset(); end = contentLocator.getEndOffset(); addElementErrors(); if (uri == null && !qName.equals(localName)) { // undeclared prefix int prefColon = qName.indexOf(':'); String prefix = qName.substring(0, prefColon); addError("undeclared-prefix", ERR_undeclaredElementPrefix(prefix)); newElement = accessor.createErrorElement(localName); } else if ("".equals(localName)) { newElement = accessor.createErrorElement(localName); } else if (FXML_FX_NAMESPACE.equals(uri)) { newElement = handleFxmlElement(localName, atts); } else { // non-fx namespace, should be either an instance, or a property or an event String eventName = FxXmlSymbols.getEventHandlerName(localName); if (rootComponent == null || FxXmlSymbols.isClassTagName(localName)) { newElement = handleClassTag(localName, atts); } else if (eventName != null) { newElement = handleEventHandlerTag(eventName); } else { newElement = handlePropertyTag(localName, atts); } } if (newElement == null) { throw new IllegalStateException(); } initElement(newElement); FxNode newNode = newElement; // if not broken attempt to attach the Element to a parent if (!newElement.isBroken()) { if (newElement instanceof FxObjectBase) { newNode = attachInstance((FxObjectBase) newElement); } else if (newElement instanceof PropertyValue) { newNode = attachProperty((PropertyValue) newElement); } } attachChildNode(newNode); // process attributes, iff it is an instance. Attribute processing needs the node pushed // on the stack, so it is delayed after attachChildNode if (newNode.getKind() == Kind.Instance) { processInstanceAttributes(atts); } }
/** * 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; }
@NbBundle.Messages({ "# {0} - tag name", "ERR_invalidFxElement=Unknown element in fx: namespace: {0}", "ERR_duplicateDefinitions=Duplicate 'definitions' element" }) private FxNode handleFxmlElement(String localName, Attributes atts) { if (FX_DEFINITIONS.equals(localName)) { definitions++; if (definitionsFound) { // error, defs cannot be nested or used more than once. Ignore. addError("duplicate-definitions", ERR_duplicateDefinitions()); } FxNode n = accessor.createElement(localName); definitionsNode = accessor.i(n); return n; } else if (FX_COPY.equals(localName)) { return handleFxReference(atts, true); } else if (FX_REFERENCE.equals(localName)) { return handleFxReference(atts, false); } else if (FX_INCLUDE.equals(localName)) { return handleFxInclude(atts, localName); } else { // error, invalid fx: element FxNode n = accessor.createErrorElement(localName); initElement(n); addError("invalid-fx-element", ERR_invalidFxElement(localName), localName); return n; } }