List of usage examples for java.util Date getYear
@Deprecated public int getYear()
From source file:br.com.nverse.sac.controllers.NewClienteCtrl.java
public void setDatFim(ValueChangeEvent e) { Date d = (Date) e.getNewValue(); d.setYear(d.getYear() + 1); contrato.setDataFim(d); }
From source file:com.krawler.common.util.StringUtil.java
public static Boolean issameDatesExTime(Date olddate, String newdatestr) { Date newdate = new Date(newdatestr); return newdate.getDate() == olddate.getDate() && newdate.getYear() == olddate.getYear() && newdate.getMonth() == olddate.getMonth(); }
From source file:org.openmrs.module.drugorderexport.web.controller.StartTreatmentController.java
/** * @see org.springframework.web.servlet.mvc.AbstractFormController#handleRequestInternal(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *///from w w w . j a va 2 s .c o m @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { // TODO Auto-generated method stub Map<String, Object> map = new HashMap<String, Object>(); List<Patient> patientsExport = new ArrayList<Patient>(); List<Object[]> objectsList = new ArrayList<Object[]>(); String checkedValueStr[] = null; int checkedValue = 0; if (request.getParameterValues("checkValue") != null) { checkedValueStr = request.getParameterValues("checkValue"); checkedValue = Integer.parseInt(checkedValueStr[0]); } if (request.getMethod().equalsIgnoreCase("post")) { List<Integer> patientIds = new ArrayList<Integer>(); Date startDate = null; Date endDate = null; DrugOrderService service = Context.getService(DrugOrderService.class); String startD = request.getParameter("startdate"); String endD = request.getParameter("enddate"); String gender = request.getParameter("gender"), minAge = request.getParameter("minAge"), maxAge = request.getParameter("maxAge"), minBirthdate = request.getParameter("minBirthdate"), maxBirthdate = request.getParameter("maxBirthdate"); SimpleDateFormat df = OpenmrsUtil.getDateFormat(); Date mnBirthdate = null; Date mxBirthdate = null; Date mnAge = null; Date mxAge = null; if (startD != null && startD.length() != 0) { startDate = df.parse(startD); } if (endD != null && endD.length() != 0) { endDate = df.parse(endD); } if (minBirthdate != null && minBirthdate.length() != 0) { mnBirthdate = df.parse(minBirthdate); } if (maxBirthdate != null && maxBirthdate.length() != 0) { mxBirthdate = df.parse(maxBirthdate); } if (maxAge != null && maxAge.length() != 0) { mxAge = service.getDateObjectFormAge(Integer.parseInt(maxAge)); } if (minAge != null && minAge.length() != 0) { mnAge = service.getDateObjectFormAge(Integer.parseInt(minAge)); } String arvDrugConceptIds = DrugOrderExportUtil.gpGetARVConceptIds(); patientIds = service.getPatientWhoStartedOnDate(startDate, endDate, gender, mnAge, mxAge, mnBirthdate, mxBirthdate); List<Integer> list = new ArrayList<Integer>(); if (checkedValue == 1) { if (endDate == null) endDate = new Date(); patientIds = service.getActiveOnDrugsPatients(patientIds, arvDrugConceptIds, endDate); } for (Integer patientId : patientIds) { Patient patient = new Patient(); patient = Context.getPatientService().getPatient(patientId); if (!patient.getVoided()) patientsExport.add(patient); Date startTreatmentDate = null; Date lastEncounterDate = null; Date lastVisitDate = null; String startTreatmentDateStr = ""; String lastEncounterDateStr = ""; String lastVisitDateStr = ""; if (service.getPatientLastVisitDate(patientId) != null) { lastVisitDate = service.getPatientLastVisitDate(patientId); lastVisitDateStr = lastVisitDate.toString(); } if (service.getWhenPatStartedXRegimen(patientId, DrugOrderExportUtil.gpGetARVDrugsIds()) != null) { startTreatmentDate = service.getWhenPatientStarted(patient); startTreatmentDateStr = startTreatmentDate.toString(); } if (service.getPatientLastEncounterDate(patientId) != null) { lastEncounterDate = service.getPatientLastEncounterDate(patientId); lastEncounterDateStr = lastEncounterDate.toString(); } objectsList.add(new Object[] { Context.getPersonService().getPerson(patientId), startTreatmentDateStr, lastEncounterDateStr, lastVisitDateStr }); } // for data exportation if (request.getParameter("export") != null && !request.getParameter("export").equals("")) { if (Context.getAuthenticatedUser().hasPrivilege("Export Collective Patient Data")) { if (request.getParameter("export").equals("excel")) DrugOrderExportUtil.exportData(request, response, patientsExport); if (request.getParameter("export").equals("pdf")) DrugOrderExportUtil.exportToPDF(request, response, patientsExport); } else map.put("msg", "Required Privilege : [Export Collective Patient Data]"); } map.put("objectsList", objectsList); map.put("collectionSize", patientsExport.size()); map.put("checkedValueExport", checkedValue); Date now = new Date(); if (startDate != null) map.put("startdate", df.format(startDate)); if (endDate != null) map.put("enddate", df.format(endDate)); if (gender.equals("f")) map.put("gender", "Female"); else if (gender.equals("")) map.put("gender", "Any"); else map.put("gender", "Male"); if (mnAge != null) map.put("minAge", now.getYear() - mnAge.getYear()); if (mxAge != null) map.put("maxAge", now.getYear() - mxAge.getYear()); if (mnBirthdate != null) map.put("minBirthdate", df.format(mnBirthdate)); if (mxBirthdate != null) map.put("maxBirthdate", df.format(mxBirthdate)); } return new ModelAndView(getViewName(), map); }
From source file:com.vkassin.mtrade.Common.java
public static void putOrder(final Context ctx, Quote quote) { final Instrument it = Common.selectedInstrument;// adapter.getItem(selectedRowId); final Dialog dialog = new Dialog(ctx); dialog.setContentView(R.layout.order_dialog); dialog.setTitle(R.string.OrderDialogTitle); datetxt = (EditText) dialog.findViewById(R.id.expdateedit); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); Date dat1 = new Date(); datetxt.setText(sdf.format(dat1));//from ww w. j av a 2 s . c o m mYear = dat1.getYear() + 1900; mMonth = dat1.getMonth(); mDay = dat1.getDate(); final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime(); datetxt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Log.i(TAG, "Show DatePickerDialog"); DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay); dpd.show(); } }); TextView itext = (TextView) dialog.findViewById(R.id.instrtext); itext.setText(it.symbol); final Spinner aspinner = (Spinner) dialog.findViewById(R.id.acc_spinner); List<String> list = new ArrayList<String>(Common.getAccountList()); ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Common.app_ctx, android.R.layout.simple_spinner_item, list); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item); aspinner.setAdapter(dataAdapter); final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit); final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit); final Button buttonpm = (Button) dialog.findViewById(R.id.buttonPriceMinus); buttonpm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { double price = Double.valueOf(pricetxt.getText().toString()); price -= 0.01; if (price < 0) price = 0; pricetxt.setText(twoDForm.format(price)); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show(); } } }); final Button buttonpp = (Button) dialog.findViewById(R.id.buttonPricePlus); buttonpp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { double price = Double.valueOf(pricetxt.getText().toString()); price += 0.01; pricetxt.setText(twoDForm.format(price)); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show(); } } }); final Button buttonqm = (Button) dialog.findViewById(R.id.buttonQtyMinus); buttonqm.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { long qty = Long.valueOf(quanttxt.getText().toString()); qty -= 1; if (qty < 0) qty = 0; quanttxt.setText(String.valueOf(qty)); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show(); } } }); final Button buttonqp = (Button) dialog.findViewById(R.id.buttonQtyPlus); buttonqp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { long qty = Long.valueOf(quanttxt.getText().toString()); qty += 1; quanttxt.setText(String.valueOf(qty)); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show(); } } }); final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0); final RadioButton bu1 = (RadioButton) dialog.findViewById(R.id.radio1); if (quote != null) { // pricetxt.setText(quote.price.toString()); pricetxt.setText(quote.getPriceS()); if (quote.qtyBuy > 0) { quanttxt.setText(quote.qtyBuy.toString()); bu1.setChecked(true); bu0.setChecked(false); } else { quanttxt.setText(quote.qtySell.toString()); bu1.setChecked(false); bu0.setChecked(true); } } Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt); customDialog_Cancel.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { dialog.dismiss(); } }); Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder); customDialog_Put.setOnClickListener(new Button.OnClickListener() { public void onClick(View arg0) { Double price = new Double(0); Long qval = new Long(0); try { price = Double.valueOf(pricetxt.getText().toString()); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show(); return; } try { qval = Long.valueOf(quanttxt.getText().toString()); } catch (Exception e) { Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show(); return; } if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay).getTime()) > 0) { Toast.makeText(ctx, R.string.CorrectDate, Toast.LENGTH_SHORT).show(); return; } JSONObject msg = new JSONObject(); try { msg.put("objType", Common.CREATE_REMOVE_ORDER); msg.put("time", Calendar.getInstance().getTimeInMillis()); msg.put("version", Common.PROTOCOL_VERSION); msg.put("device", "Android"); msg.put("instrumId", Long.valueOf(it.id)); msg.put("price", price); msg.put("qty", qval); msg.put("ordType", 1); msg.put("side", bu0.isChecked() ? 0 : 1); msg.put("code", String.valueOf(aspinner.getSelectedItem())); msg.put("orderNum", ++ordernum); msg.put("action", "CREATE"); boolean b = (((mYear - 1900) == dat.getYear()) && (mMonth == dat.getMonth()) && (mDay == dat.getDate())); if (!b) msg.put("expired", String.format("%02d.%02d.%04d", mDay, mMonth + 1, mYear)); if (isSSL) { // ? ?: newOrder-orderNum-instrumId-side-price-qty-code-ordType // : newOrder-16807-20594623-0-1150-13-1027700451-1 String forsign = "newOrder-" + ordernum + "-" + msg.getString("instrumId") + "-" + msg.getString("side") + "-" + JSONObject.numberToString(Double.valueOf(msg.getDouble("price"))) + "-" + msg.getString("qty") + "-" + msg.getString("code") + "-" + msg.getString("ordType"); byte[] signed = Common.signText(Common.signProfile, forsign.getBytes(), true); String gsign = Base64.encodeToString(signed, Base64.DEFAULT); msg.put("gostSign", gsign); } mainActivity.writeJSONMsg(msg); } catch (Exception e) { e.printStackTrace(); Log.e(TAG, "Error! Cannot create JSON order object", e); } dialog.dismiss(); } }); dialog.show(); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.getWindow().setAttributes(lp); }
From source file:br.com.nverse.sac.controllers.NewClienteCtrl.java
private void inicializarVariaveis() { Date data = this.cliente.getDataCadastro(); String mes = data.getMonth() < 10 ? "0" + data.getMonth() : data.getMonth() + ""; int ano = data.getYear() + 1900; String dia = data.getDate() < 10 ? "0" + data.getDate() : data.getDate() + ""; dataCadastro = dia + "/" + mes + "/" + ano; agregadoAtual = new Agregado(); veiculo = new Veiculo(); representante = new Representante(); contrato = new Contrato(); historiaAtual = new Historico(); }
From source file:ca.oson.json.gson.functional.DefaultTypeAdaptersTest.java
@SuppressWarnings("deprecation") private void assertEqualsDate(Date date, int year, int month, int day) { assertEquals(year - 1900, date.getYear()); assertEquals(month, date.getMonth()); assertEquals(day, date.getDate());/*from www . j av a 2 s . c o m*/ }
From source file:pa_SymposiumPlanner.RuleML2010RRChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from w w w . j a va2 s . c o m address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("RR Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } try { Types.reset(); RDFSParser.parseRDFSString(typestr); } catch (Exception e) { e.printStackTrace(); } try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println("nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:pa_SymposiumPlanner.BRF2011RRChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {/* ww w .ja va 2 s .co m*/ address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("RR Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); // BackwardReasoner br = new BackwardReasoner(); // Iterator solit =null; // DefiniteClause dc = null; // SymbolTable.reset(); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); // Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:pa_SymposiumPlanner.BRF2011PublicityChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from w ww .j ava 2 s . c o m address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("Publicty Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); //Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); br.loadClauses(pp.iterator()); //System.out.println("TEST"); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }
From source file:pa_SymposiumPlanner.RuleML2010PublicityChair.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html; charset=UTF-8"); PrintWriter out = response.getWriter(); try {//from ww w .j a v a 2 s .co m address = PAConfiguration.getAddress(); port = PAConfiguration.getPort(instantiation); poslAddress = PAConfiguration.getPOSL(instantiation, topic); rdfAddress = PAConfiguration.getRDFTaxonomy(instantiation); messageEndpoint = PAConfiguration.getEndpointName(instantiation, topic); } catch (BadConfigurationException e) { System.out.println(e.getMessage()); e.printStackTrace(); System.exit(0); } try { System.out.println("Publicty Chair Servlet"); System.out.println(response.toString()); BufferedReader brd = request.getReader(); String input = ""; String message = ""; while (!input.equals("</RuleML>")) { input = brd.readLine(); message = message + input; } String[] varOrder = getVariableOrder(message); System.out.println("Received Message: " + message); POSLParser pp = new POSLParser(); // String contents = "c(a).\nc(b).\nc(c)."; Date t1 = new GregorianCalendar().getTime(); System.out.println(t1.getHours() + ":" + t1.getMinutes()); //append time to contents System.out.println("day: " + t1.getDay()); System.out.println("day: " + t1.getYear()); System.out.println("day: " + t1.getMonth()); //time String time = "time(" + t1.getHours() + ":integer)."; System.out.println(time); String url = poslAddress; //String url = "http://www.jdrew.org/oojdrew/test.posl"; String contents = ""; //day of the week int day = t1.getDay(); boolean weekday = true; if (day == 0 || day == 6) { weekday = false; } String dayOfWeek; if (weekday) { dayOfWeek = "day(weekday)."; } else { dayOfWeek = "day(weekend)."; } //full date Calendar cal = new GregorianCalendar(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day2 = cal.get(Calendar.DAY_OF_MONTH); String date; String day3 = "" + day2; if (day2 == 1 || day2 == 2 || day2 == 3 || day2 == 4 || day2 == 5 || day2 == 6 || day2 == 7 || day2 == 8 || day2 == 9) { day3 = "0" + day2; } if (month == 10 || month == 11 || month == 12) { date = "" + year + month + day3; } else { date = "" + year + "0" + month + day3; } date = "date(" + date + ":integer)."; System.out.println(date); String url2 = rdfAddress; HttpClient client2 = new HttpClient(); GetMethod method2 = new GetMethod(url2); method2.setFollowRedirects(true); String typestr = ""; // Execute the GET method int statusCode2 = client2.executeMethod(method2); if (statusCode2 != -1) { typestr = method2.getResponseBodyAsString(); } System.out.println("Types: " + typestr); Types.reset(); RDFSParser.parseRDFSString(typestr); System.out.println("11111111111111111111111111111"); try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setFollowRedirects(true); //Execute the GET method int statusCode = client.executeMethod(method); if (statusCode != -1) { contents = method.getResponseBodyAsString(); } } catch (Exception e) { e.printStackTrace(); } contents = contents + "\n" + time; contents = contents + "\n" + dayOfWeek; contents = contents + "\n" + date; BackwardReasoner br = new BackwardReasoner(); Iterator solit = null; DefiniteClause dc = null; SymbolTable.reset(); pp.parseDefiniteClauses(contents); System.out.println("33333333333333333333333"); br.loadClauses(pp.iterator()); //System.out.println("TEST"); Iterator it = pp.iterator(); while (it.hasNext()) { DefiniteClause d = (DefiniteClause) it.next(); System.out.println("Loaded clause: " + d.toPOSLString()); } br = new BackwardReasoner(br.clauses, br.oids); MessageParser m = new MessageParser(message); Element atom = null; try { atom = m.parseForContent(); } catch (Exception e) { System.out.println("Invalid Message"); //out.flush(); } System.out.println("222222222222222222222222222222222"); QueryBuilder q = new QueryBuilder(atom); String query = q.generateDoc(); System.out.println("ABOUT TO INPUT THIS QUERY:" + query); RuleMLParser qp = new RuleMLParser(); try { dc = qp.parseRuleMLQuery(query); } catch (Exception e) { System.out.println("Invalid Query"); //out.flush(); } //solit = br.iterativeDepthFirstSolutionIterator(dc); solit = br.iterativeDepthFirstSolutionIterator(dc); System.out.println("444444444444444444444444444444444444"); int varSize = 0; while (solit.hasNext()) { Vector data = new Vector(); BackwardReasoner.GoalList gl = (BackwardReasoner.GoalList) solit.next(); Hashtable varbind = gl.varBindings; javax.swing.tree.DefaultMutableTreeNode root = br.toTree(); root.setAllowsChildren(true); javax.swing.tree.DefaultTreeModel dtm = new DefaultTreeModel(root); int i = 0; Object[][] rowdata = new Object[varbind.size()][2]; varSize = varbind.size(); Enumeration e = varbind.keys(); while (e.hasMoreElements()) { Object k = e.nextElement(); Object val = varbind.get(k); String ks = (String) k; rowdata[i][0] = ks; rowdata[i][1] = val; i++; } System.out.println("55555555555555555555555555555"); data.addElement(rowdata); String[] messages = new String[data.size()]; MessageGenerator g = new MessageGenerator(data, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel(), varOrder); messages = g.Messages2(); String appender = ""; URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); for (int i1 = 0; i1 < data.size(); i1++) { System.out.println(i1 + ")" + messages[i1].toString()); props.put("text", messages[i1].toString()); InputStream in = msg.sendGetMessage(props); } System.out.println("NEXT MESSAGE"); } System.out.println("6666666666666666666666666666"); MessageGenerator g = new MessageGenerator(null, varSize, messageEndpoint, m.getId(), m.getProtocol(), m.getRel()); URL sender = new URL(address + ":" + port); HttpMessage msg = new HttpMessage(sender); Properties props = new Properties(); String finalMessage = g.finalMessage(query); System.out.println(finalMessage); props.put("text", finalMessage); InputStream in = msg.sendGetMessage(props); System.out.println("Stop_Communication"); } catch (Exception e) { System.out.println("ERROR has occured : " + e.toString()); } out.close(); }