Example #1
0
 /**
  * check if the specified XMLGregorianCalendar instance is a valid {@odf.datatype time} data type
  *
  * @param time the value to be tested
  * @return true if the value of argument is valid for {@odf.datatype time} data type false
  *     otherwise
  */
 public static boolean isValid(XMLGregorianCalendar time) {
   if (time == null) {
     return false;
   } else {
     return W3CSchemaType.isValid("time", time.toXMLFormat());
   }
 }
    private Element createUsernameToken(String usernameValue, String passwordValue)
        throws SOAPException {

      QName usernameTokenName =
          new QName(Constants.WSSE_NS, Constants.WSSE_USERNAME_TOKEN, Constants.WSSE_PREFIX);
      QName usernameName =
          new QName(Constants.WSSE_NS, Constants.WSSE_USERNAME, Constants.WSSE_PREFIX);
      QName passwordName =
          new QName(Constants.WSSE_NS, Constants.WSSE_PASSWORD, Constants.WSSE_PREFIX);
      QName createdName = new QName(Constants.WSU_NS, "Created", Constants.WSU_PREFIX);

      SOAPFactory factory = SOAPFactory.newInstance();
      SOAPElement usernametoken = factory.createElement(usernameTokenName);
      usernametoken.addNamespaceDeclaration(Constants.WSSE_PREFIX, Constants.WSSE_NS);
      usernametoken.addNamespaceDeclaration(Constants.WSU_PREFIX, Constants.WSU_NS);
      SOAPElement username = factory.createElement(usernameName);
      username.addTextNode(usernameValue);
      SOAPElement password = factory.createElement(passwordName);
      password.addAttribute(new QName("Type"), Constants.PASSWORD_TEXT_TYPE);
      password.addTextNode(passwordValue);

      SOAPElement created = factory.createElement(createdName);
      XMLGregorianCalendar createdCal =
          dataTypefactory.newXMLGregorianCalendar(new GregorianCalendar()).normalize();
      created.addTextNode(createdCal.toXMLFormat());

      usernametoken.addChildElement(username);
      usernametoken.addChildElement(password);
      usernametoken.addChildElement(created);
      return usernametoken;
    }
  @Test
  public void testToXmlDate() throws Exception {
    Calendar cal = Calendar.getInstance();
    cal.set(2014, Calendar.DECEMBER, 15, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);

    XMLGregorianCalendar actual = DocumentUtils.toXmlDate(cal.getTime());

    assertEquals("2014-12-15", actual.toXMLFormat());
  }
 private String createResetEmail(OrcidProfile orcidProfile, String baseUri) {
   String userEmail =
       orcidProfile.getOrcidBio().getContactDetails().retrievePrimaryEmail().getValue();
   XMLGregorianCalendar date =
       DateUtils.convertToXMLGregorianCalendarNoTimeZoneNoMillis(new Date());
   String resetParams =
       MessageFormat.format(
           "email={0}&issueDate={1}", new Object[] {userEmail, date.toXMLFormat()});
   return createEmailBaseUrl(resetParams, baseUri, "reset-password-email");
 }
 static {
   try {
     GregorianCalendar calendar = new GregorianCalendar();
     calendar.setTimeInMillis((new Date()).getTime());
     XMLGregorianCalendar xmlGregCal =
         DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar);
     FEED = FEED_STR.replace("@TIME@", xmlGregCal.toXMLFormat());
   } catch (DatatypeConfigurationException e) {
     throw new RuntimeException(e);
   }
 }
Example #6
0
  /**
   * Construct an newly Time object that represents the specified XMLGregorianCalendar value
   *
   * @param time the value to be represented by the Time Object
   * @throws IllegalArgumentException if the given argument is not a valid Time
   */
  public Time(XMLGregorianCalendar time) throws IllegalArgumentException {
    if (time == null) {
      throw new IllegalArgumentException("parameter can not be null for Time");
    }

    // validate 'time' type which is defined in W3C schema
    // http://www.w3.org/TR/xmlschema-2/#time
    if (!W3CSchemaType.isValid("time", time.toXMLFormat())) {
      throw new IllegalArgumentException("parameter is invalid for datatype Time");
    }
    mTime = time;
  }
  static String format(Date date) {
    XMLGregorianCalendar xgCal = null;
    if (date != null) {
      GregorianCalendar gCal = new GregorianCalendar();
      gCal.setTime(date);
      try {
        xgCal = DatatypeFactory.newInstance().newXMLGregorianCalendar(gCal);
      } catch (DatatypeConfigurationException e) {
        return "";
      }
    }

    return (xgCal == null) ? "" : xgCal.toXMLFormat();
  }
  @Override
  public String marshal(Date date) throws Exception {
    if (date == null) {
      return null;
    }

    long utcMillis = date.getTime();
    GregorianCalendar calendar = new GregorianCalendar(TimeZone.getDefault());
    calendar.setTimeInMillis(utcMillis);

    DatatypeFactory factory = DatatypeFactory.newInstance();
    XMLGregorianCalendar xmlCalendar = factory.newXMLGregorianCalendar(calendar);
    return xmlCalendar.toXMLFormat();
  }
  @Test
  public void callService() throws Exception {
    AbstractSOAPTestHandler handler =
        new AbstractSOAPTestHandler(getXmlSupport()) {

          @Override
          protected boolean handleSOAP(
              String target,
              HttpServletRequest request,
              HttpServletResponse response,
              int dispatch,
              Document soap,
              NodeList headers,
              Node body)
              throws Exception {
            assertEquals("POST", request.getMethod());
            assertEquals(
                "Client ident", TEST_CHARGE_POINT_IDENTITY, getChargeBoxIdentityHeader(headers));
            assertEquals("Heartbeat request", "heartbeatRequest", body.getLocalName());

            response.setContentType("application/soap+xml");
            PrintWriter out = response.getWriter();
            respondWithSoapBody(
                out,
                "<heartbeatResponse xmlns=\"urn://Ocpp/Cs/2012/06/\"><currentTime>2015-06-03T15:00:00.000+00:12</currentTime></heartbeatResponse>");
            out.flush();
            response.flushBuffer();
            return true;
          }
        };
    getHttpServer().addHandler(handler);

    CentralSystemService client = getCentralSystem();

    HeartbeatRequest req = new HeartbeatRequest();
    HeartbeatResponse res = client.heartbeat(req, TEST_CHARGE_POINT_IDENTITY);
    assertNotNull("Response should not be null", res);

    XMLGregorianCalendar resultTimestamp = res.getCurrentTime();
    assertNotNull("Response date should be set", resultTimestamp);
    assertEquals("Response date", "2015-06-03T15:00:00.000+00:12", resultTimestamp.toXMLFormat());
  }
  @Override
  public String format(Object value) {
    if (value == null) {
      return null;
    }

    Calendar cal = (Calendar) value;
    if (pattern != null) {
      return super.formatCalendar(cal);
    }

    XMLGregorianCalendar xcal =
        dataTypeFactory.newXMLGregorianCalendarDate(
            cal.get(Calendar.YEAR),
            cal.get(Calendar.MONTH) + 1,
            cal.get(Calendar.DATE),
            getTimeZoneOffset(cal.getTime()));

    return xcal.toXMLFormat();
  }
Example #11
0
 public void testXMLGregorianCalendar() throws Exception {
   DatatypeFactory dtf = DatatypeFactory.newInstance();
   XMLGregorianCalendar cal = dtf.newXMLGregorianCalendar(1974, 10, 10, 18, 15, 17, 123, 0);
   assertEquals(quote(cal.toXMLFormat()), serializeAsString(cal));
 }
Example #12
0
  public static final void _write(
      final XoXMLStreamWriter writer, final Timer timer, RuntimeContext context) throws Exception {
    if (timer == null) {
      writer.writeXsiNil();
      return;
    }

    if (context == null) {
      context = new RuntimeContext();
    }

    final String prefix = writer.getUniquePrefix("http://java.sun.com/xml/ns/javaee");
    if (Timer.class != timer.getClass()) {
      context.unexpectedSubclass(writer, timer, Timer.class);
      return;
    }

    context.beforeMarshal(timer, LifecycleCallback.NONE);

    // ATTRIBUTE: id
    final String idRaw = timer.id;
    if (idRaw != null) {
      String id = null;
      try {
        id = Adapters.collapsedStringAdapterAdapter.marshal(idRaw);
      } catch (final Exception e) {
        context.xmlAdapterError(
            timer, "id", CollapsedStringAdapter.class, String.class, String.class, e);
      }
      writer.writeAttribute("", "", "id", id);
    }

    // ELEMENT: descriptions
    Text[] descriptions = null;
    try {
      descriptions = timer.getDescriptions();
    } catch (final Exception e) {
      context.getterError(timer, "descriptions", Timer.class, "getDescriptions", e);
    }
    if (descriptions != null) {
      for (final Text descriptionsItem : descriptions) {
        if (descriptionsItem != null) {
          writer.writeStartElement(prefix, "description", "http://java.sun.com/xml/ns/javaee");
          writeText(writer, descriptionsItem, context);
          writer.writeEndElement();
        } else {
          context.unexpectedNullValue(timer, "descriptions");
        }
      }
    }

    // ELEMENT: schedule
    final TimerSchedule schedule = timer.schedule;
    if (schedule != null) {
      writer.writeStartElement(prefix, "schedule", "http://java.sun.com/xml/ns/javaee");
      writeTimerSchedule(writer, schedule, context);
      writer.writeEndElement();
    } else {
      context.unexpectedNullValue(timer, "schedule");
    }

    // ELEMENT: start
    final XMLGregorianCalendar start = timer.start;
    if (start != null) {
      writer.writeStartElement(prefix, "start", "http://java.sun.com/xml/ns/javaee");
      writer.writeCharacters(start.toXMLFormat());
      writer.writeEndElement();
    }

    // ELEMENT: end
    final XMLGregorianCalendar end = timer.end;
    if (end != null) {
      writer.writeStartElement(prefix, "end", "http://java.sun.com/xml/ns/javaee");
      writer.writeCharacters(end.toXMLFormat());
      writer.writeEndElement();
    }

    // ELEMENT: timeoutMethod
    final NamedMethod timeoutMethod = timer.timeoutMethod;
    if (timeoutMethod != null) {
      writer.writeStartElement(prefix, "timeout-method", "http://java.sun.com/xml/ns/javaee");
      writeNamedMethod(writer, timeoutMethod, context);
      writer.writeEndElement();
    } else {
      context.unexpectedNullValue(timer, "timeoutMethod");
    }

    // ELEMENT: persistent
    final Boolean persistent = timer.persistent;
    if (persistent != null) {
      writer.writeStartElement(prefix, "persistent", "http://java.sun.com/xml/ns/javaee");
      writer.writeCharacters(Boolean.toString(persistent));
      writer.writeEndElement();
    }

    // ELEMENT: timezone
    final String timezoneRaw = timer.timezone;
    String timezone = null;
    try {
      timezone = Adapters.collapsedStringAdapterAdapter.marshal(timezoneRaw);
    } catch (final Exception e) {
      context.xmlAdapterError(
          timer, "timezone", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (timezone != null) {
      writer.writeStartElement(prefix, "timezone", "http://java.sun.com/xml/ns/javaee");
      writer.writeCharacters(timezone);
      writer.writeEndElement();
    }

    // ELEMENT: info
    final String infoRaw = timer.info;
    String info = null;
    try {
      info = Adapters.collapsedStringAdapterAdapter.marshal(infoRaw);
    } catch (final Exception e) {
      context.xmlAdapterError(
          timer, "info", CollapsedStringAdapter.class, String.class, String.class, e);
    }
    if (info != null) {
      writer.writeStartElement(prefix, "info", "http://java.sun.com/xml/ns/javaee");
      writer.writeCharacters(info);
      writer.writeEndElement();
    }

    context.afterMarshal(timer, LifecycleCallback.NONE);
  }
Example #13
0
  private void doTest()
      throws IndivoClientException, XPathExpressionException, UnsupportedEncodingException {
    String testDocRecApp =
        "<Testing123>strictly for testing - record specific app specific blah blah</Testing123>";

    String testDocApp =
        "<Testing123>strictly for testing - app specific NOT record specific</Testing123>";

    String testDocExtrnl = "<Testing123>strictly for testing - external from pha</Testing123>";
    String allergyDoc =
        "<Allergy xmlns=\"http://indivo.org/vocab/xml/documents#\">\n"
            + "  <dateDiagnosed>2009-05-16</dateDiagnosed>\n"
            + "  <diagnosedBy>Children's Hospital Boston</diagnosedBy>\n"
            + "  <allergen>\n"
            + "    <type type=\"http://codes.indivo.org/codes/allergentypes/\" value=\"drugs\">Drugs</type>\n"
            + "    <name type=\"http://codes.indivo.org/codes/allergens/\" value=\"penicillin\">Penicillin</name>\n"
            + "  </allergen>\n\n"
            + "  <reaction>blue rash</reaction>\n"
            + "  <specifics>this only happens on weekends - pha test</specifics>\n"
            + "</Allergy>";

    String xmlDateTime = null;
    gregCal = dtf.newXMLGregorianCalendar(new GregorianCalendar());
    xmlDateTime = gregCal.toXMLFormat();

    String hba1cDoc =
        "<HBA1C xmlns=\"http://indivo.org/vocab#\" value=\"63.63\""
            + " unit=\"mg/dL\" datetime=\""
            + xmlDateTime
            + "\" />"; // 2009-07-16T13:10:00

    /*<consumer_key>[email protected]</consumer_key>
    <secret>allergies</secret>*/
    client = new Rest("*****@*****.**", "allergies", "http://*****:*****@id", testResultDoc);
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_external_X_XPUT\n"
            + "PUT /records/{record_id}/documents/external/{app_id}/{external_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_external_X_XPUT(
                recordId,
                allergyApp,
                "externalId_pha" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                testDocExtrnl,
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_1x = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n==================================================\n\n");

    //        List<String> docsList = listAllDocs(recordId);
    System.out.println(
        "records_X_documents_X_metaGET\n"
            + "GET /records/{record_id}/documents/{document_id}/meta");
    testResultDoc =
        (Document)
            client.records_X_documents_X_metaGET(
                recordId, docId_1, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_external_X_X_metaGET\n"
            + "GET /records/{record_id}/documents/external/{app_id}/{external_id}/meta");
    testResultDoc =
        (Document)
            client.records_X_documents_external_X_X_metaGET(
                recordId,
                allergyApp,
                "externalId_pha" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_X_labelPUT\n"
            + "PUT /records/{record_id}/documents/{document_id}/label");
    testResultDoc =
        (Document)
            client.records_X_documents_X_labelPUT(
                recordId, docId_1, accessToken, accessTokenSecret, "sneeze", options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_external_X_X_labelPUT\n"
            + "PUT /records/{record_id}/documents/external/{app_id}/{external_id}/label");
    testResultDoc =
        (Document)
            client.records_X_documents_external_X_X_labelPUT(
                recordId,
                allergyApp,
                "externalId_pha" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                "cough",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println("records_X_documents_POST\n" + "POST /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("blue rash", "green rash"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_replaceMe = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_replacePOST\n"
            + "POST /records/{record_id}/documents/{document_id}/replace");
    testResultDoc =
        (Document)
            client.records_X_documents_X_replacePOST(
                recordId,
                docId_replaceMe,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("blue rash", "red rash"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n--------replacement---------------------------\n\n");

    System.out.println(
        "records_X_documents_X_versions_GET\n"
            + "GET /records/{record_id}/documents/{document_id}/versions/");
    testResultDoc =
        (Document)
            client.records_X_documents_X_versions_GET(
                pagingOrderingQuery,
                recordId,
                docId_replaceMe,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    //        System.out.println("records_X_documents_external_X_XPUT\n" +
    //        "PUT /records/{record_id}/documents/external/{app_id}/{external_id}");
    //        testResultDoc = (Document) client.records_X_documents_external_X_XPUT(recordId,
    // allergyApp,
    //                "externalId_toReplace" + extrnlRandom, accessToken, accessTokenSecret,
    //                testDocExtrnl.replace("strictly","mostly"), "application/xml", options);
    //        System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    //        //String docId_x_replaceMe = xpath.evaluate("/Document/@id", testResultDoc);
    //        System.out.println("\n---------------------------------------\n\n");

    System.out.println("records_X_documents_POST\n" + "POST /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                testDocExtrnl.replace("strictly", "partly"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_x_replaceWithExternal = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_replace_external_X_XPUT\n"
            + "PUT /records/{record_id}/documents/{document_id}/replace/external/{app_id}/{external_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_X_replace_external_X_XPUT(
                recordId,
                docId_x_replaceWithExternal,
                allergyApp,
                "externalId_replacement" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                testDocExtrnl.replace("strictly", "loosely"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n--------------------------------------------------\n\n");

    testResultDoc =
        (Document)
            client.records_X_documents_external_X_X_metaGET(
                recordId,
                allergyApp,
                "externalId_replacement" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_x_replaced = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n--------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_metaGET\n"
            + "GET /records/{record_id}/documents/{document_id}/meta");
    testResultDoc =
        (Document)
            client.records_X_documents_X_metaGET(
                recordId, docId_x_replaced, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n=partly===============================================\n\n");

    System.out.println("records_X_documents_POST\n" + "POST /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("blue rash", "green rash"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_deleteMe = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_XGET\n" + "GET /records/{record_id}/documents/{document_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_XGET(
                recordId,
                docId_deleteMe,
                accessToken,
                accessTokenSecret,
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_XDELETE\n" + "DELETE /records/{record_id}/documents/{document_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_XDELETE(
                recordId, docId_deleteMe, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n------------------------------------------------\n\n");

    try {
      testResultDoc =
          (Document)
              client.records_X_documents_X_metaGET(
                  recordId, docId_deleteMe, accessToken, accessTokenSecret, options);
      throw new RuntimeException("should have thrown 404 above");
    } catch (IndivoClientExceptionHttp404 ice4) {
      System.out.println(ice4.toString());
    }
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n= 404 ===============================================\n\n");

    System.out.println("records_X_documents_POST\n" + "POST /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("blue rash", "orange rash"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_status = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_setStatusPOST\n"
            + "POST /records/{record_id}/documents/{document_id}/set-status");
    testResultDoc =
        (Document)
            client.records_X_documents_X_setStatusPOST(
                "why not", "void", recordId, docId_status, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n----------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_statusHistoryGET\n"
            + "GET /records/{record_id}/documents/{document_id}/status-history");
    testResultDoc =
        (Document)
            client.records_X_documents_X_statusHistoryGET(
                recordId, docId_status, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("blue rash", "yellow rash"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_rel_A = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    String testDocRelate_B =
        "<Testing123>strictly for testing Relate annotation: a golden yellow/Testing123>";
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                testDocRelate_B,
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_rel_B = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_rels_X_XPUT\n"
            + "PUT /records/{record_id}/documents/{document_id}/rels/{rel_type}/{other_document_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_X_rels_X_XPUT(
                recordId,
                docId_rel_A,
                "annotation",
                docId_rel_B,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_rels_X_POST\n"
            + "POST /records/{record_id}/documents/{document_id}/rels/{rel_type}/");
    testResultDoc =
        (Document)
            client.records_X_documents_X_rels_X_POST(
                recordId,
                docId_rel_A,
                "annotation",
                accessToken,
                accessTokenSecret,
                testDocRelate_B.replace("golden", "lemon"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_rels_X_GET\n"
            + "GET /records/{record_id}/documents/{document_id}/rels/{rel_type}/");
    testResultDoc =
        (Document)
            client.records_X_documents_X_rels_X_GET(
                pagingOrderingQuery,
                recordId,
                docId_rel_A,
                "annotation",
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==related docs ================================================\n\n");

    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId,
                accessToken,
                accessTokenSecret,
                allergyDoc.replace("weekends", "Sundays"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_1x_toannotate = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n--------------------------------------------\n\n");

    System.out.println(
        "records_X_documents_X_rels_X_external_X_XPUT\n"
            + "PUT /records/{record_id}/documents/{document_id}/rels/{rel_type}/external/{app_id}/{external_id}");
    testResultDoc =
        (Document)
            client.records_X_documents_X_rels_X_external_X_XPUT(
                recordId,
                docId_1x_toannotate,
                "annotation",
                allergyApp,
                "externalId_annotation" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                testDocExtrnl.replace("external from", "external test annotation, from"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println("records_X_documents_GET\n" + "GET /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_GET(
                pagingOrderingQuery, recordId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_documents_GET\n" + "GET /records/{record_id}/documents/?type={type_url}");
    testResultDoc =
        (Document)
            client.records_X_documents_GET(
                "http://indivo.org/vocab/xml/documents#Allergy",
                pagingOrderingQuery,
                recordId,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    // if (skipnone) {
    System.out.println("records_X_notifyPOST\n" + "POST /records/{record_id}/notify");
    testResultDoc =
        (Document)
            client.records_X_notifyPOST(
                "take note", "huh?", docId_1, recordId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");
    // }

    System.out.println(
        "++++++++++++++++++++++++++ record specific app specific ++++++++++++++++++++++++++++++++++++++++");
    System.out.println(
        "records_X_apps_X_documents_POST\n" + "POST /records/{record_id}/apps/{app_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_POST(
                recordId,
                allergyApp,
                accessToken,
                accessTokenSecret,
                testDocRecApp,
                "application/xml",
                options);
    String docId_rec_app_1 = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_external_XPUT\n"
            + "PUT /records/{record_id}/apps/{app_id}/documents/external/{external_id}");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_external_XPUT(
                recordId,
                allergyApp,
                "externalId_record_app_" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                testDocRecApp.replace("app specific blah blah", "app specific externalId"),
                "application/xml",
                options);
    String docId_rec_app_1x = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_X_labelPUT\n"
            + "PUT /records/{record_id}/apps/{app_id}/documents/{document_id}/label");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_X_labelPUT(
                recordId,
                allergyApp,
                docId_rec_app_1,
                accessToken,
                accessTokenSecret,
                "label_on_rec_app",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_GET\n" + "GET /records/{record_id}/apps/{app_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_GET(
                pagingOrderingQuery, recordId, allergyApp, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_XGET\n"
            + "GET /records/{record_id}/apps/{app_id}/documents/{document_id}");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_XGET(
                recordId,
                allergyApp,
                docId_rec_app_1,
                accessToken,
                accessTokenSecret,
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_X_metaGET\n"
            + "GET /records/{record_id}/apps/{app_id}/documents/{document_id}/meta");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_X_metaGET(
                recordId, allergyApp, docId_rec_app_1, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_apps_X_documents_external_X_metaGET\n"
            + "GET /records/{record_id}/apps/{app_id}/documents/external/{external_id}/meta");
    testResultDoc =
        (Document)
            client.records_X_apps_X_documents_external_X_metaGET(
                recordId,
                allergyApp,
                "externalId_record_app_" + extrnlRandom,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "+++ END record specific app specific, START app specific +++++++++++++++++");

    testResultDoc =
        (Document) client.apps_X_documents_POST(allergyApp, testDocApp, "application/xml", options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    testResultDoc =
        (Document)
            client.apps_X_documents_external_XPUT(
                allergyApp,
                "externalId_appSpecific_" + extrnlRandom,
                testDocApp.replace("testing", "testing app specific"),
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    testResultDoc =
        (Document)
            client.apps_X_documents_external_X_metaGET(
                allergyApp, "externalId_appSpecific_" + extrnlRandom, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    String docId_app_1x = xpath.evaluate("/Document/@id", testResultDoc);
    System.out.println("\n==================================================\n\n");

    testResultDoc = (Document) client.apps_X_documents_X_metaGET(allergyApp, docId_app_1x, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    testResultDoc =
        (Document)
            client.apps_X_documents_XGET(allergyApp, docId_app_1x, "application/xml", options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    testResultDoc =
        (Document) client.apps_X_documents_GET(pagingOrderingQuery, allergyApp, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");
    System.out.println("\n============= END app specific ===============\n\n");

    System.out.println("records_X_documents_POST\n" + "POST /records/{record_id}/documents/");
    testResultDoc =
        (Document)
            client.records_X_documents_POST(
                recordId, accessToken, accessTokenSecret, hba1cDoc, "application/xml", options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n---------------------------------------------------\n\n");

    System.out.println(
        "records_X_reports_minimal_measurements_X_GET\n"
            + "GET /records/{record_id}/reports/minimal/measurements/{lab_code}/");
    testResultDoc =
        (Document)
            client.records_X_reports_minimal_measurements_X_GET(
                pagingOrderingQuery, recordId, "HBA1C", accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "records_X_reports_minimal_X_GET\n"
            + "GET /records/{record_id}/reports/minimal/medications/");
    testResultDoc =
        (Document)
            client.records_X_reports_minimal_X_GET(
                pagingOrderingQuery,
                recordId,
                "allergies",
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    String[] accountpassword = properties.getProperty("account_password").split(" ");
    String accountId = accountpassword[0];
    //        String username = accountpassword[1];
    //        String password = accountpassword[2];

    System.out.println("records_X_shares_POST\n" + "POST /records/{record_id}/shares/");
    /* testResultDoc = (Document) chrome.records_X_shares_POST(
    accountId, "physician", recordId, sessionToken, sessionTokenSecret, options);*/
    testResultDoc =
        (Document)
            client.records_X_shares_POST(
                accountId, "physician", recordId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n----------------------------------------------\n\n");

    System.out.println("records_X_shares_GET\n" + "GET /records/{record_id}/shares/");
    testResultDoc =
        (Document)
            client.records_X_shares_GET(
                pagingOrderingQuery, recordId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n----------------------------------------------\n\n");

    System.out.println(
        "records_X_shares_X_deletePOST\n" + "POST /records/{record_id}/shares/{account_id}/delete");
    testResultDoc =
        (Document)
            client.records_X_shares_X_deletePOST(
                recordId, accountId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n----------------------------------------------\n\n");

    System.out.println("records_X_shares_GET\n" + "GET /records/{record_id}/shares/");
    testResultDoc =
        (Document)
            client.records_X_shares_GET(
                pagingOrderingQuery, recordId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    String carenetPhysician = properties.getProperty("carenets_physicians");
    String docId_contact = properties.getProperty("contact_docId");
    String docId_demographics = properties.getProperty("demographics_docId");
    someChromeWork(docId_1, docId_contact, docId_demographics, carenetPhysician);

    System.out.println("carenets_X_documents_GET\n" + "GET /carenets/{carenet_id}/documents/");
    testResultDoc =
        (Document)
            client.carenets_X_documents_GET(
                pagingOrderingQuery, carenetPhysician, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_documents_GET\n" + "GET /carenets/{carenet_id}/documents/?type={type_url}");
    testResultDoc =
        (Document)
            client.carenets_X_documents_GET(
                "http://indivo.org/vocab/xml/documents#Allergy",
                pagingOrderingQuery,
                carenetPhysician,
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_documents_XGET\n" + "GET /carenets/{carenet_id}/documents/{document_id}");
    testResultDoc =
        (Document)
            client.carenets_X_documents_XGET(
                carenetPhysician,
                docId_1,
                accessToken,
                accessTokenSecret,
                "application/xml",
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_documents_special_demographicsGET\n"
            + "GET /carenets/{carenet_id}/documents/special/demographics");
    testResultDoc =
        (Document)
            client.carenets_X_documents_special_demographicsGET(
                carenetPhysician, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_documents_special_contactGET\n"
            + "GET /carenets/{carenet_id}/documents/special/contact");
    testResultDoc =
        (Document)
            client.carenets_X_documents_special_contactGET(
                carenetPhysician, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_documents_X_metaGET\n"
            + "GET /carenets/{carenet_id}/documents/{document_id}/meta");
    testResultDoc =
        (Document)
            client.carenets_X_documents_X_metaGET(
                carenetPhysician, docId_1, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    //        if (skipnone)
    try {
      System.out.println(
          "carenets_X_reports_minimal_measurements_X_GET\n"
              + "GET /carenets/{carenet_id}/reports/minimal/measurements/{lab_code}/");
      testResultDoc =
          (Document)
              client.carenets_X_reports_minimal_measurements_X_GET(
                  pagingOrderingQuery,
                  carenetPhysician,
                  "HBA1C",
                  accessToken,
                  accessTokenSecret,
                  options);
      System.out.println(Utils.domToString(testResultDoc) + "\n\n");
      System.out.println("\n==================================================\n\n");
    } catch (IndivoClientException ice) {
      reportKnownError(ice);
    }

    System.out.println(
        "carenets_X_reports_minimal_X_GET\n"
            + "GET /carenets/{carenet_id}/reports/minimal/allergies/");
    testResultDoc =
        (Document)
            client.carenets_X_reports_minimal_X_GET(
                pagingOrderingQuery,
                carenetPhysician,
                "allergies",
                accessToken,
                accessTokenSecret,
                options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println("carenets_X_recordGET\n" + "GET /carenets/{carenet_id}/record");
    testResultDoc =
        (Document)
            client.carenets_X_recordGET(carenetPhysician, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");

    System.out.println(
        "carenets_X_accounts_X_permissionsGET\n"
            + "GET /carenets/{carenet_id}/accounts/{account_id}/permissions");
    testResultDoc =
        (Document)
            client.carenets_X_accounts_X_permissionsGET(
                carenetPhysician, accountId, accessToken, accessTokenSecret, options);
    System.out.println(Utils.domToString(testResultDoc) + "\n\n");
    System.out.println("\n==================================================\n\n");
  }
Example #14
0
 /**
  * Returns a String Object representing this Time value
  *
  * @return return a string representation of the value of this Time object
  */
 @Override
 public String toString() {
   return mTime.toXMLFormat();
 }
Example #15
0
  private static void sendXQueryResponse(HttpServletResponse res, Object o) throws IOException {
    // Make sure to leave the status code alone.  It defaults to 200, but sometimes
    // callers of this method will have set it to a custom code.
    res.setContentType("x-marklogic/xquery; charset=UTF-8");
    // res.setContentType("text/plain");
    Writer writer = res.getWriter(); // care to handle errors later?

    if (o == null) {
      writer.write("()");
    } else if (o instanceof byte[]) {
      writer.write("binary {'");
      writer.write(hexEncode((byte[]) o));
      writer.write("'}");
    } else if (o instanceof Object[]) {
      Object[] arr = (Object[]) o;
      writer.write("(");
      for (int i = 0; i < arr.length; i++) {
        sendXQueryResponse(res, arr[i]);
        if (i + 1 < arr.length) writer.write(", ");
      }
      writer.write(")");
    } else if (o instanceof String) {
      writer.write("'");
      writer.write(escapeSingleQuotes(o.toString()));
      writer.write("'");
    } else if (o instanceof Integer) {
      writer.write("xs:int(");
      writer.write(o.toString());
      writer.write(")");
    } else if (o instanceof Long) {
      writer.write("xs:integer(");
      writer.write(o.toString());
      writer.write(")");
    } else if (o instanceof Float) {
      Float flt = (Float) o;
      writer.write("xs:float(");
      if (flt.equals(Float.POSITIVE_INFINITY)) {
        writer.write("'INF'");
      } else if (flt.equals(Float.NEGATIVE_INFINITY)) {
        writer.write("'-INF'");
      } else if (flt.equals(Float.NaN)) {
        writer.write("fn:number(())"); // poor man's way to write NaN
      } else {
        writer.write(o.toString());
      }
      writer.write(")");
    } else if (o instanceof Double) {
      Double dbl = (Double) o;
      writer.write("xs:double(");
      if (dbl.equals(Double.POSITIVE_INFINITY)) {
        writer.write("'INF'");
      } else if (dbl.equals(Double.NEGATIVE_INFINITY)) {
        writer.write("'-INF'");
      } else if (dbl.equals(Double.NaN)) {
        writer.write("fn:number(())"); // poor man's way to write NaN
      } else {
        writer.write(o.toString());
      }
      writer.write(")");
    } else if (o instanceof Boolean) {
      writer.write("xs:boolean('");
      writer.write(o.toString());
      writer.write("')");
    } else if (o instanceof BigDecimal) {
      writer.write("xs:decimal(");
      writer.write(o.toString());
      writer.write(")");
    } else if (o instanceof Date) {
      // We want something like: 2006-04-30T01:28:30.499-07:00
      // We format to get:       2006-04-30T01:28:30.499-0700
      // Then we add in the colon
      writer.write("xs:dateTime('");
      String d = dateFormat.format((Date) o);
      writer.write(d.substring(0, d.length() - 2));
      writer.write(":");
      writer.write(d.substring(d.length() - 2));
      writer.write("')");
    } else if (o instanceof XMLGregorianCalendar) {
      XMLGregorianCalendar greg = (XMLGregorianCalendar) o;
      QName type = greg.getXMLSchemaType();
      if (type.equals(DatatypeConstants.DATETIME)) {
        writer.write("xs:dateTime('");
      } else if (type.equals(DatatypeConstants.DATE)) {
        writer.write("xs:date('");
      } else if (type.equals(DatatypeConstants.TIME)) {
        writer.write("xs:time('");
      } else if (type.equals(DatatypeConstants.GYEARMONTH)) {
        writer.write("xs:gYearMonth('");
      } else if (type.equals(DatatypeConstants.GMONTHDAY)) {
        writer.write("xs:gMonthDay('");
      } else if (type.equals(DatatypeConstants.GYEAR)) {
        writer.write("xs:gYear('");
      } else if (type.equals(DatatypeConstants.GMONTH)) {
        writer.write("xs:gMonth('");
      } else if (type.equals(DatatypeConstants.GDAY)) {
        writer.write("xs:gDay('");
      }
      writer.write(greg.toXMLFormat());
      writer.write("')");
    } else if (o instanceof Duration) {
      Duration dur = (Duration) o;
      /*
      // The following fails on Xerces
      QName type = dur.getXMLSchemaType();
      if (type.equals(DatatypeConstants.DURATION)) {
        writer.write("xs:duration('");
      }
      else if (type.equals(DatatypeConstants.DURATION_DAYTIME)) {
        writer.write("xdt:dayTimeDuration('");
      }
      else if (type.equals(DatatypeConstants.DURATION_YEARMONTH)) {
        writer.write("xdt:yearMonthDuration('");
      }
      */
      // If no years or months, must be DURATION_DAYTIME
      if (dur.getYears() == 0 && dur.getMonths() == 0) {
        writer.write("xdt:dayTimeDuration('");
      }
      // If has years or months but nothing else, must be DURATION_YEARMONTH
      else if (dur.getDays() == 0
          && dur.getHours() == 0
          && dur.getMinutes() == 0
          && dur.getSeconds() == 0) {
        writer.write("xdt:yearMonthDuration('");
      } else {
        writer.write("xs:duration('");
      }
      writer.write(dur.toString());
      writer.write("')");
    } else if (o instanceof org.jdom.Element) {
      org.jdom.Element elt = (org.jdom.Element) o;
      writer.write("xdmp:unquote('");
      // Because "&lt;" in XQuery is the same as "<" I need to double escape any ampersands
      writer.write(
          new org.jdom.output.XMLOutputter()
              .outputString(elt)
              .replaceAll("&", "&amp;")
              .replaceAll("'", "''"));
      writer.write("')/*"); // make sure to return the root elt
    } else if (o instanceof org.jdom.Document) {
      org.jdom.Document doc = (org.jdom.Document) o;
      writer.write("xdmp:unquote('");
      writer.write(
          new org.jdom.output.XMLOutputter()
              .outputString(doc)
              .replaceAll("&", "&amp;")
              .replaceAll("'", "''"));
      writer.write("')");
    } else if (o instanceof org.jdom.Text) {
      org.jdom.Text text = (org.jdom.Text) o;
      writer.write("text {'");
      writer.write(escapeSingleQuotes(text.getText()));
      writer.write("'}");
    } else if (o instanceof org.jdom.Attribute) {
      // <fake xmlns:pref="http://uri.com" pref:attrname="attrvalue"/>/@*:attrname
      // <fake xmlns="http://uri.com" attrname="attrvalue"/>/@*:attrname
      org.jdom.Attribute attr = (org.jdom.Attribute) o;
      writer.write("<fake xmlns");
      if ("".equals(attr.getNamespacePrefix())) {
        writer.write("=\"");
      } else {
        writer.write(":" + attr.getNamespacePrefix() + "=\"");
      }
      writer.write(attr.getNamespaceURI());
      writer.write("\" ");
      writer.write(attr.getQualifiedName());
      writer.write("=\"");
      writer.write(escapeSingleQuotes(attr.getValue()));
      writer.write("\"/>/@*:");
      writer.write(attr.getName());
    } else if (o instanceof org.jdom.Comment) {
      org.jdom.Comment com = (org.jdom.Comment) o;
      writer.write("comment {'");
      writer.write(escapeSingleQuotes(com.getText()));
      writer.write("'}");
    } else if (o instanceof org.jdom.ProcessingInstruction) {
      org.jdom.ProcessingInstruction pi = (org.jdom.ProcessingInstruction) o;
      writer.write("processing-instruction ");
      writer.write(pi.getTarget());
      writer.write(" {'");
      writer.write(escapeSingleQuotes(pi.getData()));
      writer.write("'}");
    } else if (o instanceof QName) {
      QName q = (QName) o;
      writer.write("fn:expanded-QName('");
      writer.write(escapeSingleQuotes(q.getNamespaceURI()));
      writer.write("','");
      writer.write(q.getLocalPart());
      writer.write("')");
    } else {
      writer.write(
          "error('XQuery tried to retrieve unsupported type: " + o.getClass().getName() + "')");
    }

    writer.flush();
  }