public static List<NameValuePair> parseForParameters(String stringResponse)
      throws JSONException, InvalidRequestException, InvalidClientException, InvalidGrantException,
          UnauthorizedClientException, UnsupportedGrantTypeException, InvalidScopeException,
          OAuthException {
    OAuthException exception = null;
    List<NameValuePair> parameterList = new ArrayList<NameValuePair>();
    String[] parameters = stringResponse.split("&");
    for (String parameter : parameters) {
      if (parameter.contains("?")) {
        parameterList.add(new BasicNameValuePair("redirectUri", parameter.split("?")[0]));
        parameter = parameter.split("?")[1];
      }
      if (parameter.contains("=")) {

        String[] pair = parameter.split("=");
        BasicNameValuePair basicNameValuePair = new BasicNameValuePair(pair[0], pair[1]);
        parameterList.add(basicNameValuePair);
        if (basicNameValuePair.getName().equalsIgnoreCase("error")) {
          exception = ErrorParser.getException(basicNameValuePair.getValue());
        }
      }
    }
    if (exception != null) {
      throw exception;
    }
    return parameterList;
  }
  @Override
  protected OAIPMHtype parseElement(XMLEventReader reader) throws ParseException {
    OAIPMHtype pmh = new OAIPMHtype();

    try {
      if (!reader.peek().asStartElement().getName().getLocalPart().equals(NAME))
        throw new ParseException("Expecting " + NAME + " element");

      reader.nextEvent();
      this.nextElement(reader);

      pmh.setResponseDate(
          super.getConfiguration().getFormatter().parse(this.getElement(reader, RESPONSE_DATE)));
      pmh.setRequest(reqParser.parse(reader));

      String name = reader.peek().asStartElement().getName().getLocalPart();

      if (name.equals("ListRecords")) pmh.setListRecords(listRecordsParser.parse(reader));
      else if (name.equals("GetRecord")) pmh.setGetRecord(getRecordParser.parse(reader));
      else if (name.equals("ListIdentifiers"))
        pmh.setListIdentifiers(listIdentifiersParser.parse(reader));
      else if (name.equals("ListSets")) pmh.setListSets(listSetsParser.parse(reader));
      else if (name.equals("ListMetadataFormats"))
        pmh.setListMetadataFormats(listMetadataFormatsParser.parse(reader));
      else if (name.equals("Identify")) pmh.setIdentify(identifyParser.parse(reader));
      else {
        while (reader.peek().asStartElement().getName().getLocalPart().equals("error")) {
          pmh.getError().add(errorParser.parse(reader));
        }
      }

    } catch (XMLStreamException e) {
      throw new ParseException(e);
    } catch (java.text.ParseException e) {
      throw new ParseException(e);
    }

    return pmh;
  }