List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:org.opendatakit.odktables.DataManager.java
/** * Perform direct query on dateColToUseForCompare to retrieve the * SEQUENCE_VALUE of that row. This is then used to construct the query for * getting data with that using this start time. * //from ww w . j av a 2 s .c o m * @param logTable * - the log table to use * @param dateColToUseForCompare * - the date field to use for the comparison * @param givenTimestamp * - the original string value the user passed in * @param dateToCompare * - the date to compare against the LAST_UPDATE_DATE_COLUMN_NAME * @param dir * - the sort direction to use when retrieving the data * @return SEQUENCE_VALUE of that row * @throws ODKDatastoreException */ private String getSequenceValueForStartTime(DbLogTable logTable, String dateColToUseForCompare, String givenTimestamp, Date dateToCompare, Direction dir) throws ODKDatastoreException { Query query = logTable.query("DataManager.getSequenceValueForTimestamp", cc); // we need the filter to activate the sort for the sequence value query.addFilter(DbLogTable.SEQUENCE_VALUE, org.opendatakit.persistence.Query.FilterOperation.GREATER_THAN, " "); query.addSort(DbLogTable.SEQUENCE_VALUE, dir); // _LAST_UPDATE_DATE is a datetime field // _SAVEPOINT_TIMESTAMP is a String field if (dateColToUseForCompare.equals(DbLogTable.LAST_UPDATE_DATE_COLUMN_NAME)) { query.addFilter(dateColToUseForCompare, org.opendatakit.persistence.Query.FilterOperation.GREATER_THAN_OR_EQUAL, dateToCompare); } else if (dateColToUseForCompare.equals(DbLogTable.SAVEPOINT_TIMESTAMP.getName())) { query.addFilter(dateColToUseForCompare, org.opendatakit.persistence.Query.FilterOperation.GREATER_THAN_OR_EQUAL, givenTimestamp); } List<Entity> values = query.execute(); if (values == null || values.size() == 0) { throw new ODKEntityNotFoundException( "Timestamp " + dateToCompare.toString() + " was not found in log table!"); } Entity e = values.get(0); return e.getString(DbLogTable.SEQUENCE_VALUE); }
From source file:org.dbgl.gui.MainWindow.java
private void doImportDefaultTemplates(final boolean interactive) { if (!interactive || GeneralPurposeDialogs.confirmMessage(shell, settings.msg("dialog.importdefaulttemplates.confirm.start"))) { try {/*w w w . j a va 2 s.c om*/ if (checkDefaultDBVersion() == null) { return; } File defaultXml = FileUtils.getDefaultTemplatesXmlFile(); if (!FileUtils.isExistingFile(defaultXml)) throw new IOException(settings.msg("general.error.openfile", new Object[] { defaultXml })); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(defaultXml); XPath xPath = XPathFactory.newInstance().newXPath(); String packageVersion = xPath.evaluate("/document/export/format-version", doc); String packageTitle = xPath.evaluate("/document/export/title", doc); String packageAuthor = xPath.evaluate("/document/export/author", doc); String packageNotes = xPath.evaluate("/document/export/notes", doc); String creationApp = xPath.evaluate("/document/export/generator-title", doc); String creationAppVersion = xPath.evaluate("/document/export/generator-version", doc); Date creationDate = XmlUtils.datetimeFormatter .parse(xPath.evaluate("/document/export/creationdatetime", doc)); System.out .println(settings.msg("dialog.import.importing", new Object[] { StringUtils.join( new String[] { packageTitle, packageVersion, packageAuthor, packageNotes, creationApp, creationAppVersion, creationDate.toString() }, ' ') })); NodeList templateNodes = (NodeList) xPath.evaluate("/document/template", doc, XPathConstants.NODESET); java.util.List<ExpTemplate> templates = new ArrayList<ExpTemplate>(); SortedSet<DosboxVersion> dbSet = new TreeSet<DosboxVersion>(); for (int i = 0; i < templateNodes.getLength(); i++) { Element templateNode = (Element) templateNodes.item(i); Element dosbox = XmlUtils.getNode(templateNode, "dosbox"); DosboxVersion d = new DosboxVersion(i, XmlUtils.getTextValue(dosbox, "title"), "", "", true, false, false, "", XmlUtils.getTextValue(dosbox, "version"), null, null, null, 0); dbSet.add(d); templates.add(new ExpTemplate(templateNode, ImportDialog.getDosboxVersionId(d, dbSet))); } java.util.List<Integer> dbmapping = new ArrayList<Integer>(); for (DosboxVersion dbversion : dbSet) { dbmapping.add(dbversion.findBestMatchId(dbversionsList)); } ByteArrayOutputStream bos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(bos); Template addedTemplate = null; for (ExpTemplate template : templates) { template.setDbversionId( ImportDialog.getMappedDosboxVersionId(dbSet, dbmapping, template.getDbversionId())); DosboxVersion assocDBVersion = DosboxVersion.findById(dbversionsList, template.getDbversionId()); addedTemplate = dbase.addOrEditTemplate(template.getTitle(), template.getDbversionId(), template.isDefault(), -1); Conf gameConf = new Conf(template.getImportedFullConfig(), template.getImportedIncrConfig(), false, FileUtils.getDefaultTemplatesXmlFile().getPath(), addedTemplate.getId(), assocDBVersion, ps); gameConf.save(); } updateTemplateList(addedTemplate); if (bos.size() > 0) { GeneralPurposeDialogs.warningMessage(shell, bos.toString()); bos.reset(); } else { if (interactive) GeneralPurposeDialogs.infoMessage(shell, settings.msg("dialog.import.notice.importok")); } } catch (XPathExpressionException | SAXException e) { GeneralPurposeDialogs.fatalMessage(shell, settings.msg("dialog.importdefaulttemplates.error.defaultxmlinvalidformat", new Object[] { e.toString() }), e); } catch (Exception e) { GeneralPurposeDialogs.fatalMessage(shell, e.toString(), e); } } }
From source file:mom.trd.opentheso.bdd.helper.TermHelper.java
/** * Cette fonction permet de rcuprer l'historique d'un terme une date prcise * * @param ds/* w w w . j av a 2 s.com*/ * @param idTerm * @param idThesaurus * @param idLang * @param date * @return Objet class Concept */ public ArrayList<Term> getTermsHistoriqueFromDate(HikariDataSource ds, String idTerm, String idThesaurus, String idLang, Date date) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<Term> nodeTermList = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT lexical_value, modified, source, status, username FROM term_historique, users" + " WHERE id_term = '" + idTerm + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and term_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified DESC, lexical_value ASC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { nodeTermList = new ArrayList<>(); resultSet.next(); Term t = new Term(); t.setId_term(idTerm); t.setId_thesaurus(idThesaurus); t.setLexical_value(resultSet.getString("lexical_value")); t.setModified(resultSet.getDate("modified")); t.setSource(resultSet.getString("source")); t.setStatus(resultSet.getString("status")); t.setIdUser(resultSet.getString("username")); t.setLang(idLang); nodeTermList.add(t); } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting date historique of Term : " + idTerm, sqle); } return nodeTermList; }
From source file:com.ibm.cics.ca1y.Emit.java
/** * Using the key and pattern to identify a token, replace all tokens for the key value in the property. * // w w w . j a v a 2 s . c om * @param key * - The string to search for tokens * @param pattern * - The pattern to use to find tokens * @param props * - The properties to use as the lookup table * @param cicsChannel * - The channel to get containers from * @param channelDFHEP * - True if the name of the current CICS channel is identified as event processing * @param allowReevaluateForTokens * - reevaluated the key for tokens if at least one token was replaced with a value that could contain * another token * @return true if at least one token was replaced */ private static boolean resolveTokensInKey(String key, Pattern pattern, EmitProperties props, Channel cicsChannel, boolean channelDFHEP, boolean allowReevaluateForTokens) { if ((key == null) || (pattern == null) || (props == null) || (props.getProperty(key) == null)) { return false; } if (props.getPropertyResolved(key)) { // Property is already resolved if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("PropertyResolved") + " " + EmitProperties.getPropertySummary(props, key)); } return false; } if ((logger.isLoggable(Level.FINE))) { logger.fine( messages.getString("PropertyResolving") + " " + EmitProperties.getPropertySummary(props, key)); } // Do not change the order of the command options, as later processing relies on this order final String[] nomoretokensCommand = { "nomoretokens" }; final String[] noinnertokensCommand = { "noinnertokens" }; final String[] datetimeCommand = { "datetime=" }; final String[] mimeCommand = { "mime=", ":to=", ":xslt=" }; final String[] nameCommand = { "name=" }; final String[] responsecontainerCommand = { "responsecontainer=" }; final String[] fileCommand = { "file=", ":encoding=", ":binary", ":options=" }; final String[] zipCommand = { "zip=", ":include=" }; final String[] doctemplateCommand = { "doctemplate=", ":addPropertiesAsSymbols", ":binary" }; final String[] transformCommand = { "transform=", ":xmltransform=", ":jsontransform=", ":jvmserver=" }; final String[] ftpCommand = { "ftp=", ":server=", ":username=", ":userpassword=", ":transfer=", ":mode=", ":epsv=", ":protocol=", ":trustmgr=", ":datatimeout=", ":proxyserver=", ":proxyusername=", ":proxypassword=" }; final String[] hexCommand = { "hex=" }; final String[] systemsymbolCommand = { "systemsymbol=" }; final String[] commonBaseEventRESTCommand = { "commonbaseeventrest" }; final String[] commonBaseEventCommandCommand = { "commonbaseevent" }; final String[] cicsFlattenedEventCommand = { "cicsflattenedevent" }; final String[] jsonCommand = { "json", ":properties=" }; final String[] emitCommand = { "emit" }; final String[] linkCommand = { "link=" }; final String[] putcontainerCommand = { "putcontainer=" }; final String[] htmltableCommand = { "htmltable", ":properties=", ":containers=", ":summary" }; final String[] texttableCommand = { "texttable", ":properties=", ":containers=", ":summary" }; final String[] trimCommand = { "trim" }; final int maxTimesToResolveTokens = 10; boolean tokenReplaced = false; boolean allowPropertyToBeReevaluatedForTokens = true; String putContainer = null; // Indicate the property has been resolved at this point to prevent recursion resolving tokens within the // property props.setPropertyResolved(key, true); // As a token's replacement may itself contain tokens we need to iterate token searching, up to a maximum number // of times for (int i = 0; (i < maxTimesToResolveTokens) && (allowPropertyToBeReevaluatedForTokens); i++) { boolean reevaluateForTokens = false; Matcher matcher = pattern.matcher(props.getProperty(key)); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String token = matcher.group(1).trim(); if (logger.isLoggable(Level.FINE)) { logger.fine(Emit.messages.getString("ResolvingToken") + " " + token); } if (token.startsWith(nomoretokensCommand[0])) { // Do not process any more tokens in the key tokenReplaced = true; matcher.appendReplacement(buffer, ""); reevaluateForTokens = false; break; } else if (token.startsWith(noinnertokensCommand[0])) { // Processing all tokens in this property but prevent re-evaluation tokens in resolve tokens // eg. token is "noinntertokens" tokenReplaced = true; matcher.appendReplacement(buffer, ""); allowPropertyToBeReevaluatedForTokens = false; } else if (token.startsWith(transformCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, transformCommand); if (isCICS == false) { // if CICS API not available, ignore this token } else if (options[1] != null) { // eg. {transform=property:xmltranform=resource} try { Container inputContainer = cicsChannel.createContainer("CA1Y-TRANSFORM-I"); Container outputContainer = cicsChannel.createContainer("CA1Y-TRANSFORM-O"); if (props.getPropertyAttachment(options[0]) == null) { // property is text inputContainer.putString(props.getProperty(options[0])); } else { // property is binary inputContainer.put(props.getPropertyAttachment(options[0])); } XmlTransform xmltransform = new XmlTransform(options[1]); TransformInput transforminput = new TransformInput(); transforminput.setChannel(cicsChannel); transforminput.setDataContainer(inputContainer); transforminput.setXmlContainer(outputContainer); transforminput.setXmltransform(xmltransform); Transform.dataToXML(transforminput); buffer.append(new String(outputContainer.get(Emit.defaultCharset))); inputContainer.delete(); outputContainer.delete(); } catch (Exception e) { e.printStackTrace(); } } else if (options[2] != null) { // eg. {transform=propertyName:jsontransform=jsontransfrmResource:jvmserver=jvmResource} try { Container inputContainer = cicsChannel.createContainer("DFHJSON-DATA"); inputContainer.put(props.getPropertyAttachment(options[0])); inputContainer = cicsChannel.createContainer("DFHJSON-TRANSFRM"); inputContainer.putString(options[2]); if (options[3] != null) { inputContainer = cicsChannel.createContainer("DFHJSON-JVMSERVR"); inputContainer.putString(options[3]); } Program p = new Program(); p.setName("DFHJSON"); p.link(cicsChannel); Container outputContainer = (cicsChannel).createContainer("DFHSON-JSON"); buffer.append(outputContainer.get("UTF-8")); inputContainer.delete(); outputContainer.delete(); } catch (Exception e) { e.printStackTrace(); } } } else if (token.startsWith(mimeCommand[0])) { // Store the MIME type in the property // eg. token is "mime=application/octet-stream" // eg. token is "mime=application/xml" // eg. token is "mime=text/xsl:to=application/pdf" // eg. token is "mime=text/xml:to=application/pdf:xslt=xsltProperty" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, mimeCommand); props.setPropertyMime(key, options[0]); if (options[1] != null) { props.setPropertyMimeTo(key, options[1]); } if (options[2] != null) { props.setPropertyXSLT(key, options[2]); } } else if (token.startsWith(nameCommand[0])) { // Store the name in the property // eg. token is "name=My Picture" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, nameCommand); props.setPropertyAlternateName(key, options[0]); } else if (token.startsWith(datetimeCommand[0])) { // For tokens that start with DATETIME_PREFIX, replace the token with the resolved date and time // format // eg. token is "datetime=yyyy.MM.dd G 'at' HH:mm:ss z" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, datetimeCommand); Date date = null; if (props.containsKey("EPCX_ABSTIME")) { date = Util.getDateFromAbstime(props.getProperty("EPCX_ABSTIME")); } else { date = new Date(); } if (options[0].isEmpty()) { buffer.append(date.toString()); } else { buffer.append((new SimpleDateFormat(options[0])).format(date)); } } else if (token.startsWith(zipCommand[0])) { // Store the zip in the property // eg. token is "zip=" // eg. token is "zip=MyZip.zip" // eg. token is "zip=MyZip.zip:include=property1" // eg. token is "zip=MyZip.zip:include=property1,property2" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, zipCommand); if (options[0].isEmpty()) { props.setPropertyZip(key, key + ".zip"); } else { props.setPropertyZip(key, options[0]); } if (options[1] != null) { props.setPropertyZipInclude(key, options[1]); } else { props.setPropertyZipInclude(key, key); } } else if (token.startsWith(fileCommand[0])) { // Replace the token with the content of the file // eg. token is "file=//dataset" // eg. token is "file=//dataset:encoding=Cp1047" // eg. token is "file=//dataset:binary" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, fileCommand); if (options[0].startsWith("//")) { ZFile zf = null; if (options[2] != null) { try { // Read dataset in binary using IBM JZOS library zf = new ZFile(options[0], (options[3] == null) ? "rb" : options[3]); if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, zf.getActualFilename()); } if (props.getPropertyMime(key) == null) { props.setPropertyMimeDefault(key, zf.getActualFilename()); } props.setPropertyAttachment(key, IOUtils.toByteArray(zf.getInputStream())); } catch (Exception e) { e.printStackTrace(); } finally { if (zf != null) { try { zf.close(); } catch (Exception e2) { } } } } else { try { // Read dataset in text using IBM JZOS library zf = new ZFile(options[0], (options[3] == null) ? "r" : options[3]); if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, zf.getActualFilename()); } buffer.append(IOUtils.toString(zf.getInputStream(), (options[1] == null) ? ZUtil.getDefaultPlatformEncoding() : options[1])); reevaluateForTokens = true; } catch (Exception e) { e.printStackTrace(); } finally { if (zf != null) { try { zf.close(); } catch (Exception e2) { } } } } } else { File f = null; if (options[2] != null) { try { f = new File(options[0]); // Read zFS file as binary if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, f.getName()); } if (props.getPropertyMime(key) == null) { props.setPropertyMimeDefault(key, f.getName()); } props.setPropertyAttachment(key, FileUtils.readFileToByteArray(f)); } catch (Exception e) { e.printStackTrace(); } } else { try { // Read zFS file as text f = new File(options[0]); if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, f.getName()); } buffer.append(FileUtils.readFileToString(f, options[1])); reevaluateForTokens = true; } catch (Exception e) { e.printStackTrace(); } } } } else if (token.startsWith(doctemplateCommand[0])) { // Replace the token with the contents of the CICS document template resource // eg. token is "doctemplate=MyTemplate" // eg. token is "doctemplate=MyTemplate:addPropertiesAsSymbols" // eg. token is "doctemplate=MyTemplate:binary" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, doctemplateCommand); if (options[2] == null) { try { // Read doctemplate as text if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, options[0]); } Document document = new Document(); if (options[1] != null) { // Add all properties except the current property as symbols to document Enumeration<?> e = props.propertyNamesOrdered(); while (e.hasMoreElements()) { String key2 = (String) e.nextElement(); // Only add property if it is not the current key and is not private if ((key.equals(key2) == false) && (props.getPropertyPrivacy(key2) == false)) { try { if ((props.getPropertyResolved(key2) == false) && (allowPropertyToBeReevaluatedForTokens)) { // resolve the token before attempting to use it resolveTokensInKey(key2, pattern, props, cicsChannel, channelDFHEP, allowReevaluateForTokens); } document.addSymbol(key2, props.getProperty(key2)); } catch (Exception e2) { // Continue even if there are errors adding a symbol } } } } document.createTemplate(options[0]); buffer.append(new String(document.retrieve("UTF-8", true), "UTF-8")); reevaluateForTokens = true; } catch (Exception e) { e.printStackTrace(); } } else { try { // Read doctemplate as binary if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, options[0]); } if (props.getPropertyMime(key) == null) { props.setPropertyMimeDefault(key, options[0]); } Document document = new Document(); document.createTemplate(options[0]); props.setPropertyAttachment(key, document.retrieve()); } catch (Exception e) { e.printStackTrace(); } } } else if (token.startsWith(commonBaseEventRESTCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); buffer.append(getCommonBaseEventREST(props)); reevaluateForTokens = true; if (props.getPropertyMime(key) == null) { props.setPropertyMime(key, MIME_XML); } } else if (token.startsWith(commonBaseEventCommandCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); buffer.append(getCommonBaseEvent(props)); reevaluateForTokens = true; if (props.getPropertyMime(key) == null) { props.setPropertyMime(key, MIME_XML); } } else if (token.startsWith(cicsFlattenedEventCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); buffer.append(getCicsFlattenedEvent(props)); reevaluateForTokens = true; } else if (token.startsWith(jsonCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, jsonCommand); buffer.append(getJson(props, options[1])); reevaluateForTokens = true; if (props.getPropertyMime(key) == null) { props.setPropertyMime(key, MIME_JSON); } } else if (token.startsWith(htmltableCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, htmltableCommand); buffer.append(getHtmlTable(props, options[1], options[2], options[3], isCICS)); } else if (token.startsWith(texttableCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, texttableCommand); buffer.append(getTextTable(props, options[1], options[2], options[3])); } else if (token.startsWith(ftpCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, ftpCommand); String defaultanonymouspassword = null; if (isCICS) { defaultanonymouspassword = channelDFHEP ? props.getProperty("EPCX_USERID") : props.getProperty("TASK_USERID"); if (defaultanonymouspassword != null) { try { defaultanonymouspassword = (new StringBuilder( String.valueOf(defaultanonymouspassword))).append("@") .append(InetAddress.getLocalHost().getHostName()).toString(); } catch (Exception _ex) { } } } byte b[] = getFileUsingFTP(options[0], options[1], options[2], options[3], options[4], options[5], options[6], options[7], options[8], options[9], options[10], options[11], options[12], defaultanonymouspassword); if (b != null) { if ("binary".equalsIgnoreCase(options[4])) { String filename = FilenameUtils.getName(options[0]); if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, filename); } if (props.getPropertyMime(key) == null) { props.setPropertyMimeDefault(key, filename); } props.setPropertyAttachment(key, b); } else { try { buffer.append(new String(b, "US-ASCII")); reevaluateForTokens = true; } catch (Exception _ex) { // Ignore } } } } else if (token.startsWith(responsecontainerCommand[0])) { // Store the name in the property // eg. token is "responsecontainer=" // eg. token is "responsecontainer=MyContainer" tokenReplaced = true; matcher.appendReplacement(buffer, ""); String[] options = Util.getOptions(token, responsecontainerCommand); props.setPropertyReturnContainer(key, (options[0].isEmpty()) ? key : options[0]); } else if (token.startsWith(hexCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, hexCommand); if (props.getProperty(options[0]) != null) { buffer.append(Util.getHex(props.getProperty(options[0]).getBytes())); } else { if (props.getPropertyAttachment(options[0]) != null) buffer.append(Util.getHex(props.getPropertyAttachment(options[0]))); } } else if (token.startsWith(emitCommand[0])) { // Set this property to be emitted tokenReplaced = true; matcher.appendReplacement(buffer, ""); props.putBusinessInformationItem(key, 0); } else if (token.startsWith(systemsymbolCommand[0])) { // Get the z/OS system symbol tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, systemsymbolCommand); try { buffer.append(Util.getSystemSymbol(options[0])); } catch (Exception e) { } } else if (token.startsWith(linkCommand[0])) { // Link to CICS program tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, linkCommand); if (isCICS) { // Only execute if CICS API is available if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("LinkTo") + " " + options[0]); } Program p = new Program(); p.setName(options[0]); try { p.link(cicsChannel); } catch (Exception e) { e.printStackTrace(); } } } else if (token.startsWith(putcontainerCommand[0])) { // Put the value of this property into a CICS container once the tokens have been resolve tokenReplaced = true; matcher.appendReplacement(buffer, ""); String options[] = Util.getOptions(token, putcontainerCommand); putContainer = options[0]; } else if (token.startsWith(trimCommand[0])) { tokenReplaced = true; matcher.appendReplacement(buffer, ""); // Remove leading and training spaces from the buffer up to the point of the token buffer = new StringBuffer(buffer.toString().trim()); } else if (props.containsKey(token)) { // The token refers to a property tokenReplaced = true; matcher.appendReplacement(buffer, ""); // Do not copy property if it is the current key or it is marked as private if ((key.equals(token) == false) && (props.getPropertyPrivacy(key) == false)) { if ((props.getPropertyResolved(token) == false) && (allowPropertyToBeReevaluatedForTokens)) { // Resolve the tokens in the property before attempting to use it resolveTokensInKey(token, pattern, props, cicsChannel, channelDFHEP, allowReevaluateForTokens); } if (props.getPropertyAttachment(token) == null) { // Copy the tokens' property buffer.append(props.getProperty(token)); } else { // Copy the tokens' property attachment if (props.getPropertyAttachment(key) == null) { // current property does not have an attachment props.setPropertyAttachment(key, Arrays.copyOf(props.getPropertyAttachment(token), props.getPropertyAttachment(token).length)); } else { // Current property has an attachment, so append the tokens' attachment ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { outputStream.write(props.getPropertyAttachment(key)); outputStream.write(props.getPropertyAttachment(token)); } catch (Exception e) { } props.setPropertyAttachment(key, outputStream.toByteArray()); } } props.setPropertyAlternateName(key, props.getPropertyAlternateName(token)); } } else if (System.getProperty(token) != null) { // The token refers to a system property tokenReplaced = true; matcher.appendReplacement(buffer, ""); buffer.append(System.getProperty(token)); } else if (isCICS && (token.getBytes().length >= CONTAINER_NAME_LENGTH_MIN) && (token.getBytes().length <= CONTAINER_NAME_LENGTH_MAX)) { // If this is not an EP event and the token is a max of 16 characters, attempt to replace token with // contents of the CICS container named by the token in current channel tokenReplaced = true; matcher.appendReplacement(buffer, ""); if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("GetContainer") + " " + token); } try { Container container = (cicsChannel).createContainer(token); try { // Assume container is of type CHAR and get CICS to convert it buffer.append(container.getString()); reevaluateForTokens = true; } catch (CodePageErrorException e) { // As container could not be converted, assume it is of type BIT and copy the contents into // an attachment if (props.getPropertyAttachment(key) == null) { props.setPropertyAttachment(key, container.get()); } else { // Append the property named by token to the existing attachment ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { outputStream.write(props.getPropertyAttachment(key)); outputStream.write(container.get()); } catch (Exception e2) { } props.setPropertyAttachment(key, outputStream.toByteArray()); } } if (props.getPropertyAlternateName(key) == null) { props.setPropertyAlternateName(key, token); } } catch (Exception e) { if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("GetContainerError") + " " + token); } } } else { // Token could not be resolved, so just remove it matcher.appendReplacement(buffer, ""); if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("UnResolvedToken") + " " + token); } } } matcher.appendTail(buffer); props.setProperty(key, buffer.toString()); if ((reevaluateForTokens == false) || (allowReevaluateForTokens == false)) { break; } } if ((isCICS) && (putContainer != null) && (putContainer.length() >= CONTAINER_NAME_LENGTH_MIN) && (putContainer.length() <= CONTAINER_NAME_LENGTH_MAX)) { try { Container container = cicsChannel.createContainer(putContainer); if (props.getPropertyAttachment(key) == null) { // Create a container of type CHAR. // Should use container.putString but this was only added in // CICS TS V5.1 if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("PutContainerChar") + " " + putContainer); } container.putString(props.getProperty(key)); } else { // Creates a container of type BIT if (logger.isLoggable(Level.FINE)) { logger.fine(messages.getString("PutContainerBit") + " " + putContainer); } container.put(props.getPropertyAttachment(key)); } } catch (Exception e) { e.printStackTrace(); } } if (logger.isLoggable(Level.FINE) && (tokenReplaced)) { logger.fine( messages.getString("PropertyReplaced") + " " + EmitProperties.getPropertySummary(props, key)); } return tokenReplaced; }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
@Override public void onDateComplete(Date tripDate, boolean arriveBy) { this.mTripDate = tripDate; this.mArriveBy = arriveBy; String tripTime = tripDate.toString() + arriveBy; Log.v(OTPApp.TAG, tripTime);/*from w ww. ja v a 2 s . c om*/ }
From source file:edu.usf.cutr.opentripplanner.android.fragments.MainFragment.java
@Override public boolean onOptionsItemSelected(final MenuItem pItem) { OTPApp app = ((OTPApp) getActivity().getApplication()); switch (pItem.getItemId()) { case R.id.gps_settings: Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(myIntent);/*from www .j a v a2s . c o m*/ break; case R.id.settings: getActivity().startActivityForResult(new Intent(getActivity(), SettingsActivity.class), OTPApp.SETTINGS_REQUEST_CODE); break; case R.id.feedback: Server selectedServer = app.getSelectedServer(); String[] recipients = { selectedServer.getContactEmail(), getString(R.string.feedback_email_android_developer) }; String uriText = "mailto:"; for (String recipient : recipients) { uriText += recipient + ";"; } String subject = ""; subject += getResources().getString(R.string.menu_button_feedback_subject); Date d = Calendar.getInstance().getTime(); subject += "[" + d.toString() + "]"; uriText += "?subject=" + subject; String content = ((MyActivity) getActivity()).getCurrentRequestString(); try { uriText += "&body=" + URLEncoder.encode(content, OTPApp.URL_ENCODING); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); return false; } Uri uri = Uri.parse(uriText); Intent sendIntent = new Intent(Intent.ACTION_SENDTO); sendIntent.setData(uri); startActivity(Intent.createChooser(sendIntent, getResources().getString(R.string.menu_button_feedback_send_email))); break; case R.id.server_info: Server server = app.getSelectedServer(); if (server == null) { Log.w(OTPApp.TAG, "Tried to get server info when no server was selected"); Toast.makeText(mApplicationContext, mApplicationContext.getResources().getString(R.string.toast_no_server_selected_error), Toast.LENGTH_SHORT).show(); break; } WeakReference<Activity> weakContext = new WeakReference<Activity>(getActivity()); ServerChecker serverChecker = new ServerChecker(weakContext, mApplicationContext, true); serverChecker.execute(server); break; default: break; } return false; }
From source file:mom.trd.opentheso.bdd.helper.TermHelper.java
/** * Cette fonction permet de rcuprer l'historique des termes synonymes d'un terme une date prcise * * @param ds//from w ww. jav a 2 s.c om * @param idTerm * @param idThesaurus * @param idLang * @param date * @return Objet class Concept */ public ArrayList<NodeEM> getNonPreferredTermsHistoriqueFromDate(HikariDataSource ds, String idTerm, String idThesaurus, String idLang, Date date) { Connection conn; Statement stmt; ResultSet resultSet; ArrayList<NodeEM> nodeEMList = null; try { // Get connection from pool conn = ds.getConnection(); try { stmt = conn.createStatement(); try { String query = "SELECT lexical_value, modified, source, status, hiden, action, username FROM non_preferred_term_historique, users" + " WHERE id_term = '" + idTerm + "'" + " and id_thesaurus = '" + idThesaurus + "'" + " and lang ='" + idLang + "'" + " and non_preferred_term_historique.id_user=users.id_user" + " and modified <= '" + date.toString() + "' order by modified, lexical_value ASC"; stmt.executeQuery(query); resultSet = stmt.getResultSet(); if (resultSet != null) { nodeEMList = new ArrayList<>(); while (resultSet.next()) { if (resultSet.getString("action").equals("DEL")) { for (NodeEM nem : nodeEMList) { if (nem.getLexical_value().equals(resultSet.getString("lexical_value")) && nem.getAction().equals("ADD") && nem.getStatus().equals(resultSet.getString("status"))) { nodeEMList.remove(nem); break; } } } else { NodeEM nodeEM = new NodeEM(); nodeEM.setLexical_value(resultSet.getString("lexical_value")); nodeEM.setModified(resultSet.getDate("modified")); nodeEM.setSource(resultSet.getString("source")); nodeEM.setStatus(resultSet.getString("status")); nodeEM.setHiden(resultSet.getBoolean("hiden")); nodeEM.setAction(resultSet.getString("action")); nodeEM.setIdUser(resultSet.getString("username")); nodeEM.setLang(idLang); nodeEMList.add(nodeEM); } } } } finally { stmt.close(); } } finally { conn.close(); } } catch (SQLException sqle) { // Log exception log.error("Error while getting NonPreferedTerm date historique of Term : " + idTerm, sqle); } return nodeEMList; }
From source file:eu.europa.esig.dss.cades.validation.CAdESSignature.java
@Override public Date getSigningTime() { final AttributeTable attributes = signerInformation.getSignedAttributes(); if (attributes == null) { return null; }/* w w w . ja v a2s.com*/ final Attribute attr = attributes.get(PKCSObjectIdentifiers.pkcs_9_at_signingTime); if (attr == null) { return null; } final ASN1Set attrValues = attr.getAttrValues(); final ASN1Encodable attrValue = attrValues.getObjectAt(0); final Date signingDate; if (attrValue instanceof ASN1UTCTime) { signingDate = DSSASN1Utils.toDate((ASN1UTCTime) attrValue); } else if (attrValue instanceof Time) { signingDate = ((Time) attrValue).getDate(); } else if (attrValue instanceof ASN1GeneralizedTime) { signingDate = DSSASN1Utils.toDate((ASN1GeneralizedTime) attrValue); } else { signingDate = null; } if (signingDate != null) { /* * RFC 3852 [4] states that "dates between January 1, 1950 and * December 31, 2049 (inclusive) must be encoded as UTCTime. Any * dates with year values before 1950 or after 2049 must be encoded * as GeneralizedTime". */ if (!(signingDate.before(JANUARY_1950) && signingDate.after(JANUARY_2050))) { // must be ASN1UTCTime if (!(attrValue instanceof ASN1UTCTime)) { LOG.error( "RFC 3852 states that dates between January 1, 1950 and December 31, 2049 (inclusive) must be encoded as UTCTime. Any dates with year values before 1950 or after 2049 must be encoded as GeneralizedTime. Date found is {} encoded as {}", signingDate.toString(), attrValue.getClass()); return null; } } return signingDate; } if (LOG.isErrorEnabled()) { LOG.error("Error when reading signing time. Unrecognized " + attrValue.getClass()); } return null; }
From source file:org.apache.hadoop.hive.service.HSSessionItem.java
public synchronized boolean isInactive() { boolean res = true; Date currentDate = new Date(); lock.lock();/*from w w w . ja v a2 s . c o m*/ try { Iterator<TTransport> i = transSet.iterator(); while (i.hasNext()) { TTransport trans = (TTransport) i.next(); if (trans.isOpen() == true) { res = false; } else { l4j.info("Session " + sessionName + " Connection disconnected!"); i.remove(); } } } finally { lock.unlock(); } if (!res) { if (this.runSqlCnt == 0) { if (this.freedate == null) { this.freedate = new Date(); } else { if (currentDate.getTime() - this.freedate.getTime() >= 300 * 1000) { if (dayLogStream != null) { dayLogStream.print("update session log, the connection is still alive"); dayLogStream.print('\n'); dayLogStream.flush(); } this.freedate = new Date(); } } } return false; } if (config.timer != null) { return false; } if (currentDate.getTime() - opdate.getTime() >= to * 1000) { l4j.info("Time @ " + currentDate.toString() + " Set empty: " + Boolean.toString((transSet.isEmpty()))); return true; } else return false; }
From source file:ome.formats.importer.gui.HistoryTableStore.java
public DefaultListModel getBaseTableDataByDate(Date start, Date end) { try {// w w w . j av a 2s.c om // Format the current time. String dayString, hourString, status; long uid = 0L, importTime = 0L; String icon; DefaultListModel list = new DefaultListModel(); String searchString = "(DateTime>=" + start.getTime() + ") & (DateTime<=" + end.getTime() + ")"; long[] ids = baseTable.getWhereList(searchString, null, 0, baseTable.getNumberOfRows(), 1); int returnedRows = ids.length; if (DEBUG) log.debug("getBaseTableDataByDate returned rows: " + returnedRows); Data d = getBaseTableData(); if (d == null) { log.error("Error retrieving base table data."); return new DefaultListModel(); } LongColumn uids = (LongColumn) d.columns[BASE_UID_COLUMN]; LongColumn importTimes = (LongColumn) d.columns[BASE_DATETIME_COLUMN]; StringColumn statuses = (StringColumn) d.columns[BASE_STATUS_COLUMN]; for (int h = 0; h < returnedRows; h++) { int i = (int) ids[h]; try { uid = uids.values[i]; importTime = importTimes.values[i]; status = statuses.values[i].trim(); } catch (ArrayIndexOutOfBoundsException e) { System.err.println("ids[" + h + "] not found in dataset."); continue; } if (status.equals("complete")) icon = "gfx/import_done_16.png"; else icon = "gfx/warning_msg16.png"; dayString = day.format(new Date(importTime)); hourString = hour.format(new Date(importTime)); if (day.format(new Date()).equals(dayString)) dayString = "Today"; if (day.format(getYesterday()).equals(dayString)) { dayString = "Yesterday"; } ImportEntry entry = new ImportEntry(dayString + " " + hourString, icon, (int) uid); list.addElement(entry); } return list; } catch (Exception e) { String s = String.format("Error retrieving base list from %s to %s.", start.toString(), end.toString()); log.error(s, e); } return new DefaultListModel(); // return empty defaultlist }