/** Deserializes the object from XML */
  public DataReported parseReported(XMLStreamReader in) throws IOException, XMLStreamException {
    DataReported reported = new DataReported();

    ArrayList<DataField> fieldList = new ArrayList<DataField>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        reported.setFieldList(fieldList);

        return reported;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "reported");

    return reported;
  }
  @Override
  public boolean login(boolean isFail) {
    try {
      WebApp webApp = getWebApp();

      if (webApp == null) {
        if (log.isLoggable(Level.FINE)) log.finer("authentication failed, no web-app found");

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      }

      // If the authenticator can find the user, return it.
      Login login = webApp.getLogin();

      if (login != null) {
        Principal user = login.login(this, getResponse(), isFail);

        return user != null;
        /*
        if (user == null)
          return false;

        setAttribute(AbstractLogin.LOGIN_NAME, user);

        return true;
        */
      } else if (isFail) {
        if (log.isLoggable(Level.FINE))
          log.finer("authentication failed, no login module found for " + webApp);

        getResponse().sendError(HttpServletResponse.SC_FORBIDDEN);

        return false;
      } else {
        // if a non-failure, then missing login is fine

        return false;
      }
    } catch (IOException e) {
      log.log(Level.FINE, e.toString(), e);

      return false;
    }
  }
  /** Deserializes the object from XML */
  public DataField parseField(XMLStreamReader in) throws IOException, XMLStreamException {
    String label = in.getAttributeValue(null, "label");
    String type = in.getAttributeValue(null, "type");
    String var = in.getAttributeValue(null, "var");

    DataField field = new DataField(type, var, label);

    ArrayList<DataValue> valueList = new ArrayList<DataValue>();
    ArrayList<DataOption> optionList = new ArrayList<DataOption>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        field.setValueList(valueList);
        field.setOptionList(optionList);

        return field;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "desc".equals(in.getLocalName())) {
        String desc = in.getElementText();

        field.setDesc(desc);

        skipToEnd(in, "desc");
      } else if (XMLStreamReader.START_ELEMENT == tag && "option".equals(in.getLocalName())) {
        optionList.add(parseOption(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "required".equals(in.getLocalName())) {
        field.setRequired(true);

        skipToEnd(in, "required");
      } else if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) {
        String value = in.getElementText();

        valueList.add(new DataValue(value));

        skipToEnd(in, "value");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "field");

    return field;
  }
  /** Deserializes the object from XML */
  public Serializable fromXml(XmppStreamReader in) throws IOException, XMLStreamException {
    boolean isFinest = log.isLoggable(Level.FINEST);

    String type = in.getAttributeValue(null, "type");

    DataForm form = new DataForm(type);

    ArrayList<DataField> fieldList = new ArrayList<DataField>();
    ArrayList<DataItem> itemList = new ArrayList<DataItem>();
    ArrayList<DataInstructions> instructionsList = new ArrayList<DataInstructions>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        form.setFieldList(fieldList);
        form.setItemList(itemList);
        form.setInstructionsList(instructionsList);

        return form;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "field".equals(in.getLocalName())) {
        fieldList.add(parseField(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "item".equals(in.getLocalName())) {
        itemList.add(parseItem(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "reported".equals(in.getLocalName())) {
        form.setReported(parseReported(in));
      } else if (XMLStreamReader.START_ELEMENT == tag && "title".equals(in.getLocalName())) {
        String title = in.getElementText();

        form.setTitle(title);

        skipToEnd(in, "title");
      } else if (XMLStreamReader.START_ELEMENT == tag && "instructions".equals(in.getLocalName())) {
        String value = in.getElementText();

        instructionsList.add(new DataInstructions(value));

        skipToEnd(in, "instructions");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    return null;
  }
  /** Deserializes the object from XML */
  public DataOption parseOption(XMLStreamReader in) throws IOException, XMLStreamException {
    String label = in.getAttributeValue(null, "label");

    DataOption option = new DataOption(label);

    ArrayList<DataValue> valueList = new ArrayList<DataValue>();

    int tag = in.nextTag();
    while (tag > 0) {
      if (_isFinest) debug(in);

      if (XMLStreamReader.END_ELEMENT == tag) {
        option.setValueList(valueList);

        return option;
      }

      if (XMLStreamReader.START_ELEMENT == tag && "value".equals(in.getLocalName())) {
        String value = in.getElementText();

        valueList.add(new DataValue(value));

        skipToEnd(in, "value");
      } else if (XMLStreamReader.START_ELEMENT == tag) {
        log.finer(this + " <" + in.getLocalName() + "> is an unknown tag");

        skipToEnd(in, in.getLocalName());
      }

      tag = in.nextTag();
    }

    skipToEnd(in, "option");

    return option;
  }
示例#6
0
  public String readAsXmlString() throws IOException, XMLStreamException {
    StringBuilder sb = new StringBuilder();
    int depth = 0;

    while (true) {
      if (XMLStreamReader.START_ELEMENT == getEventType()) {
        depth++;

        String prefix = getPrefix();

        sb.append("<");

        if (!"".equals(prefix)) {
          sb.append(prefix);
          sb.append(":");
        }

        sb.append(getLocalName());

        if (getNamespaceURI() != null) {
          if ("".equals(prefix)) sb.append(" xmlns");
          else sb.append(" xmlns:").append(prefix);

          sb.append("=\"");
          sb.append(getNamespaceURI()).append("\"");
        }

        for (int i = 0; i < getAttributeCount(); i++) {
          sb.append(" ");
          sb.append(getAttributeLocalName(i));
          sb.append("=\"");
          sb.append(getAttributeValue(i));
          sb.append("\"");
        }
        sb.append(">");

        log.finest(this + " " + sb);
      } else if (XMLStreamReader.END_ELEMENT == getEventType()) {
        depth--;

        sb.append("</");

        String prefix = getPrefix();
        if (!"".equals(prefix)) sb.append(prefix).append(":");

        sb.append(getLocalName());
        sb.append(">");

        if (depth == 0) return sb.toString();
      } else if (XMLStreamReader.CHARACTERS == getEventType()) {
        sb.append(getText());
      } else {
        log.finer(this + " tag=" + getEventType());

        return sb.toString();
      }

      if (next() < 0) {
        log.finer(this + " unexpected end of file");

        return sb.toString();
      }
    }
  }