Esempio n. 1
0
  /**
   * Ends processing of the current element.
   *
   * @param uri The uri.
   * @param localName The localName.
   * @param qName The qName.
   */
  @Override
  public void endElement(String uri, String localName, String qName) {
    // Tell the currently active element processor to complete its processing.
    elementProcessor.end();

    // Set the active element processor to the parent of the existing processor.
    elementProcessor = elementProcessor.getParent();
  }
Esempio n. 2
0
 /** {@inheritDoc} */
 public void process(ZipInputStream zip) throws DocumentException {
   Node context = getContext(zip);
   try {
     Element[] elements = getElements(context, "/document/body/*");
     document = new Document();
     for (Element element : elements) {
       ElementProcessor processor = processors.get(element.getNodeName());
       if (processor != null) {
         processor.process(element);
       }
     }
   } catch (XmlException e) {
     throw new DocumentException(e);
   }
 }
  public JCodeModel process(AnnotationElements validatedModel) throws Exception {

    JCodeModel codeModel = new JCodeModel();

    EBeansHolder eBeansHolder = new EBeansHolder(codeModel);
    for (ElementProcessor processor : processors) {
      Class<? extends Annotation> target = processor.getTarget();

      Set<? extends Element> annotatedElements = validatedModel.getAnnotatedElements(target);

      for (Element annotatedElement : annotatedElements) {
        processor.process(annotatedElement, codeModel, eBeansHolder);
      }
    }

    return codeModel;
  }
 @Override
 public boolean process(@NotNull GoNamedElement element) {
   ProgressManager.checkCanceled();
   Boolean allowed = null;
   ExistingImportData importData = null;
   for (ElementProcessor processor : myProcessors) {
     if (processor.isMine(myName, element)) {
       importData = cachedImportData(element, importData);
       allowed = cachedAllowed(element, allowed);
       if (allowed == Boolean.FALSE || importData.isDot) break;
       if (!processor.process(myName, element, importData, myResult)) {
         return false;
       }
     }
   }
   return true;
 }
Esempio n. 5
0
  /**
   * Begins processing of a new element.
   *
   * @param uri The uri.
   * @param localName The localName.
   * @param qName The qName.
   * @param attributes The attributes.
   */
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) {
    // Get the appropriate element processor for the element.
    if (elementProcessor != null) {
      // We already have an active element processor, therefore use the
      // active element processor to retrieve the appropriate child
      // element processor.
      elementProcessor = elementProcessor.getChild(uri, localName, qName);
    } else if (ELEMENT_NAME_OSM.equals(qName)) {
      // There is no active element processor which means we have
      // encountered the root osm element.
      elementProcessor = osmElementProcessor;
    } else {
      // There is no active element processor which means that this is a
      // root element. The root element in this case does not match the
      // expected name.
      throw new OsmRuntimeException("This does not appear to be an OSM XML file.");
    }

    // Initialise the element processor with the attributes of the new element.
    elementProcessor.begin(attributes);
  }
 private void runProcessor() {
   final XmlPullParser parser = this.parser;
   final ElementProcessor p = getCurrentDescriptor().createProcessor(),
       last = getCurrentElementProcessor();
   p.setContext(last == null ? getContext() : last.childContext());
   p.setDepth(parser.getDepth());
   p.processAttributes(parser);
   processors.addLast(p);
 }
Esempio n. 7
0
 public void process(ElementProcessor p) {
   p.process(this);
 }
  @Override
  public void handleResponse() throws RequestMethodException {
    try {
      initializeRoot();
      final XmlPullParser parser = this.parser;
      final StringBuilder currentText = this.currentText;
      int type = parser.next();
      Descriptor<?> currentDescriptor = null;
      while (type != END_DOCUMENT) {
        currentDescriptor = getCurrentDescriptor();
        if (DEBUG) {
          Log.d(
              TAG,
              "lastTag=<"
                  + lastTag
                  + ">, "
                  + currentText
                  + ", "
                  + currentDescriptor
                  + ", type "
                  + type);
        }

        switch (type) {
          case START_TAG:
            if (currentText.length() > 0) {
              currentText.delete(0, currentText.length());
            }
            final String name = parser.getName().trim();
            lastTag = name;
            final Descriptor<?> d = currentDescriptor.getChildDescriptors().get(name);
            if (d != null) {
              descriptors.addLast(d);
              runProcessor();
              if (DEBUG) {
                Log.d(TAG, "Run processor for " + name);
              }
            }
            break;

          case TEXT:
            currentText.append(parser.getText());
            break;

          case END_TAG:
            final ElementProcessor p = getCurrentElementProcessor();
            if (p == null) {
              // throw new IllegalStateException("Cannot end tag. " + dumpState());
              Log.e(TAG, "Cannot end tag " + parser.getName() + " / " + dumpState());
              break;
            }
            if (parser.getDepth() > p.getDepth()) { // set a value
              if (lastTag == null) {
                throw new IllegalStateException("Cannot set value. " + dumpState());
              }
              if (lastTag.equals(parser.getName())) {
                final String value = currentText.toString().trim();
                final boolean done = p.processValue(lastTag, value);
                final SimpleResultHandler h = getContext().getSimpleResultHandler();
                if (!done && h != null) {
                  h.handleValue(lastTag, value);
                }
              }
            } else { // return to the parent processor
              stopProcessor();
              if (DEBUG) {
                Log.d(TAG, "Stop processor for " + parser.getName());
              }
              descriptors.removeLast();
            }
            break;

          default:
        }
        type = parser.next();
      }
      if (currentText.length() > 0) {
        currentText.delete(0, currentText.length());
      }
    } catch (final XmlPullParserException e) {
      throw new RequestMethodException(e, this);
    } catch (final IOException e) {
      throw new RequestMethodException(e);
    }
  }