Example usage for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT

List of usage examples for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT.

Prototype

FastDateFormat ISO_DATETIME_TIME_ZONE_FORMAT

To view the source code for org.apache.commons.lang.time DateFormatUtils ISO_DATETIME_TIME_ZONE_FORMAT.

Click Source Link

Document

ISO8601 formatter for date-time with time zone.

Usage

From source file:com.github.rnewson.couchdb.lucene.RhinoDocument.java

public static void jsFunction_add(final Context cx, final Scriptable thisObj, final Object[] args,
        final Function funObj) {
    final RhinoDocument doc = checkInstance(thisObj);

    if (args.length < 1 || args.length > 2) {
        throw Context.reportRuntimeError("Invalid number of arguments.");
    }/*from w  w w . java  2 s  .c o m*/

    if (args[0] == null) {
        throw Context.reportRuntimeError("first argument must be non-null.");
    }

    if (args.length == 2 && (args[1] == null || args[1] instanceof NativeObject == false)) {
        throw Context.reportRuntimeError("second argument must be an object.");
    }

    final JSONObject defaults = JSONObject.fromObject((String) cx.getThreadLocal("defaults"));

    String language = defaults.optString("language", "en");
    String field = defaults.optString("field", Config.DEFAULT_FIELD);
    String store = defaults.optString("store", "no");
    String index = defaults.optString("index", "analyzed");

    // Check for local override.
    if (args.length == 2) {
        final NativeObject obj = (NativeObject) args[1];
        language = optString(obj, "language", language);
        field = optString(obj, "field", field);
        store = optString(obj, "store", store);
        index = optString(obj, "index", index);
    }

    if (args[0] instanceof String || args[0] instanceof Integer || args[0] instanceof Double
            || args[0] instanceof Boolean) {
        doc.add(new Field(field, args[0].toString(), Store.get(store), Index.get(index)));
    } else {
        // Is it a date?
        try {
            final Date date = (Date) Context.jsToJava(args[0], Date.class);

            // Special indexed form.
            doc.add(new Field(field, Long.toString(date.getTime()), Field.Store.NO,
                    Field.Index.NOT_ANALYZED_NO_NORMS));

            // Store in ISO8601 format, if requested.
            if ("yes".equals(store)) {
                final String asString = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(date);
                doc.add(new Field(field, asString, Field.Store.YES, Field.Index.NO));
            }
        } catch (final EvaluatorException e) {
            Utils.LOG.warn(args[0].getClass().getCanonicalName() + " seen, treating as String.");
            doc.add(new Field(field, args[0].toString(), Store.get(store), Index.get(index)));
        }
    }
}

From source file:com.smartitengineering.event.hub.common.EventJsonProvider.java

public String getJsonString(Event event) {
    if (event == null) {
        return "";
    }//from  ww w . j a  va  2 s  .  co m
    Map<String, String> jsonMap = new LinkedHashMap<String, String>();
    if (StringUtils.isNotBlank(event.getPlaceholderId())) {
        jsonMap.put(PLACEHOLDER_ID, event.getPlaceholderId());
    }
    if (StringUtils.isNotBlank(event.getUniversallyUniqueID())) {
        jsonMap.put(UNIVERSAL_UNIQUE_ID, event.getUniversallyUniqueID());
    }
    if (StringUtils.isNotBlank(event.getEventContent().getContentType())) {
        jsonMap.put(CONTENT_TYPE, event.getEventContent().getContentType());
    }
    InputStream contentStream = event.getEventContent().getContent();
    if (contentStream != null) {
        String contentAsString = "";
        if (contentCache.containsKey(event)) {
            contentAsString = contentCache.get(event);
        } else {
            try {
                if (contentStream.markSupported()) {
                    contentStream.mark(Integer.MAX_VALUE);
                }
                contentAsString = IOUtils.toString(contentStream);
                contentCache.put(event, contentAsString);
                if (contentStream.markSupported()) {
                    contentStream.reset();
                }
            } catch (IOException ex) {
            }
        }
        jsonMap.put(CONTENT_AS_STRING, contentAsString);
    }
    Date creationDate = event.getCreationDate();
    if (creationDate != null) {
        jsonMap.put(CREATION_DATE, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(creationDate));
    }
    try {
        return mapper.writeValueAsString(jsonMap);
    } catch (Exception ex) {
        return "";
    }
}

From source file:com.smartitengineering.dao.impl.hbase.spi.impl.SchemaInfoProviderImpl.java

@Override
public byte[] getRowIdFromId(IdType id) throws IOException {
    final byte[] rowId;
    if (id instanceof Integer) {
        rowId = Bytes.toBytes((Integer) id);
    } else if (id instanceof String) {
        rowId = Bytes.toBytes((String) id);
    } else if (id instanceof Long) {
        rowId = Bytes.toBytes((Long) id);
    } else if (id instanceof Double) {
        rowId = Bytes.toBytes((Double) id);
    } else if (id instanceof Date) {
        rowId = Bytes.toBytes(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(((Date) id)));
    } else if (id instanceof Externalizable) {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream);
        ((Externalizable) id).writeExternal(outputStream);
        IOUtils.closeQuietly(outputStream);
        rowId = byteArrayOutputStream.toByteArray();
    } else if (id != null) {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        final ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(id);
        IOUtils.closeQuietly(objectOutputStream);
        IOUtils.closeQuietly(byteArrayOutputStream);
        rowId = byteArrayOutputStream.toByteArray();
    } else {/*www  .j a  v a  2 s .c om*/
        rowId = new byte[0];
    }
    return rowId;
}

From source file:edu.asu.lib.qdc.QualifiedDublinCoreDocument.java

public void addDate(Date value) {
    W3CDTF w3cdtf = new W3CDTF();
    w3cdtf.getContent().add(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(value));
    getSimpleDc().getTitleOrCreatorOrSubject().add(of.createDate(w3cdtf));
}

From source file:com.smartitengineering.event.hub.common.ChannelJsonProvider.java

protected String formatDate(Date date) {
    return DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(date);
}

From source file:com.smartitengineering.dao.impl.hbase.spi.impl.SchemaInfoProviderImpl.java

@Override
public IdType getIdFromRowId(byte[] id) throws IOException, ClassNotFoundException {
    final Object idInstance;
    if (Externalizable.class.isAssignableFrom(idTypeClass)) {
        idInstance = provider.getInstance(idTypeClass);
        DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(id));
        ((Externalizable) idInstance).readExternal(inputStream);
    } else if (Integer.class.isAssignableFrom(idTypeClass)) {
        idInstance = Bytes.toInt(id);// w ww . j  a va  2 s  .c o  m
    } else if (String.class.isAssignableFrom(idTypeClass)) {
        idInstance = Bytes.toString(id);
    } else if (Long.class.isAssignableFrom(idTypeClass)) {
        idInstance = Bytes.toLong(id);
    } else if (Double.class.isAssignableFrom(idTypeClass)) {
        idInstance = Bytes.toDouble(id);
    } else if (Date.class.isAssignableFrom(idTypeClass)) {
        try {
            idInstance = DateUtils.parseDate(Bytes.toString(id),
                    new String[] { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() });
        } catch (ParseException ex) {
            throw new IOException(ex);
        }
    } else {
        idInstance = (IdType) new ObjectInputStream(new ByteArrayInputStream(id)).readObject();
    }
    return (IdType) idInstance;
}

From source file:com.hpe.application.automation.tools.octane.tests.TestDispatcher.java

private void audit(OctaneConfiguration octaneConfiguration, Run run, String id,
        boolean temporarilyUnavailable) {
    try {//from  ww w.  j a v a 2 s.c o m
        FilePath auditFile = new FilePath(new File(run.getRootDir(), TEST_AUDIT_FILE));
        JSONArray audit;
        if (auditFile.exists()) {
            InputStream is = auditFile.read();
            audit = JSONArray.fromObject(IOUtils.toString(is, "UTF-8"));
            IOUtils.closeQuietly(is);
        } else {
            audit = new JSONArray();
        }
        JSONObject event = new JSONObject();
        event.put("id", id);
        event.put("pushed", id != null && !id.isEmpty());
        event.put("date", DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date()));
        event.put("location", octaneConfiguration.getUrl());
        event.put("sharedSpace", octaneConfiguration.getSharedSpace());
        if (temporarilyUnavailable) {
            event.put("temporarilyUnavailable", true);
        }
        audit.add(event);
        auditFile.write(audit.toString(), "UTF-8");
    } catch (IOException | InterruptedException e) {
        logger.error("failed to create audit entry for  " + octaneConfiguration + "; " + run);
    }
}

From source file:com.hp.application.automation.tools.octane.tests.TestDispatcher.java

private void audit(ServerConfiguration configuration, Run build, Long id, boolean temporarilyUnavailable)
        throws IOException, InterruptedException {
    FilePath auditFile = new FilePath(new File(build.getRootDir(), TEST_AUDIT_FILE));
    JSONArray audit;/*from w  w w.  j  a  v  a  2s  .  c o  m*/
    if (auditFile.exists()) {
        InputStream is = auditFile.read();
        audit = JSONArray.fromObject(IOUtils.toString(is, "UTF-8"));
        IOUtils.closeQuietly(is);
    } else {
        audit = new JSONArray();
    }
    JSONObject event = new JSONObject();
    event.put("id", id);
    event.put("pushed", id != null);
    event.put("date", DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date()));
    event.put("location", configuration.location);
    event.put("sharedSpace", configuration.sharedSpace);
    if (temporarilyUnavailable) {
        event.put("temporarilyUnavailable", true);
    }
    audit.add(event);
    auditFile.write(audit.toString(), "UTF-8");
}

From source file:edu.asu.lib.qdc.QualifiedDublinCoreDocument.java

public void addDateSubmitted(Date value) {
    W3CDTF w3cdtf = new W3CDTF();
    w3cdtf.getContent().add(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(value));
    getDcTerms().getAlternativeOrTableOfContentsOrAbstract().add(of.createDateSubmitted(w3cdtf));
}

From source file:edu.asu.lib.qdc.QualifiedDublinCoreDocument.java

public void addCreated(Date dateCreated) {
    guardExtendedDc();//  ww  w.j  a va 2 s.  c o  m
    W3CDTF w3cdtf = new W3CDTF();
    w3cdtf.getContent().add(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(dateCreated));
    getDcTerms().getAlternativeOrTableOfContentsOrAbstract().add(of.createCreated(w3cdtf));
}