public void setModified(Date modified) {
   Calendar cal = Calendar.getInstance();
   cal.setTime(modified);
   String date = DatatypeConverter.printDateTime(cal);
   res.addProperty(
       DCTerms.modified, model.createTypedLiteral(date, JenaOREConstants.dateTypedLiteral));
 }
Esempio n. 2
0
 /**
  * @param dt
  * @return
  */
 public static String printDateTime(Date dt) {
   if (dt != null) {
     Calendar cal = new GregorianCalendar();
     cal.setTime(dt);
     return DatatypeConverter.printDateTime(cal);
   }
   return null;
 }
 //		@JsonIgnore
 public String getLastActive() {
   String dt = null;
   if (lastActive != null) {
     TimeZone zone = TimeZone.getTimeZone("UTC");
     Calendar c = Calendar.getInstance(zone);
     c.setTime(lastActive);
     dt = DatatypeConverter.printDateTime(c).substring(0, 19) + "Z";
   }
   return dt;
 }
 private static String asString(final Object primitive) {
   // TODO: improve 'string' conversion; maybe consider only String properties
   if (primitive instanceof String) {
     return (String) primitive;
   } else if (primitive instanceof Calendar) {
     return DatatypeConverter.printDateTime((Calendar) primitive);
   } else if (primitive instanceof byte[]) {
     return DatatypeConverter.printBase64Binary((byte[]) primitive);
   } else {
     return primitive.toString();
   }
 }
Esempio n. 5
0
  // returns the given datetime formatted as a string adhering to the given pattern
  public static String emit(java.util.Calendar input, String pattern) {
    if (pattern == null) pattern = DEFAULT_DATETIME_PATTERN;
    String output = null;

    if (input != null) {
      if (pattern.equals("datetime")) {
        output = javax.xml.bind.DatatypeConverter.printDateTime(input);
      } else if (pattern.equals("date")) {
        output = javax.xml.bind.DatatypeConverter.printDate(input);
      } else if (pattern.equals("time")) {
        output = javax.xml.bind.DatatypeConverter.printTime(input);
      } else if (pattern.equals("milliseconds")) {
        output = "" + input.getTimeInMillis();
      } else {
        java.text.DateFormat formatter = new java.text.SimpleDateFormat(pattern);
        formatter.setLenient(false);
        output = formatter.format(input.getTime());
      }
    }

    return output;
  }
 @Override
 public String marshal(Date v) throws Exception {
   Calendar calendar = Calendar.getInstance();
   calendar.setTime(v);
   return DatatypeConverter.printDateTime(calendar);
 }
Esempio n. 7
0
  @Converter
  public static String toString(SyslogMessage message) {

    boolean isRfc5424 = message instanceof Rfc5424SyslogMessage;

    StringBuilder sbr = new StringBuilder();
    sbr.append("<");
    if (message.getFacility() == null) {
      message.setFacility(SyslogFacility.USER);
    }
    if (message.getSeverity() == null) {
      message.setSeverity(SyslogSeverity.INFO);
    }
    if (message.getHostname() == null) {
      // This is massively ugly..
      try {
        message.setHostname(InetAddress.getLocalHost().toString());
      } catch (UnknownHostException e) {
        message.setHostname("UNKNOWN_HOST");
      }
    }
    sbr.append(message.getFacility().ordinal() * 8 + message.getSeverity().ordinal());
    sbr.append(">");

    // version number
    if (isRfc5424) {
      sbr.append("1");
      sbr.append(" ");
    }

    if (message.getTimestamp() == null) {
      message.setTimestamp(Calendar.getInstance());
    }

    if (isRfc5424) {
      sbr.append(DatatypeConverter.printDateTime(message.getTimestamp()));
    } else {
      addRfc3164TimeStamp(sbr, message);
    }
    sbr.append(" ");

    sbr.append(message.getHostname());
    sbr.append(" ");

    if (isRfc5424) {
      Rfc5424SyslogMessage rfc5424SyslogMessage = (Rfc5424SyslogMessage) message;

      sbr.append(rfc5424SyslogMessage.getAppName());
      sbr.append(" ");

      sbr.append(rfc5424SyslogMessage.getProcId());
      sbr.append(" ");

      sbr.append(rfc5424SyslogMessage.getMsgId());
      sbr.append(" ");

      sbr.append(rfc5424SyslogMessage.getStructuredData());
      sbr.append(" ");
    }

    sbr.append(message.getLogMessage());

    return sbr.toString();
  }
Esempio n. 8
0
 public static String convertTime(Date date) {
   TimeZone zone = TimeZone.getTimeZone("UTC");
   Calendar cal = Calendar.getInstance(zone);
   cal.setTime(date);
   return DatatypeConverter.printDateTime(cal);
 }
  /**
   * A DIME request is really a SOAP request that we are dealing with, and so its authentication is
   * the SOAP authentication approach. Since Axis2 does not handle DIME messages we deal with them
   * here.
   *
   * @param request
   * @param response
   */
  private void processDimeRequest(HttpServletRequest request, HttpServletResponse response) {
    S3PutObjectRequest putRequest = null;
    S3PutObjectResponse putResponse = null;
    int bytesRead = 0;

    S3Engine engine = new S3Engine();

    try {
      logRequest(request);

      MultiPartDimeInputStream ds = new MultiPartDimeInputStream(request.getInputStream());

      // -> the first stream MUST be the SOAP party
      if (ds.nextInputStream()) {
        // logger.debug( "DIME msg [" + ds.getStreamType() + "," + ds.getStreamTypeFormat() + "," +
        // ds.getStreamId() + "]" );
        byte[] buffer = new byte[8192];
        bytesRead = ds.read(buffer, 0, 8192);
        // logger.debug( "DIME SOAP Bytes read: " + bytesRead );
        ByteArrayInputStream bis = new ByteArrayInputStream(buffer, 0, bytesRead);
        putRequest = toEnginePutObjectRequest(bis);
      }

      // -> we only need to support a DIME message with two bodyparts
      if (null != putRequest && ds.nextInputStream()) {
        InputStream is = ds.getInputStream();
        putRequest.setData(is);
      }

      // -> need to do SOAP level auth here, on failure return the SOAP fault
      StringBuffer xml = new StringBuffer();
      String AWSAccessKey = putRequest.getAccessKey();
      UserInfo info = ServiceProvider.getInstance().getUserInfo(AWSAccessKey);
      try {
        S3SoapAuth.verifySignature(
            putRequest.getSignature(),
            "PutObject",
            putRequest.getRawTimestamp(),
            AWSAccessKey,
            info.getSecretKey());

      } catch (AxisFault e) {
        String reason = e.toString();
        int start = reason.indexOf(".AxisFault:");
        if (-1 != start) reason = reason.substring(start + 11);

        xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        xml.append(
            "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" >\n");
        xml.append("<soap:Body>\n");
        xml.append("<soap:Fault>\n");
        xml.append("<faultcode>").append(e.getFaultCode().toString()).append("</faultcode>\n");
        xml.append("<faultstring>").append(reason).append("</faultstring>\n");
        xml.append("</soap:Fault>\n");
        xml.append("</soap:Body></soap:Envelope>");

        endResponse(response, xml.toString());
        return;
      }

      // -> PutObject S3 Bucket Policy would be done in the engine.handleRequest() call
      UserContext.current()
          .initContext(AWSAccessKey, info.getSecretKey(), AWSAccessKey, "S3 DIME request", request);
      putResponse = engine.handleRequest(putRequest);

      xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
      xml.append(
          "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"http://s3.amazonaws.com/doc/2006-03-01/\">");
      xml.append("<soap:Body>");
      xml.append("<tns:PutObjectResponse>");
      xml.append("<tns:PutObjectResponse>");
      xml.append("<tns:ETag>\"").append(putResponse.getETag()).append("\"</tns:ETag>");
      xml.append("<tns:LastModified>")
          .append(DatatypeConverter.printDateTime(putResponse.getLastModified()))
          .append("</tns:LastModified>");
      xml.append("</tns:PutObjectResponse></tns:PutObjectResponse>");
      xml.append("</soap:Body></soap:Envelope>");

      endResponse(response, xml.toString());
    } catch (PermissionDeniedException e) {
      logger.error("Unexpected exception " + e.getMessage(), e);
      response.setStatus(403);
      endResponse(response, "Access denied");
    } catch (Throwable e) {
      logger.error("Unexpected exception " + e.getMessage(), e);
    } finally {
    }
  }
Esempio n. 10
0
 @XmlAttribute
 public String getCreatedAtISO() {
   Calendar calendar = GregorianCalendar.getInstance();
   calendar.setTime(this.createdAt);
   return javax.xml.bind.DatatypeConverter.printDateTime(calendar);
 }
Esempio n. 11
0
 public String write(Object in) {
   return DatatypeConverter.printDateTime((Calendar) in);
 }