List of usage examples for java.util Calendar setTimeInMillis
public void setTimeInMillis(long millis)
From source file:org.herrlado.websms.connector.myphone.ConnectorMyphone.java
/** * These post data is needed for sending a sms. * /*from w ww . j av a 2 s .c o m*/ * @param ctx * {@link ConnectorContext} * @return array of params * @throws Exception * if an error occures. */ private String getSmsPost(final ConnectorContext ctx) throws Exception { final StringBuilder sb = new StringBuilder(); final String[] to = ctx.getCommand().getRecipients(); String delimiter = ","; for (int i = 0; i < to.length; ++i) { if (i == to.length - 1) { delimiter = ""; } String rn = Utils.getRecipientsNumber(to[i]); if (!rn.startsWith("8")) { rn = Utils.national2international(ctx.command.getDefPrefix(), Utils.getRecipientsNumber(rn)); } sb.append(rn).append(delimiter); } // data: { // rcpt: this.target, // sender: sender, // sendernum: $pick(sendernum, ''), // message: text, // schedule: (this.options.schedule || ''), // parentid: (parentid || ''), // parenttype: (parenttype || ''), // eventtype: (eventtype || ''), // send: true // }, final StringBuilder sb1 = new StringBuilder(); sb1.append("rcpt="); // sb1.append(URLEncoder.encode(sb.toString(), PAGE_ENCODING)); String sender = Utils.getSender(ctx.getContext(), ctx.getCommand().getDefSender()); sender = URLEncoder.encode(sender, PAGE_ENCODING); sb1.append("&sender="); sb1.append("&sendernum=").append(sender); sb1.append("&message="); sb1.append(URLEncoder.encode(ctx.getCommand().getText(), PAGE_ENCODING)); final long sendLater = ctx.getCommand().getSendLater(); sb1.append("&schedule="); if (sendLater > 0) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(sendLater); cal.set(Calendar.SECOND, 0); final String late = format.get().format(cal.getTime()); sb1.append(URLEncoder.encode(late, PAGE_ENCODING)); } sb1.append("&parentid="); sb1.append("&parenttype="); sb1.append("&eventtype="); sb1.append("&send=true"); final String post = sb1.toString(); Log.d(TAG, "request: " + post); return post; }
From source file:net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskXMsgClient.CFAsteriskXMsgClientSchema.java
public static Calendar convertTimestampString(String val) { if ((val == null) || (val.length() == 0)) { return (null); } else if (val.length() != 19) { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskXMsgClientSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } else if (((val.charAt(0) >= '0') && (val.charAt(0) <= '9')) && ((val.charAt(1) >= '0') && (val.charAt(1) <= '9')) && ((val.charAt(2) >= '0') && (val.charAt(2) <= '9')) && ((val.charAt(3) >= '0') && (val.charAt(3) <= '9')) && (val.charAt(4) == '-') && ((val.charAt(5) >= '0') && (val.charAt(5) <= '1')) && ((val.charAt(6) >= '0') && (val.charAt(6) <= '9')) && (val.charAt(7) == '-') && ((val.charAt(8) >= '0') && (val.charAt(8) <= '3')) && ((val.charAt(9) >= '0') && (val.charAt(9) <= '9')) && (val.charAt(10) == ' ') && ((val.charAt(11) >= '0') && (val.charAt(11) <= '2')) && ((val.charAt(12) >= '0') && (val.charAt(12) <= '9')) && (val.charAt(13) == ':') && ((val.charAt(14) >= '0') && (val.charAt(14) <= '5')) && ((val.charAt(15) >= '0') && (val.charAt(15) <= '9')) && (val.charAt(16) == ':') && ((val.charAt(17) >= '0') && (val.charAt(17) <= '5')) && ((val.charAt(18) >= '0') && (val.charAt(18) <= '9'))) { /*// w w w .j a v a 2 s . c om * NOTE: * .Net uses substring( startcol, lengthOfSubstring ) * Java uses substring( startcol, endcol ) and does not * include charAt( endcol ); */ int year = Integer.parseInt(val.substring(0, 4)); int month = Integer.parseInt(val.substring(5, 7)); int day = Integer.parseInt(val.substring(8, 10)); int hour = Integer.parseInt(val.substring(11, 13)); int minute = Integer.parseInt(val.substring(14, 16)); int second = Integer.parseInt(val.substring(17, 19)); Calendar retval = new GregorianCalendar(CFLibDbUtil.getDbServerTimeZone()); retval.set(Calendar.YEAR, year); retval.set(Calendar.MONTH, month - 1); retval.set(Calendar.DAY_OF_MONTH, day); retval.set(Calendar.HOUR_OF_DAY, hour); retval.set(Calendar.MINUTE, minute); retval.set(Calendar.SECOND, second); Calendar local = new GregorianCalendar(); local.setTimeInMillis(retval.getTimeInMillis()); return (local); } else { throw CFLib.getDefaultExceptionFactory().newUsageException(CFAsteriskXMsgClientSchema.class, "convertTimestampString", "Value must be in YYYY-MM-DD HH24:MI:SS format \"" + val + "\" is invalid"); } }
From source file:edu.uci.ics.crawler4j.crawler.fetcher.PageFetcher.java
private void parseCacheHeaders(final Page page, final HttpResponse response) { boolean canCache = true; Header cacheControl = response.getLastHeader("cache-control"); if (cacheControl != null) { String[] cacheControls = cacheControl.getValue().split(","); for (String cc : cacheControls) { if (cc.equalsIgnoreCase("no-cache") || cc.equalsIgnoreCase("no-store")) { canCache = false;// w ww . j a va2s .com break; } } } if (canCache) { Header lastMod = response.getLastHeader("last-modified"); if (lastMod != null) { try { Calendar lastModCal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); lastModCal.setTimeInMillis(DateUtils.parseDate(lastMod.getValue()).getTime()); page.setLastModified(lastModCal); } catch (DateParseException e) { logger.debug("Unable to parse last modified date: " + lastMod.getValue(), e); } } Header etag = response.getLastHeader("etag"); if (etag != null) page.setETag(etag.getValue()); } }
From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java
/** * Returns a sample dataset./*from www . ja v a 2s. c o m*/ * * @return The dataset. */ private CategoryDataset createDataset() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Calendar calendarEnd = Calendar.getInstance(); int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis()); long time = calendarEnd.getTimeInMillis(); time = time - (time % (60 * 60 * 24 * 1000)) - tzoffset; calendarEnd.setTimeInMillis(time); try { Connection connection = Util.getConnection("main", getServletContext()); Calendar calendarBegin = (Calendar) calendarEnd.clone(); calendarBegin.add(Calendar.DAY_OF_MONTH, -7); getMetrics(connection, " ?", "CLIENT_CONNECTIONS", calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset); } catch (SQLException e) { logger.error(e); e.printStackTrace(); } return dataset; }
From source file:org.xaloon.wicket.component.repository.impl.FileRepositoryImpl.java
public void storeNextVersion(FileDescription latestVersion, InputStream fileStream) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, PathNotFoundException, RepositoryException { final String pathLatestVersion = latestVersion.getFilePath(); Node rootNode = contentSessionFacade.getDefaultSession().getRootNode(); if (rootNode.hasNode(pathLatestVersion)) { final Node childNode = rootNode.getNode(pathLatestVersion); childNode.checkout();// w w w. j a va 2 s .co m childNode.getNode(JcrConstants.JCR_CONTENT).setProperty(JcrConstants.JCR_DATA, fileStream); final Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(System.currentTimeMillis()); childNode.getNode(JcrConstants.JCR_CONTENT).setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); childNode.save(); final Version version = childNode.checkin(); latestVersion.setFileVersion(version.getName()); latestVersion.setLastModified(lastModified.getTime()); } }
From source file:com.appeligo.alerts.KeywordAlertChecker.java
/** * @param timeZone the user's timezone/*from w w w .j ava 2 s. c o m*/ * @param startOfDay We're using the value of earliestSmsTime (user account setting) as a starting point, * so anything before this time is credited to the previous day) * @return 12am (midnight) using system time (not user time) because "Date" objects stored in SQL * come back in system time. */ private Date calculateDay(TimeZone timeZone, Time startOfDay) { Calendar cal = Calendar.getInstance(timeZone); Calendar start = Calendar.getInstance(); start.setTimeInMillis(startOfDay.getTime()); cal.add(Calendar.HOUR_OF_DAY, 0 - start.get(Calendar.HOUR_OF_DAY)); cal.add(Calendar.MINUTE, 0 - start.get(Calendar.MINUTE)); cal.add(Calendar.SECOND, 0 - start.get(Calendar.SECOND)); cal.clear(Calendar.MILLISECOND); cal.clear(Calendar.SECOND); cal.clear(Calendar.MINUTE); cal.clear(Calendar.HOUR_OF_DAY); cal.clear(Calendar.HOUR); cal.clear(Calendar.AM_PM); TimeZone systemTimeZone = TimeZone.getDefault(); long now = System.currentTimeMillis(); long difference = systemTimeZone.getOffset(now) - timeZone.getOffset(now); return new Date(cal.getTimeInMillis() - difference); }
From source file:org.xaloon.wicket.component.repository.impl.FileRepositoryImpl.java
public FileDescription storeFile(String path, String name, String mimeType, InputStream fileStream) throws PathNotFoundException, RepositoryException, Exception { FileDescription filedesc = null;/*from www . j a va 2s . c o m*/ Session session = contentSessionFacade.getDefaultSession(); Node rootNode = session.getRootNode(); Node folder = (rootNode.hasNode(path)) ? rootNode.getNode(path) : RepositoryHelper.createFolder(session, path, rootNode); Node file = folder.addNode(name, JcrConstants.NT_FILE); file.addMixin(JcrConstants.MIX_REFERENCEABLE); Node fileContent = file.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); fileContent.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); final Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(System.currentTimeMillis()); fileContent.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); fileContent.setProperty(JcrConstants.JCR_DATA, fileStream); session.save(); final String uuid = fileContent.getUUID(); filedesc = new FileDescription(); filedesc.setLastModified(lastModified.getTime()); filedesc.setMimeType(mimeType); filedesc.setPath(path); filedesc.setName(name); filedesc.setUUID(uuid); return filedesc; }
From source file:ai.ilikeplaces.logic.sits9.SubscriberNotifications.java
@Timeout synchronized public void timeout(final Timer timer) throws IOException, SAXException, TransformerException, JSONException, SQLException { final HBaseCrudService<GeohashSubscriber> _geohashSubscriberHBaseCrudService = new HBaseCrudService<GeohashSubscriber>(); final HBaseCrudService<GeohashSubscriber>.Scanner _scanner = _geohashSubscriberHBaseCrudService .scan(new GeohashSubscriber(), 1).returnValueBadly(); while (_scanner.getNewValue() != null) { final String _newValue = _scanner.getNewValue(); Loggers.debug("Scanned value:" + _newValue); final RowResponse _rowResponse = new Gson().fromJson(_newValue, RowResponse.class); Loggers.debug("Scanned as GSON:" + _rowResponse.toString()); for (final Row _row : _rowResponse.Row) { final BASE64Decoder _base64DecoderRowKey = new BASE64Decoder(); final byte[] _bytes = _base64DecoderRowKey.decodeBuffer(_row.key); final String rowKey = new String(_bytes); Loggers.debug("Decoded row key:" + rowKey); for (final Cell _cell : _row.Cell) { final BASE64Decoder _base64DecoderValue = new BASE64Decoder(); final byte[] _valueBytes = _base64DecoderValue.decodeBuffer(_cell.$); final String _cellAsString = new String(_valueBytes); Loggers.debug("Cell as string:" + _cellAsString); final GeohashSubscriber _geohashSubscriber = new GeohashSubscriber(); final DatumReader<GeohashSubscriber> _geohashSubscriberSpecificDatumReader = new SpecificDatumReader<GeohashSubscriber>( _geohashSubscriber.getSchema()); final BinaryDecoder _binaryDecoder = DecoderFactory.get().binaryDecoder(_valueBytes, null); final GeohashSubscriber _read = _geohashSubscriberSpecificDatumReader.read(_geohashSubscriber, _binaryDecoder); Loggers.debug("Decoded value avro:" + _read.toString()); final Date now = new Date(); final Calendar _week = Calendar.getInstance(); _week.setTimeInMillis(now.getTime() + (7 * 24 * 60 * 60 * 1000)); final SimpleDateFormat _simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); _simpleDateFormat.format(_week.getTime()); final StringBuffer eventList = new StringBuffer(""); {//Eventful try { final SimpleDateFormat eventfulDate = new SimpleDateFormat("yyyyMMdd00"); _simpleDateFormat.format(_week.getTime()); final JSONObject jsonObject = Modules.getModules().getEventulFactory() .getInstance("http://api.eventful.com/json/events/search/") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("location", "" + _read.getLatitude() + "," + _read.getLongitude()); put("within", "" + 100); put("date", eventfulDate.format(Calendar.getInstance().getTime()) + "-" + eventfulDate.format(_week.getTime())); }/*from w w w .j a v a2 s. co m*/ } ); Loggers.debug("Eventful Reply:" + jsonObject.toString()); final JSONArray events = jsonObject.getJSONObject("events").getJSONArray("event"); final Document eventTemplateDocument = HTMLDocParser .getDocument(RBGet.getGlobalConfigKey("PAGEFILES") + SUBSCRIBER_EMAIL_EVENT); final String eventTemplate = HTMLDocParser .convertNodeToHtml(HTMLDocParser.$("content", eventTemplateDocument)); for (int i = 0; i < events.length(); i++) { final JSONObject eventJSONObject = new JSONObject(events.get(i).toString()); Double.parseDouble(eventJSONObject.getString(LATITUDE)); Double.parseDouble(eventJSONObject.getString(LONGITUDE)); final String eventName = eventJSONObject.getString("title"); final String eventUrl = eventJSONObject.getString("url"); final String eventDate = eventJSONObject.getString("start_time"); final String eventVenue = eventJSONObject.getString("venue_name"); Loggers.debug("Event name:" + eventName); eventList .append(eventTemplate .replace("_name_link_", !(("" + eventUrl).isEmpty()) ? eventUrl : ("https://www.google.com/search?q=" + eventName .replaceAll(" ", "+").replaceAll("-", "+"))) .replace("_place_link_", "https://maps.googleapis.com/maps/api/staticmap?sensor=false&size=600x600&markers=color:blue%7Clabel:S%7C" + _read.getLatitude().toString() + "," + _read.getLongitude().toString()) .replace("_name_", eventName).replace("_place_", eventVenue) .replace("_date_", eventDate)); } } catch (final Throwable t) { Loggers.error("Error appending Eventful data to Geohash Subscriber", t); } } {//Foursquare try { _simpleDateFormat.format(_week.getTime()); final JSONObject jsonObject = Modules.getModules().getEventulFactory() .getInstance("https://api.foursquare.com/v2/venues/explore") .get("", new HashMap<String, String>() { {//Don't worry, this is a static initializer of this map :) put("ll", "" + _read.getLatitude() + "," + _read.getLongitude()); put("radius", "" + 50000);//meters put("intent", "browse"); put("section", "topPicks"); put("client_secret", "PODRX5YWBSLAKAYRQ5CLPEPS3WHCXWFIJ3LXF3AKH4U1BDNI"); put("client_id", "25JZAK3TQPLIPUUXPIJWXQ5NSKSPTP4SYZLUZSCTZF3UJ4YX"); } } ); Loggers.debug("Foursquare Reply:" + jsonObject.toString()); final JSONArray referralArray = jsonObject.getJSONObject("response") .getJSONArray("groups").getJSONObject(0).getJSONArray("items"); final Document eventTemplateDocument = HTMLDocParser .getDocument(RBGet.getGlobalConfigKey("PAGEFILES") + SUBSCRIBER_EMAIL_PLACE); final String eventTemplate = HTMLDocParser .convertNodeToHtml(HTMLDocParser.$("content", eventTemplateDocument)); for (int i = 0; i < referralArray.length(); i++) { final JSONObject referral = referralArray.getJSONObject(i); referral.getJSONObject("venue").getJSONObject("location").getDouble("lng"); referral.getJSONObject("venue").getJSONObject("location").getDouble("lat"); final String eventName = referral.getJSONObject("venue").getString("name"); final String eventUrl = referral.getJSONObject("venue").optString("url"); final String eventVenue = referral.getJSONObject("venue").getJSONObject("location") .getString("address"); Loggers.debug("Event name:" + eventName); eventList .append(eventTemplate .replace("_name_link_", !(("" + eventUrl).isEmpty()) ? eventUrl : ("https://www.google.com/search?q=" + eventName .replaceAll(" ", "+").replaceAll("-", "+"))) .replace("_place_link_", "https://maps.googleapis.com/maps/api/staticmap?sensor=false&size=600x600&markers=color:blue%7Clabel:S%7C" + _read.getLatitude().toString() + "," + _read.getLongitude().toString()) .replace("_name_", eventName).replace("_place_", eventVenue) .replace("_date_", eventName)); } } catch (final Throwable t) { Loggers.error("Error appending Foursquare data to Geohash Subscriber", t); } } final String template = HTMLDocParser .getDocumentAsString(RBGet.getGlobalConfigKey("PAGEFILES") + EMAIL_FRAME); final Document email = HTMLDocParser .getDocument(RBGet.getGlobalConfigKey("PAGEFILES") + SUBSCRIBER_EMAIL); final String _content = HTMLDocParser.convertNodeToHtml(HTMLDocParser.$("content", email)); final Parameter _unsubscribeLink = new Parameter("http://www.ilikeplaces.com/unsubscribe/") .append(Unsubscribe.TYPE, Unsubscribe.Type.GeohashSubscribe.name(), true) .append(Unsubscribe.VALUE, rowKey); final String finalEmail = template.replace("_FrameContent_", _content.replace(" ___||_", eventList.toString()).replace("_unsubscribe_link_", _unsubscribeLink.get())); Loggers.debug("Final email:" + finalEmail); sendMailLocal.sendAsHTML(_read.getEmailId().toString(), "Thank God it's Friday!", finalEmail); } } _geohashSubscriberHBaseCrudService.scan(new GeohashSubscriber(), _scanner); } Loggers.debug("Completed scanner"); }
From source file:org.xaloon.wicket.component.repository.impl.FileRepositoryImpl.java
public FileDescription storeFileVersion(String path, String name, String mimeType, InputStream fileStream) throws NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException, Exception { FileDescription filedesc = null;//from www. j a v a 2 s . co m Session session = contentSessionFacade.getDefaultSession(); Node rootNode = session.getRootNode(); Node folder = (rootNode.hasNode(path)) ? rootNode.getNode(path) : RepositoryHelper.createFolder(session, path, rootNode); Node file = folder.addNode(name, JcrConstants.NT_FILE); file.addMixin(JcrConstants.MIX_VERSIONABLE); Node fileContent = file.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE); fileContent.setProperty(JcrConstants.JCR_MIMETYPE, mimeType); final Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(System.currentTimeMillis()); fileContent.setProperty(JcrConstants.JCR_LASTMODIFIED, lastModified); fileContent.setProperty(JcrConstants.JCR_DATA, fileStream); session.save(); final Version version = file.checkin(); filedesc = new FileDescription(); filedesc.setLastModified(lastModified.getTime()); filedesc.setMimeType(mimeType); filedesc.setPath(path); filedesc.setName(name); filedesc.setUUID(fileContent.getUUID()); filedesc.setFileVersion(version.getName()); // filedesc.setSize(file.getNode("jcr:content").getProperty("jcr:data").getLength()); return filedesc; }
From source file:net.sf.l2j.gameserver.instancemanager.clanhallsiege.BanditStrongholdSiege.java
private BanditStrongholdSiege() { _log.info("SiegeManager of Bandits Stronghold"); long siegeDate = restoreSiegeDate(35); Calendar tmpDate = Calendar.getInstance(); tmpDate.setTimeInMillis(siegeDate); setSiegeDate(tmpDate);// www . j ava 2 s . co m setNewSiegeDate(siegeDate, 35, 22); // Schedule siege auto start _startSiegeTask.schedule(1000); }