コード例 #1
0
 @Override
 protected final void startElement(Attributes attrs) {
   children = declareChildren();
   if (children != null) {
     for (ElementHandler child : children.values()) {
       child.setParent(this);
     }
   }
   startSelf(attrs);
 }
コード例 #2
0
ファイル: ParserContext.java プロジェクト: eabrand/windup
  @SuppressWarnings({"rawtypes", "unchecked"})
  public ParserContext(ConfigurationBuilder builder) {
    List<ElementHandler> loadedHandlers =
        Iterators.asList(ServiceLoader.load(ElementHandler.class));
    for (ElementHandler handler : loadedHandlers) {
      NamespaceElementHandler annotation =
          Annotations.getAnnotation(handler.getClass(), NamespaceElementHandler.class);
      if (annotation != null) {
        handlers.put(new HandlerId(annotation.namespace(), annotation.elementName()), handler);
      }
    }

    this.builder = builder;
  }
コード例 #3
0
ファイル: ParserContext.java プロジェクト: eabrand/windup
 @SuppressWarnings("unchecked")
 public <T> T processElement(Element element) throws ConfigurationException {
   String namespace = $(element).namespaceURI();
   String tagName = $(element).tag();
   ElementHandler<?> handler = handlers.get(new HandlerId(namespace, tagName));
   if (handler != null) {
     Object o = handler.processElement(this, element);
     return (T) o;
   }
   throw new ConfigurationException(
       "No Handler registered for element named ["
           + tagName
           + "] in namespace: ["
           + namespace
           + "]");
 }
コード例 #4
0
ファイル: VarElementHandler.java プロジェクト: ronshapiro/j86
 /**
  * Parses attributes of the element. The following attributes are supported:
  *
  * <dl>
  *   <dt>idref
  *   <dd>the identifier to refer to the variable
  *   <dt>id
  *   <dd>the identifier of the variable that is intended to store the result
  * </dl>
  *
  * @param name the attribute name
  * @param value the attribute value
  */
 @Override
 public void addAttribute(String name, String value) {
   if (name.equals("idref")) { // NON-NLS: the attribute name
     this.value = ValueObjectImpl.create(getVariable(value));
   } else {
     super.addAttribute(name, value);
   }
 }
コード例 #5
0
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes)
      throws SAXException {
    String elem = localName;
    if (elem.isEmpty()) {
      elem = qName;
    }
    elemStack.addFirst(elem);

    ElementHandler contextHandler = handlerStack.getFirst();
    ElementHandler elemHandler = contextHandler.getHandler(elem);
    if (elemHandler == null) {
      throw new IllegalStateException(
          String.format(
              "Context handler %s have not returned handler for elem %s",
              contextHandler, elemStack));
    }
    handlerStack.addFirst(elemHandler);
    elemHandler.startElement(attributes);
  }
コード例 #6
0
ファイル: XMLUtil.java プロジェクト: eclipse/cdo
  public static int handleElements(NodeList nodeList, ElementHandler handler) throws Exception {
    int count = 0;
    for (int i = 0; i < nodeList.getLength(); i++) {
      Node node = nodeList.item(i);
      if (node instanceof Element) {
        Element element = (Element) node;
        handler.handleElement(element);
        ++count;
      }
    }

    return count;
  }
コード例 #7
0
  @Override
  public void endElement(String uri, String localName, String qName) throws SAXException {
    String elem = localName;
    if (elem.isEmpty()) {
      elem = qName;
    }
    // check doc structure sanity
    if (!elemStack.getFirst().equals(elem)) {
      throw new IllegalStateException(
          String.format("Elem ending expected: %s, but was: %s", elemStack.getFirst(), elem));
    }

    ElementHandler elemHandler = handlerStack.removeFirst();
    if (sb != null) {
      String txt = sb.toString();
      // !
      txt.trim();
      elemHandler.characters(txt);
      sb = null;
    }
    elemHandler.endElement();

    elemStack.removeFirst();
  }