List of usage examples for javax.servlet.jsp JspWriter println
abstract public void println(Object x) throws IOException;
From source file:com.truthbean.core.web.kindeditor.FileUpload.java
@Override public void service(final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException { final PageContext pageContext; HttpSession session = null;//from w w w . j av a 2s . c om final ServletContext application; final ServletConfig config; JspWriter out = null; final Object page = this; JspWriter _jspx_out = null; PageContext _jspx_page_context = null; try { response.setContentType("text/html; charset=UTF-8"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); _jspx_page_context = pageContext; application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); out.write("\r\n"); /** * KindEditor JSP * * JSP???? ?? * */ // ? String savePath = pageContext.getServletContext().getRealPath("/") + "resource/"; String savePath$ = savePath; // ?URL String saveUrl = request.getContextPath() + "/resource/"; // ??? HashMap<String, String> extMap = new HashMap<>(); extMap.put("image", "gif,jpg,jpeg,png,bmp"); extMap.put("flash", "swf,flv"); extMap.put("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); extMap.put("file", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2"); // ? long maxSize = 10 * 1024 * 1024 * 1024L; response.setContentType("text/html; charset=UTF-8"); if (!ServletFileUpload.isMultipartContent(request)) { out.println(getError("")); return; } // File uploadDir = new File(savePath); if (!uploadDir.isDirectory()) { out.println(getError("?")); return; } // ?? if (!uploadDir.canWrite()) { out.println(getError("??")); return; } String dirName = request.getParameter("dir"); if (dirName == null) { dirName = "image"; } if (!extMap.containsKey(dirName)) { out.println(getError("???")); return; } // savePath += dirName + "/"; saveUrl += dirName + "/"; File saveDirFile = new File(savePath); if (!saveDirFile.exists()) { saveDirFile.mkdirs(); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String ymd = sdf.format(new Date()); savePath += ymd + "/"; saveUrl += ymd + "/"; File dirFile = new File(savePath); if (!dirFile.exists()) { dirFile.mkdirs(); } FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("UTF-8"); List items = upload.parseRequest(request); Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); String fileName = item.getName(); if (!item.isFormField()) { // ? if (item.getSize() > maxSize) { out.println(getError("??")); return; } // ?? String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase(); if (!Arrays.asList(extMap.get(dirName).split(",")).contains(fileExt)) { out.println(getError("??????\n??" + extMap.get(dirName) + "?")); return; } SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt; try { File uploadedFile = new File(savePath, newFileName); item.write(uploadedFile); } catch (Exception e) { out.println(getError("")); return; } JSONObject obj = new JSONObject(); obj.put("error", 0); obj.put("url", saveUrl + newFileName); request.getSession().setAttribute("fileName", savePath$ + fileName); request.getSession().setAttribute("filePath", savePath + newFileName); request.getSession().setAttribute("fileUrl", saveUrl + newFileName); out.println(obj.toJSONString()); } } out.write('\r'); out.write('\n'); } catch (IOException | FileUploadException t) { if (!(t instanceof javax.servlet.jsp.SkipPageException)) { out = _jspx_out; if (out != null && out.getBufferSize() != 0) { if (response.isCommitted()) { out.flush(); } else { out.clearBuffer(); } } if (_jspx_page_context != null) { _jspx_page_context.handlePageException(t); } else { throw new ServletException(t); } } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } }
From source file:com.redhat.rhn.frontend.taglibs.ListDisplayTag.java
/** {@inheritDoc} */ @Override//from w w w .j a v a 2 s . c o m public int doEndTag() throws JspException { JspWriter out = null; try { if (getPageList().isEmpty()) { return EVAL_PAGE; } if (isExport()) { ExportWriter eh = createExportWriter(); String[] columns = StringUtils.split(this.getExportColumns(), ','); eh.setColumns(Arrays.asList(columns)); ServletExportHandler seh = new ServletExportHandler(eh); pageContext.getOut().clear(); pageContext.getOut().clearBuffer(); pageContext.getResponse().reset(); seh.writeExporterToOutput((HttpServletResponse) pageContext.getResponse(), getPageList()); return SKIP_PAGE; } // Get the JSPWriter that the body used, then pop the // bodyContent, so that we can get the real JspWriter with getOut. BodyContent body = getBodyContent(); pageContext.popBody(); out = pageContext.getOut(); if (body != null) { String bodyString = body.getString(); // The toReplace string is kind of odd, but it is because // HtmlTag doesn't understand adding a property to be replaced. if (numItemsChecked == getPageList().size()) { bodyString = bodyString.replaceFirst("@@CHECKED@@=\"\"", "checked=\"1\""); } else { bodyString = bodyString.replaceFirst("@@CHECKED@@=\"\"", ""); } out.println(bodyString); } out.println("</tbody>"); out.println("</table>"); /* If the type is a half-table, we must draw an extra row on the * end of the table if the reflink has been set */ out.println("<div class=\"panel-footer\">"); out.println("<div class=\"spacewalk-list-footer-addons\">"); out.println("<div class=\"spacewalk-list-footer-addons-extra\">"); renderSetButtons(out); out.println("</div>"); out.println("<div class=\"spacewalk-list-reflinks\">"); if (reflink != null) { setColumnCount(0); out.println("<a href=\"" + reflink + "\" >"); /* * Here we render the reflink and its key. If the key hasn't * been set we just display the link address itself. */ if (reflinkkey != null) { Object[] args = new Object[2]; args[0] = new Integer(getPageList().getTotalSize()); args[1] = reflinkkeyarg0; String message = LocalizationService.getInstance().getMessage(reflinkkey, args); out.println(message); } else { out.println(reflink); } out.println("</a>"); } out.println("</div>"); out.println("</div>"); // close footer out.println("</div>"); // close panel out.println("</div>"); out.println("<div class=\"spacewalk-list-bottom-addons\">"); out.println("<div class=\"spacewalk-list-pagination\">"); /* If paging is on, we render the pagination */ if (isPaging()) { renderPagination(out, false); } /* If paging is off and we are rendering a normal list, * we show a count of the results in the lower left corner * of the list */ else if (type.equals("list")) { int finalResult = getPageList().getEnd(); if (finalResult > getPageList().getTotalSize()) { finalResult = getPageList().getTotalSize(); } Object[] args = new Object[4]; args[0] = new Integer(getPageList().getStart()); args[1] = new Integer(finalResult); args[2] = new Integer(getPageList().getTotalSize()); args[3] = LocalizationService.getInstance().getMessage(description); out.print("<span class=\"text-right\">\n"); out.print(LocalizationService.getInstance().getMessage("message.range.withtypedescription", args)); out.println("</span>"); } out.println("</div>"); if (isPaging()) { out.print("<div class=\"row-0\">\n"); renderActionButtons(out); out.println("</div>"); } out.println("</div>"); // close list out.println("</div>"); // export button goes outside of the list because in the new // implementation it is data-set dependent and not list dependent if (getExportColumns() != null) { renderExport(out); } setColumnCount(0); setNumberOfColumns(0); } catch (IOException e) { throw new JspException("IO error" + e.getMessage()); } finally { pageContext.setAttribute("current", null); } return EVAL_PAGE; }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryBusStop(JspWriter out, RepositoryConnection con, String idService) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); String nomeFermata = ""; String queryStringBusStop = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX schema:<http://schema.org/#> " + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "SELECT distinct ?nomeFermata ?bslat ?bslong ?address WHERE { " + " <" + idService + "> rdf:type km4c:BusStop." + " <" + idService + "> foaf:name ?nomeFermata." + " OPTIONAL {<" + idService + "> km4c:isInRoad ?road." + " ?road km4c:extendName ?address}." + " <" + idService + "> geo:lat ?bslat." + " <" + idService + "> geo:long ?bslong." + "}LIMIT 1"; TupleQuery tupleQueryBusStop = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringBusStop); TupleQueryResult busStopResult = tupleQueryBusStop.evaluate(); out.println("{\"Fermata\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int i = 0;// w w w . j a v a 2 s .co m try { while (busStopResult.hasNext()) { BindingSet bindingSetBusStop = busStopResult.next(); String valueOfBSLat = bindingSetBusStop.getValue("bslat").stringValue(); String valueOfBSLong = bindingSetBusStop.getValue("bslong").stringValue(); String valueOfRoad = ""; if (bindingSetBusStop.getValue("address") != null) { valueOfRoad = bindingSetBusStop.getValue("address").stringValue(); } nomeFermata = bindingSetBusStop.getValue("nomeFermata").stringValue(); if (i != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfBSLong + ", " + " " + valueOfBSLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " // + " \"popupContent\": \"" + nomeFermata + "\", " + " \"nome\": \"" + nomeFermata + "\", " + " \"serviceUri\": \"" + idService + "\", " + " \"tipo\": \"fermata\", " + " \"address\": \"" + valueOfRoad + "\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"NearBusStop\" " // ********************************************** + "}, " + "\"id\": " + Integer.toString(i + 1) + " " + "}"); i++; } } catch (Exception e) { out.println(e.getMessage()); } out.println("] " + "},"); /*String queryForLine = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource/>" + "PREFIX schema:<http://schema.org/>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX vcard:<http://www.w3.org/2006/vcard/ns#>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "SELECT DISTINCT ?id WHERE {" + " ?tpll rdf:type km4c:PublicTransportLine." + " ?tpll dcterms:identifier ?id." + " ?tpll km4c:hasRoute ?route." + " ?route km4c:hasSection ?rs." + " ?rs km4c:endsAtStop ?bs1." + " ?rs km4c:startsAtStop ?bs2." + " { ?bs1 foaf:name \"" + nomeFermata + "\"." + " }UNION " + " {?bs2 foaf:name \"" + nomeFermata + "\" . " + " } " + "} ORDER BY ?id "; TupleQuery tupleQueryForLine = con.prepareTupleQuery(QueryLanguage.SPARQL, queryForLine);*/ TupleQueryResult resultLines = queryBusLines(nomeFermata, con); if (resultLines != null) { try { out.println("\"linee\":"); out.println("{ \"head\": {" + "\"fermata\": " + "\"" + nomeFermata + "\"" + "," + "\"vars\": " + "\"linea\"" + "},"); out.println("\"results\": {"); out.println("\"bindings\": ["); int j = 0; while (resultLines.hasNext()) { BindingSet bindingSetLines = resultLines.next(); String idLine = bindingSetLines.getValue("id").stringValue(); if (j != 0) { out.println(", "); } out.println("{" + "\"linea\": {" + "\"type\": \"literal\"," + "\"value\": \"" + idLine + "\" " + " }" + " }"); j++; } out.println("]}},"); } catch (Exception e) { out.println(e.getMessage()); } } String queryStringAVM = "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX dcterms:<http://purl.org/dc/terms/> " + "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX schema:<http://schema.org/#> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX time:<http://www.w3.org/2006/time#> " + "SELECT ?ride (MAX(?avmr) AS ?avmrNew) " + "WHERE{ " //+ " <" + idService + "> rdf:type km4c:BusStop." + " <" + idService + "> km4c:hasForecast ?bsf." + " <" + idService + "> km4c:hasForecast ?bsf.\n" + " ?avmr km4c:includeForecast ?bsf.\n" + " OPTIONAL {?rs km4c:endsAtStop <" + idService + "> }.\n" + " OPTIONAL {?rs km4c:startsAtStop <" + idService + "> }.\n" + " ?route km4c:hasSection ?rs.\n" + " ?avmr km4c:onRoute ?route.\n" //+ " ?avmr km4c:concernLine ?tpll." + " ?ride km4c:hasAVMRecord ?avmr." + " ?avmr km4c:hasLastStopTime ?time." + " ?time <http://schema.org/value> ?timeInstant." + "}GROUP BY ?ride ORDER BY DESC (?avmrNew) LIMIT 10"; TupleQuery tupleQueryAVM = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringAVM); TupleQueryResult resultAVM = tupleQueryAVM.evaluate(); String filtroSecondaQuery = ""; try { i = 0; while (resultAVM.hasNext()) { BindingSet bindingSetAVM = resultAVM.next(); String valueOfAVMR = bindingSetAVM.getValue("avmrNew").stringValue(); if (i > 0) { filtroSecondaQuery += "UNION"; } filtroSecondaQuery += " { ?ride km4c:hasAVMRecord <" + valueOfAVMR + ">."; filtroSecondaQuery += " ?ride dcterms:identifier ?idRide."; filtroSecondaQuery += " <" + valueOfAVMR + "> km4c:includeForecast ?previsione;"; filtroSecondaQuery += " km4c:onRoute ?route;\n"; filtroSecondaQuery += " km4c:rideState ?stato.} "; i++; } if (i == 0) { out.println("\"realtime\": {}}"); return; } } catch (Exception e) { out.println(e.getMessage()); } String queryStringAVM2 = "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX dcterms:<http://purl.org/dc/terms/>\n" + "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX time:<http://www.w3.org/2006/time#>\n" + "SELECT DISTINCT ?arrivoPrevistoIstante ?linea ?stato ?idRide ?bsLast ?rName ?bsFirst WHERE {\n" + " ?fermata rdf:type km4c:BusStop.\n" + " ?fermata foaf:name \"" + nomeFermata + "\".\n" + " ?fermata km4c:hasForecast ?previsione\n." + filtroSecondaQuery + " ?previsione km4c:hasExpectedTime ?arrivoPrevisto.\n" + " ?arrivoPrevisto schema:value ?arrivoPrevistoIstante.\n" + " FILTER (?arrivoPrevistoIstante >= now()).\n" + " ?ride km4c:onRoute ?route.\n" + " ?route km4c:hasLastStop ?bse.\n" + " ?bse foaf:name ?bsLast.\n" + " ?route km4c:hasFirstStop ?bss.\n" + " ?bss foaf:name ?bsFirst.\n" + " ?route foaf:name ?rName.\n" /*+ " ?ride km4c:onRoute ?route.\n" + " ?route km4c:direction ?dir.\n" + " ?route km4c:hasSection ?rs.\n" + " ?rs km4c:distance ?mxdist.\n" + " ?rs km4c:endsAtStop ?bse.\n" + " ?bse foaf:name ?bsLast.\n" + " {\n" + " SELECT ?route ?dir (max(?dist) as ?mxdist) WHERE {\n" + " ?route km4c:hasSection ?rs.\n" + " ?route km4c:direction ?dir.\n" + " ?rs km4c:distance ?dist.\n" + " } group by ?route ?dir\n" + " }"*/ + " }\n" + " ORDER BY ASC (?arrivoPrevistoIstante) LIMIT 6"; /*String queryStringAVM2 = "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX schema:<http://schema.org/>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX time:<http://www.w3.org/2006/time#>" + "SELECT distinct ?avmr ?linea ?stato ?arrivoPrevistoIstante ?idRide WHERE {" + "{" + "SELECT ?ride (MAX(?avmr) AS ?avmrLast) WHERE{" + "?bs rdf:type km4c:BusStop." + "?bs foaf:name \"" + nomeFermata + "\"." + "?bs km4c:hasForecast ?bsf." + "?avmr km4c:includeForecast ?bsf." //+ "?avmr km4c:concernLine ?tpll." + "?ride km4c:hasAVMRecord ?avmr." //+ "?avmr km4c:hasLastStopTime/schema:value ?timeInstant." + "}" + "GROUP BY ?ride " + "ORDER BY DESC (?avmrLast)" + "LIMIT 15" + "}" + "?bs rdf:type km4c:BusStop." + "?bs foaf:name \"" + nomeFermata + "\"." + "?bs km4c:hasForecast ?previsione." + "?avmrLast km4c:includeForecast ?previsione." + "?previsione km4c:expectedTime ?arrivoPrevistoIstante." + "?avmrLast km4c:concernLine ?linea." + "?avmrLast km4c:rideState ?stato." + "?ride km4c:hasAVMRecord ?avmrLast." + "?ride dcterms:identifier ?idRide." + "FILTER(?arrivoPrevistoIstante>=now())" + "}" + "order by ?arrivoPrevistoIstante";*/ TupleQuery tupleQueryAVM2 = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringAVM2); String idRide = ""; TupleQueryResult resultAVM2 = tupleQueryAVM2.evaluate(); out.println("\"realtime\":"); if (resultAVM2.hasNext()) { out.println("{ \"head\": {" + "\"fermata\":[ " + "\"" + nomeFermata + "\"" + "]," + "\"vars\":[ " + "\"orario\", " + "\"linea\"," + "\"stato\"," + "\"ride\"" + "]" + "},"); out.println("\"results\": {"); out.println("\"bindings\": ["); int k = 0; while (resultAVM2.hasNext()) { BindingSet bindingSet2 = resultAVM2.next(); String valueOfArrivoPrevistoIstante = bindingSet2.getValue("arrivoPrevistoIstante").stringValue(); String valueOfLinea = ""; String bsLast = ""; String bsFirst = ""; String nomeLinea = ""; if (bindingSet2.getValue("linea") != null) { valueOfLinea = bindingSet2.getValue("linea").stringValue(); } String valueOfStato = ""; if (bindingSet2.getValue("stato") != null) { valueOfStato = bindingSet2.getValue("stato").stringValue(); } if (bindingSet2.getValue("idRide") != null) { idRide = bindingSet2.getValue("idRide").stringValue(); } if (bindingSet2.getValue("bsLast") != null) { bsLast = bindingSet2.getValue("bsLast").stringValue(); } if (bindingSet2.getValue("bsFirst") != null) { bsFirst = bindingSet2.getValue("bsFirst").stringValue(); } String direction = bsFirst + " ➔ " + bsLast; if (bindingSet2.getValue("rName") != null) { nomeLinea = bindingSet2.getValue("rName").stringValue(); } valueOfLinea = valueOfLinea.replace("http://www.disit.org/km4city/resource/", ""); valueOfArrivoPrevistoIstante = valueOfArrivoPrevistoIstante.substring(11, 19); if (k != 0) { out.println(", "); } out.println("{" + "\"orario\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfArrivoPrevistoIstante + "\" " + " }," + "\"linea\": { " + "\"type\": \"literal\"," + "\"value\": \"" + nomeLinea + "\" " + " }," + "\"stato\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfStato + "\" " + " }," + "\"direction\": {" + "\"type\": \"literal\"," + "\"value\": \"" + direction + "\" " + " }," + "\"ride\": {" + "\"type\": \"literal\"," + "\"value\": \"" + idRide + "\" " + " }"); out.println(" }"); k++; } out.println("]}}}"); } else { out.println("{}}"); } }
From source file:org.dspace.app.webui.jsptag.PoliciesListTag.java
public int doStartTag() throws JspException { String label_name = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_name"); String label_action = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_action"); String label_group = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_group"); String label_sdate = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_sdate"); String label_edate = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.label_edate"); String label_emptypolicies = LocaleSupport.getLocalizedMessage(pageContext, "org.dspace.app.webui.jsptag.policies-list.no_policies"); JspWriter out = pageContext.getOut(); StringBuffer sb = new StringBuffer(); try {//from w ww. j a v a 2s. c o m if (policies != null && policies.size() > 0) { sb.append("<div class=\"table-responsive\">\n"); sb.append("<table class=\"table\">\n"); sb.append("<tr>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_name).append("</th>\n"); sb.append("<th class=\"accessHeadEven\">").append(label_action).append("</th>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_group).append("</th>\n"); sb.append("<th class=\"accessHeadEven\">").append(label_sdate).append("</th>\n"); sb.append("<th class=\"accessHeadOdd\">").append(label_edate).append("</th>\n"); if (showButton) { sb.append("<th class=\"accessButton\"> </th>\n"); } sb.append("</tr>\n"); String column1 = "Even"; String column2 = "Odd"; for (ResourcePolicy policy : policies) { column1 = (column1.equals("Even") ? "Odd" : "Even"); column2 = (column2.equals("Even") ? "Odd" : "Even"); String rpName = (policy.getRpName() == null ? "" : policy.getRpName()); String startDate = (policy.getStartDate() == null ? "" : DateFormatUtils.format(policy.getStartDate(), "yyyy-MM-dd")); String endDate = (policy.getEndDate() == null ? "" : DateFormatUtils.format(policy.getEndDate(), "yyyy-MM-dd")); sb.append("<tr>\n"); sb.append("<td class=\"access").append(column1).append("\">").append(rpName).append("</td>\n"); sb.append("<td class=\"access").append(column2).append("\">").append(policy.getActionText()) .append("</td>\n"); sb.append("<td class=\"access").append(column1).append("\">") .append(policy.getGroup().getName()).append("</td>\n"); sb.append("<td class=\"access").append(column2).append("\">").append(startDate) .append("</td>\n"); sb.append("<td class=\"access").append(column1).append("\">").append(endDate).append("</td>\n"); if (showButton) { sb.append("<td class=\"accessButton\">\n"); sb.append("<input class=\"btn btn-default\" name=\"submit_edit_edit_policies_") .append(policy.getID()) .append("\" type=\"submit\" value=\"Edit\" /> <input class=\"btn btn-danger\" name=\"submit_delete_edit_policies_") .append(policy.getID()).append("\" type=\"submit\" value=\"Remove\" />\n"); sb.append("</td>\n"); } sb.append("</tr>\n"); } sb.append("</table>\n"); sb.append("</div>\n"); } else { sb.append("<div class=\"alert alert-warning\">").append(label_emptypolicies).append("</div>") .append("\n"); } out.println(sb.toString()); } catch (IOException ie) { throw new JspException(ie); } catch (SQLException e) { throw new JspException(e); } return SKIP_BODY; }
From source file:org.opencms.setup.CmsSetupBean.java
/** * Generates the output for step 8b of the setup wizard.<p> * /*from w ww . java2 s . co m*/ * @param out the JSP print stream * @throws IOException in case errors occur while writing to "out" */ public void prepareStep8bOutput(JspWriter out) throws IOException { if ((m_workplaceImportThread == null) || (m_workplaceImportThread.getLoggingThread() == null)) { return; } m_oldLoggingOffset = m_newLoggingOffset; m_newLoggingOffset = m_workplaceImportThread.getLoggingThread().getMessages().size(); if (isInitialized()) { for (int i = m_oldLoggingOffset; i < m_newLoggingOffset; i++) { String str = m_workplaceImportThread.getLoggingThread().getMessages().get(i).toString(); str = CmsEncoder.escapeWBlanks(str, CmsEncoder.ENCODING_UTF_8); out.println("output[" + (i - m_oldLoggingOffset) + "] = \"" + str + "\";"); } } else { out.println("output[0] = 'ERROR';"); } boolean threadFinished = m_workplaceImportThread.isFinished(); boolean allWritten = m_oldLoggingOffset >= m_workplaceImportThread.getLoggingThread().getMessages().size(); out.println("function initThread() {"); if (isInitialized()) { out.print("send();"); if (threadFinished && allWritten) { out.println("setTimeout('top.display.finish()', 1000);"); } else { int timeout = 5000; if (getWorkplaceImportThread().getLoggingThread().getMessages().size() < 20) { timeout = 2000; } out.println("setTimeout('location.reload()', " + timeout + ");"); } } out.println("}"); }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryMeteo(JspWriter out, RepositoryConnection con, String idService) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); String queryForComune = "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX dcterms:<http://purl.org/dc/terms/> " + "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX schema:<http://schema.org/#> " + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX time:<http://www.w3.org/2006/time#> " + "SELECT ?nomeComune WHERE {" + " {" + " <" + idService + "> km4c:refersToMunicipality ?mun." + " ?mun foaf:name ?nomeComune." + " }UNION{" + " <" + idService + "> rdf:type km4c:Municipality;" + " foaf:name ?nomeComune." + " }" + "}"; TupleQuery tupleQueryComuneMeteo = con.prepareTupleQuery(QueryLanguage.SPARQL, queryForComune); TupleQueryResult resultComuneMeteo = tupleQueryComuneMeteo.evaluate(); String nomeComune = ""; int i = 0;/*from w w w. ja va2s .co m*/ try { if (resultComuneMeteo.hasNext()) { BindingSet bindingSetComuneMeteo = resultComuneMeteo.next(); nomeComune = bindingSetComuneMeteo.getValue("nomeComune").stringValue(); } else { out.println("{\"ERROR\":\"Invalid service url\"}"); } } catch (Exception e) { out.println(e.getMessage()); } //System.out.println("comune: " + nomeComune); String queryStringMeteo1 = "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX schema:<http://schema.org/#>" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>" + "PREFIX time:<http://www.w3.org/2006/time#> " + "SELECT distinct ?wRep ?instantDateTime WHERE{" + " ?comune rdf:type km4c:Municipality." + " ?comune foaf:name \"" + nomeComune + "\"^^xsd:string." + " ?comune km4c:hasWeatherReport ?wRep." + " ?wRep km4c:updateTime ?instant." + " ?instant <http://schema.org/value> ?instantDateTime." + "} ORDER BY DESC (?instantDateTime) LIMIT 1 "; TupleQuery tupleQuery1 = con.prepareTupleQuery(QueryLanguage.SPARQL, filterQuery(queryStringMeteo1, km4cVersion)); TupleQueryResult result1 = tupleQuery1.evaluate(); if (result1.hasNext()) { BindingSet bindingSet1 = result1.next(); String valueOfInstantDateTime = bindingSet1.getValue("instantDateTime").stringValue(); String valueOfWRep = bindingSet1.getValue("wRep").stringValue(); String wPred = ""; String queryMeteo = "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX dcterms:<http://purl.org/dc/terms/> " + "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX schema:<http://schema.org/#> " + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX time:<http://www.w3.org/2006/time#> " + "SELECT distinct ?giorno ?descrizione ?minTemp ?maxTemp ?instantDateTime ?wPred WHERE{" + " <" + valueOfWRep + "> km4c:hasPrediction ?wPred." + " ?wPred dcterms:description ?descrizione." + " ?wPred km4c:day ?giorno." + " ?wPred km4c:hour ?g. FILTER(STR(?g)=\"giorno\")\n" + " OPTIONAL { ?wPred km4c:minTemp ?minTemp.}" + " OPTIONAL { ?wPred km4c:maxTemp ?maxTemp.}" + "}"; TupleQuery tupleQueryMeteo = con.prepareTupleQuery(QueryLanguage.SPARQL, queryMeteo); //tolto filterQuery per problema temporaneo da rimettere TupleQueryResult resultMeteo = tupleQueryMeteo.evaluate(); out.println("{ \"head\": {" + "\"location\": " + "\"" + nomeComune + "\"" + "," + "\"vars\":[ " + "\"giorno\", " + "\"descrizione\"," + "\"minTemp\"," + "\"maxTemp\"," + "\"instantDateTime\"" + "]" + "},"); out.println("\"results\": {"); out.println("\"bindings\": ["); try { i = 0; while (resultMeteo.hasNext()) { BindingSet bindingSetMeteo = resultMeteo.next(); wPred = bindingSetMeteo.getValue("wPred").stringValue(); String valueOfGiorno = bindingSetMeteo.getValue("giorno").stringValue(); String valueOfDescrizione = bindingSetMeteo.getValue("descrizione").stringValue(); String valueOfMinTemp = ""; if (bindingSetMeteo.getValue("minTemp") != null) { valueOfMinTemp = bindingSetMeteo.getValue("minTemp").stringValue(); } String valueOfMaxTemp = ""; if (bindingSetMeteo.getValue("maxTemp") != null) { valueOfMaxTemp = bindingSetMeteo.getValue("maxTemp").stringValue(); } if (i != 0) { out.println(", "); } out.println("{" + "\"giorno\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfGiorno + "\" " + " }," + "\"descrizione\": { " + "\"type\": \"literal\"," + "\"value\": \"" + valueOfDescrizione + "\" " + " }," + "\"minTemp\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfMinTemp + "\" " + " }," + "\"maxTemp\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfMaxTemp + "\" " + " }," + "\"instantDateTime\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfInstantDateTime + "\" " + " }" + "}"); i++; } out.println("]}}"); } catch (Exception e) { out.println(e.getMessage()); } } else { out.println("{\"ERROR\":\"No forecast found\"}"); } }
From source file:edu.cornell.mannlib.vedit.tags.DynamicFieldsTag.java
public int doEndTag() throws JspException { try {/* ww w . j av a2 s . co m*/ parseMarkup(); JspWriter out = pageContext.getOut(); HashMap values = null; try { FormObject foo = getFormObject(); List<DynamicField> dynfs = foo.getDynamicFields(); Iterator<DynamicField> dynIt = dynfs.iterator(); int i = 9899; while (dynIt.hasNext()) { DynamicField dynf = dynIt.next(); StringBuffer genTaName = new StringBuffer().append("_").append(dynf.getTable()).append("_"); genTaName.append("-1").append("_"); Iterator pparamIt = dynf.getRowTemplate().getParameterMap().keySet().iterator(); while (pparamIt.hasNext()) { String key = (String) pparamIt.next(); String value = (String) dynf.getRowTemplate().getParameterMap().get(key); byte[] valueInBase64 = Base64.encodeBase64(value.getBytes()); genTaName.append(key).append(":").append(new String(valueInBase64)).append(";"); } String preWithVars = new String(preMarkup); preWithVars = strReplace(preWithVars, type + "NN", Integer.toString(i)); preWithVars = strReplace(preWithVars, "\\$genTaName", genTaName.toString()); preWithVars = strReplace(preWithVars, "\\$fieldName", dynf.getName()); out.print(preWithVars); Iterator<DynamicFieldRow> rowIt = dynf.getRowList().iterator(); while (rowIt.hasNext()) { ++i; DynamicFieldRow row = rowIt.next(); if (row.getValue() == null) row.setValue(""); if (row.getValue().length() > 0) { StringBuffer taName = new StringBuffer().append("_").append(dynf.getTable()) .append("_"); taName.append(row.getId()).append("_"); Iterator paramIt = row.getParameterMap().keySet().iterator(); while (paramIt.hasNext()) { String key = (String) paramIt.next(); String value = (String) row.getParameterMap().get(key); byte[] valueInBase64 = Base64.encodeBase64(value.getBytes()); taName.append(key).append(":").append(new String(valueInBase64)).append(";"); } if (row.getValue().length() > 0) { String templateWithVars = new String(templateMarkup); templateWithVars = strReplace(templateWithVars, type + "NN", Integer.toString(i)); templateWithVars = strReplace(templateWithVars, "\\$taName", taName.toString()); templateWithVars = strReplace(templateWithVars, "\\$\\$", row.getValue()); out.print(templateWithVars); } } } out.print(postMarkup); } // output the row template for the javascript to clone out.println("<!-- row template inserted by DynamicFieldsTag -->"); String hiddenTemplatePreMarkup = new String(preMarkup); // bit of a hack to hide the template from the user: hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:none\\;", ""); hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:block\\;", ""); hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "display\\:inline\\;", ""); hiddenTemplatePreMarkup = strReplace(hiddenTemplatePreMarkup, "style\\=\\\"", "style=\"display:none;"); out.print(hiddenTemplatePreMarkup); String hiddenTemplateTemplateMarkup = new String(templateMarkup); hiddenTemplateTemplateMarkup = strReplace(hiddenTemplateTemplateMarkup, "\\$\\$", ""); out.print(hiddenTemplateTemplateMarkup); out.print(postMarkup); } catch (Exception e) { System.out.println("DynamicFieldsTag could not get the form object"); } } catch (Exception ex) { throw new JspException(ex.getMessage()); } return SKIP_BODY; }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void querySensor(JspWriter out, RepositoryConnection con, String idService) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); String querySensore = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#> " + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#> " + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#> " + "PREFIX schema:<http://schema.org/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "PREFIX dct:<http://purl.org/dc/terms/#>" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " + "select distinct ?idSensore ?lat ?long ?address ?nomeComune where{" + " <" + idService + "> rdf:type km4c:SensorSite;" + " geo:lat ?lat;" + " geo:long ?long;" + " dcterms:identifier ?idSensore;" + " schema:streetAddress ?address;" + " km4c:placedOnRoad ?road." + " ?road km4c:inMunicipalityOf ?mun." + " ?mun foaf:name ?nomeComune." //+ " FILTER regex(str(?lat), \"^4\") ." + "}" + "LIMIT 1"; String nomeSensore = ""; TupleQuery tupleQuerySensor = con.prepareTupleQuery(QueryLanguage.SPARQL, querySensore); TupleQueryResult resultSensor = tupleQuerySensor.evaluate(); out.println("{\"Sensore\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); try {//from w w w . ja va2s .c o m int s = 0; while (resultSensor.hasNext()) { BindingSet bindingSetSensor = resultSensor.next(); String valueOfId = bindingSetSensor.getValue("idSensore").stringValue(); String nomeComune = bindingSetSensor.getValue("nomeComune").stringValue(); String valueOfLat = bindingSetSensor.getValue("lat").stringValue(); String valueOfLong = bindingSetSensor.getValue("long").stringValue(); String valueOfAddress = bindingSetSensor.getValue("address").stringValue(); nomeSensore = valueOfId; if (s != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfLong + ", " + " " + valueOfLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " // + " \"popupContent\": \"" + valueOfId + " - sensore\", " + " \"nome\": \"" + valueOfId + "\", " + " \"tipo\": \"sensore\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"RoadSensor\", " // ********************************************** + " \"serviceUri\": \"" + idService + "\", " + " \"nomeComune\": \"" + nomeComune + "\", " + " \"indirizzo\": \"" + valueOfAddress + "\" " + "}, " + "\"id\": " + Integer.toString(s + 1) + " " + "}"); s++; } out.println("]},"); } catch (Exception e) { out.println(e.getMessage()); } String querySensorData = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX schema:<http://schema.org/#>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "PREFIX dct:<http://purl.org/dc/terms/#>" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#> " + "PREFIX foaf:<http://xmlns.com/foaf/0.1/> " + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#> " + "select ?avgDistance ?avgTime ?occupancy ?concentration ?vehicleFlow ?averageSpeed ?thresholdPerc ?speedPercentile ?timeInstant where{" + " <" + idService + "> rdf:type km4c:SensorSite;" + " dcterms:identifier \"" + nomeSensore + "\"^^xsd:string;" + " km4c:hasObservation ?obs." + " ?obs km4c:measuredTime ?time." + " ?time dcterms:identifier ?timeInstant." + " optional {?obs km4c:averageDistance ?avgDistance}." + " optional {?obs km4c:averageTime ?avgTime}." + " optional {?obs km4c:occupancy ?occupancy}." + " optional {?obs km4c:concentration ?concentration}." + " optional {?obs km4c:vehicleFlow ?vehicleFlow}." + " optional {?obs km4c:averageSpeed ?averageSpeed}." + " optional {?obs km4c:thresholdPerc ?thresholdPerc}." + " optional {?obs km4c:speedPrecentile ?speedPercentile}." + "} ORDER BY DESC (?timeInstant)" + "LIMIT 1"; TupleQuery tupleQuerySensorData = con.prepareTupleQuery(QueryLanguage.SPARQL, filterQuery(querySensorData, km4cVersion)); TupleQueryResult resultSensorData = tupleQuerySensorData.evaluate(); String valueOfInstantDateTime = ""; try { int t = 0; out.println("\"realtime\":"); if (resultSensorData.hasNext()) { out.println("{ \"head\": {" + "\"sensore\":[ " + "\"" + nomeSensore + "\"" + "]," + "\"vars\":[ " + "\"avgDistance\", " + "\"avgTime\"," + "\"occupancy\"," + "\"concentration\"," + "\"vehicleFlow\"," + "\"averageSpeed\"," + "\"thresholdPerc\"," + "\"speedPercentile\"," + "\"timeInstant\"" + "]" + "},"); out.println("\"results\": {"); out.println("\"bindings\": ["); while (resultSensorData.hasNext()) { BindingSet bindingSetSensorData = resultSensorData.next(); valueOfInstantDateTime = bindingSetSensorData.getValue("timeInstant").stringValue(); String valueOfAvgDistance = "Not Available"; if (bindingSetSensorData.getValue("avgDistance") != null) { valueOfAvgDistance = bindingSetSensorData.getValue("avgDistance").stringValue(); } String valueOfAvgTime = "Not Available"; if (bindingSetSensorData.getValue("avgTime") != null) { valueOfAvgTime = bindingSetSensorData.getValue("avgTime").stringValue(); } String valueOfOccupancy = "Not Available"; if (bindingSetSensorData.getValue("occupancy") != null) { valueOfOccupancy = bindingSetSensorData.getValue("occupancy").stringValue(); } String valueOfConcentration = "Not Available"; if (bindingSetSensorData.getValue("concentration") != null) { valueOfConcentration = bindingSetSensorData.getValue("concentration").stringValue(); } String valueOfVehicleFlow = "Not Available"; if (bindingSetSensorData.getValue("vehicleFlow") != null) { valueOfVehicleFlow = bindingSetSensorData.getValue("vehicleFlow").stringValue(); } String valueOfAverageSpeed = "Not Available"; if (bindingSetSensorData.getValue("averageSpeed") != null) { valueOfAverageSpeed = bindingSetSensorData.getValue("averageSpeed").stringValue(); } String valueOfThresholdPerc = "Not Available"; if (bindingSetSensorData.getValue("thresholdPerc") != null) { valueOfThresholdPerc = bindingSetSensorData.getValue("thresholdPerc").stringValue(); } String valueOfSpeedPercentile = "Not Available"; if (bindingSetSensorData.getValue("speedPercentile") != null) { valueOfSpeedPercentile = bindingSetSensorData.getValue("speedPercentile").stringValue(); } if (t != 0) { out.println(", "); } out.println("{"); out.println("\"avgDistance\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfAvgDistance + "\" " + " },"); out.println("\"avgTime\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfAvgTime + "\" " + " },"); out.println("\"occupancy\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfOccupancy + "\" " + " },"); out.println("\"concentration\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfConcentration + "\" " + " },"); out.println("\"vehicleFlow\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfVehicleFlow + "\" " + " },"); out.println("\"averageSpeed\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfAverageSpeed + "\" " + " },"); out.println("\"thresholdPerc\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfThresholdPerc + "\" " + " },"); out.println("\"speedPercentile\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfSpeedPercentile + "\" " + " },"); out.println("\"instantTime\": {" + "\"type\": \"literal\"," + "\"value\": \"" + valueOfInstantDateTime + "\" " + " }"); out.println("}"); t++; } out.println("]}}}"); } else { out.println("{}}"); } } catch (Exception e) { out.println(e.getMessage()); } }
From source file:info.magnolia.cms.taglibs.util.SimpleNavigationTag.java
/** * Draws page children as an unordered list. * @param page current page/*from w w w . j av a 2 s .co m*/ * @param activePage active page * @param out jsp writer * @throws IOException jspwriter exception * @throws RepositoryException any exception thrown during repository reading */ private void drawChildren(Content page, Content activePage, JspWriter out) throws IOException, RepositoryException { Collection children = page.getChildren(ItemType.CONTENT); if (children.size() == 0) { return; } out.print("<ul class=\"level"); //$NON-NLS-1$ out.print(page.getLevel()); if (style != null && page.getLevel() == startLevel) { out.print(" "); out.print(style); } out.print("\">"); //$NON-NLS-1$ Iterator it = children.iterator(); while (it.hasNext()) { Content child = (Content) it.next(); if (expandAll.equalsIgnoreCase(EXPAND_NONE) || expandAll.equalsIgnoreCase(EXPAND_SHOW)) { if (child.getNodeData(StringUtils.defaultString(this.hideInNav, DEFAULT_HIDEINNAV_NODEDATA)) .getBoolean()) { continue; } } List cssClasses = new ArrayList(3); String title = child.getNodeData(NODEDATA_NAVIGATIONTITLE).getString(StringUtils.EMPTY); // if nav title is not set, the main title is taken if (StringUtils.isEmpty(title)) { title = child.getTitle(); } // if main title is not set, the name of the page is taken if (StringUtils.isEmpty(title)) { title = child.getName(); } boolean showChildren = false; boolean self = false; if (!expandAll.equalsIgnoreCase(EXPAND_NONE)) { showChildren = true; } if (activePage.getHandle().equals(child.getHandle())) { // self showChildren = true; self = true; cssClasses.add(CSS_LI_ACTIVE); //$NON-NLS-1$ } else if (!showChildren) { showChildren = (child.getLevel() <= activePage.getAncestors().size() && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())); } if (!showChildren) { showChildren = child .getNodeData(StringUtils.defaultString(this.openMenu, DEFAULT_OPENMENU_NODEDATA)) .getBoolean(); } if (endLevel > 0) { showChildren &= child.getLevel() < endLevel; } cssClasses.add(hasVisibleChildren(child) ? (showChildren ? CSS_LI_OPEN : CSS_LI_CLOSED) : CSS_LI_LEAF); if (child.getLevel() < activePage.getLevel() && activePage.getAncestor(child.getLevel()).getHandle().equals(child.getHandle())) { cssClasses.add(CSS_LI_TRAIL); } StringBuffer css = new StringBuffer(cssClasses.size() * 10); Iterator iterator = cssClasses.iterator(); while (iterator.hasNext()) { css.append(iterator.next()); if (iterator.hasNext()) { css.append(" "); //$NON-NLS-1$ } } out.print("<li class=\""); //$NON-NLS-1$ out.print(css.toString()); out.print("\">"); //$NON-NLS-1$ if (self) { out.println("<strong>"); //$NON-NLS-1$ } String accesskey = child.getNodeData(NODEDATA_ACCESSKEY).getString(StringUtils.EMPTY); out.print("<a href=\""); //$NON-NLS-1$ out.print(((HttpServletRequest) this.pageContext.getRequest()).getContextPath()); out.print(child.getHandle()); out.print(".html\""); //$NON-NLS-1$ if (StringUtils.isNotEmpty(accesskey)) { out.print(" accesskey=\""); //$NON-NLS-1$ out.print(accesskey); out.print("\""); //$NON-NLS-1$ } out.print(">"); //$NON-NLS-1$ out.print(StringEscapeUtils.escapeHtml(title)); out.print(" </a>"); //$NON-NLS-1$ if (self) { out.println("</strong>"); //$NON-NLS-1$ } if (showChildren) { drawChildren(child, activePage, out); } out.print("</li>"); //$NON-NLS-1$ } out.print("</ul>"); //$NON-NLS-1$ }
From source file:org.disit.servicemap.api.ServiceMapApi.java
public void queryLatLngServices(JspWriter out, RepositoryConnection con, String[] coords, String categorie, String textToSearch, String raggioBus, String raggioSensori, String raggioServizi, String risultatiBus, String risultatiSensori, String risultatiServizi) throws Exception { Configuration conf = Configuration.getInstance(); String sparqlType = conf.get("sparqlType", "virtuoso"); String km4cVersion = conf.get("km4cVersion", "new"); List<String> listaCategorieServizi = new ArrayList<String>(); if (categorie != null) { String[] arrayCategorie = categorie.split(";"); // GESTIONE CATEGORIE listaCategorieServizi = Arrays.asList(arrayCategorie); }//from w w w .j av a2s. c om String fc = ""; try { fc = ServiceMap.filterServices(listaCategorieServizi); } catch (Exception e) { } int i = 0; int numeroBus = 0; //if (listaCategorieServizi.contains("NearBusStops")) { if (listaCategorieServizi.contains("BusStop")) { String queryStringNearBusStop = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?bs (STR(?nome) AS ?nomeFermata) ?bslat ?bslong ?x WHERE {\n" + " ?bs geo:lat ?bslat.\n" + " ?bs geo:long ?bslong.\n" + ServiceMap.geoSearchQueryFragment("?bs", coords, raggioBus) + " ?bs rdf:type km4c:BusStop.\n" + " ?bs foaf:name ?nome.\n" + ServiceMap.textSearchQueryFragment("?bs", "foaf:name", textToSearch) + (km4cVersion.equals("old") ? " FILTER ( datatype(?bslat ) = xsd:float )\n" + " FILTER ( datatype(?bslong ) = xsd:float )\n" : "") + "} ORDER BY ?dist"; if (!risultatiBus.equals("0")) { queryStringNearBusStop += " LIMIT " + risultatiBus; } TupleQuery tupleQueryNearBusStop = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearBusStop); TupleQueryResult resultNearBS = tupleQueryNearBusStop.evaluate(); out.println("{\"Fermate\": "); out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int s = 0; while (resultNearBS.hasNext()) { BindingSet bindingSetNearBS = resultNearBS.next(); String valueOfBS = bindingSetNearBS.getValue("bs").stringValue(); String valueOfNomeFermata = bindingSetNearBS.getValue("nomeFermata").stringValue(); String valueOfBSLat = bindingSetNearBS.getValue("bslat").stringValue(); String valueOfBSLong = bindingSetNearBS.getValue("bslong").stringValue(); /*String queryForLinee = "PREFIX km4c:<http://www.disit.org/km4city/schema#>" + "PREFIX km4cr:<http://www.disit.org/km4city/resource/>" + "PREFIX schema:<http://schema.org/>" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX vcard:<http://www.w3.org/2006/vcard/ns#>" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>" + "PREFIX dcterms:<http://purl.org/dc/terms/>" + "SELECT DISTINCT ?id WHERE {" + " ?tpll rdf:type km4c:PublicTransportLine." + " ?tpll dcterms:identifier ?id." + " ?tpll km4c:hasRoute ?route." + " ?route km4c:hasSection ?rs." + " ?rs km4c:endsAtStop ?bs1." + " ?rs km4c:startsAtStop ?bs2." + " { ?bs1 foaf:name \"" + valueOfNomeFermata + "\"." + " }UNION " + " {?bs2 foaf:name \"" + valueOfNomeFermata + "\" . " + " } " + "} ORDER BY ?id "; TupleQuery tupleQueryForLinee = con.prepareTupleQuery(QueryLanguage.SPARQL, queryForLinee);*/ TupleQueryResult resultLinee = queryBusLines(valueOfNomeFermata, con); String valueOfLinee = ""; if (resultLinee != null) { while (resultLinee.hasNext()) { BindingSet bindingSetLinee = resultLinee.next(); String idLinee = bindingSetLinee.getValue("id").stringValue(); valueOfLinee = valueOfLinee + " - " + idLinee; } } if (s != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfBSLong + ", " + " " + valueOfBSLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfNomeFermata) + "\", " + " \"tipo\": \"fermata\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"NearBusStop\", " + " \"linee\": \"" + valueOfLinee.substring(3) + "\", " // ********************************************** + " \"serviceUri\": \"" + valueOfBS + "\" " + "}, " + "\"id\": " + Integer.toString(s + 1) + " " + "}"); s++; numeroBus++; } out.println("]}"); //if (categorie.equals("NearBusStops")) { if (categorie.equals("BusStop")) { out.println("}"); } } int numeroSensori = 0; //if (listaCategorieServizi.contains("RoadSensor")) { if (listaCategorieServizi.contains("SensorSite")) { String queryStringNearSensori = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX dcterms:<http://purl.org/dc/terms/>\n" + "PREFIX dct:<http://purl.org/dc/terms/#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "SELECT DISTINCT ?sensor ?idSensore ?lat ?long ?address ?x WHERE {\n" + " ?sensor rdf:type km4c:SensorSite.\n" + " ?sensor geo:lat ?lat.\n" + " ?sensor geo:long ?long.\n" + " ?sensor dcterms:identifier ?idSensore.\n" + ServiceMap.textSearchQueryFragment("?sensor", "?p", textToSearch) + ServiceMap.geoSearchQueryFragment("?sensor", coords, raggioBus) + " ?sensor schema:streetAddress ?address.\n" + "} ORDER BY ?dist"; if (!risultatiSensori.equals("0")) { queryStringNearSensori += " LIMIT " + risultatiSensori; } TupleQuery tupleQuerySensori = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringNearSensori); TupleQueryResult resultNearSensori = tupleQuerySensori.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops")) { if (!listaCategorieServizi.contains("BusStop")) { out.println("{\"Sensori\": "); } else { out.println(", \"Sensori\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); while (resultNearSensori.hasNext()) { // out.println(result); BindingSet bindingSetNearSensori = resultNearSensori.next(); String valueOfId = bindingSetNearSensori.getValue("idSensore").stringValue(); String valueOfIdService = bindingSetNearSensori.getValue("sensor").stringValue(); String valueOfLat = bindingSetNearSensori.getValue("lat").stringValue(); String valueOfLong = bindingSetNearSensori.getValue("long").stringValue(); String valueOfAddress = bindingSetNearSensori.getValue("address").stringValue(); if (i != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfLong + ", " + " " + valueOfLat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfId) + "\", " + " \"tipo\": \"sensore\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"RoadSensor\", " // ********************************************** + " \"serviceUri\": \"" + valueOfIdService + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(i + 1) + " " + "}"); i++; numeroSensori++; } out.println("]}"); //if (categorie.equals("RoadSensor")) { if (categorie.equals("SensorSite")) { out.println("}"); } } int numeroServizi = 0; //if (!categorie.equals("NearBusStops") && !categorie.equals("RoadSensor") && !categorie.equals("RoadSensor;NearBusStops") && !categorie.equals("NearBusStops;RoadSensor")) { if (!categorie.equals("BusStop") && !categorie.equals("SensorSite") && !categorie.equals("SensorSite;BusStop") && !categorie.equals("BusStop;SensorSite")) { String queryStringServiceNear = "PREFIX km4c:<http://www.disit.org/km4city/schema#>\n" + "PREFIX km4cr:<http://www.disit.org/km4city/resource#>\n" + "PREFIX schema:<http://schema.org/>\n" + "PREFIX geo:<http://www.w3.org/2003/01/geo/wgs84_pos#>\n" + "PREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n" + "PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" + "PREFIX omgeo:<http://www.ontotext.com/owlim/geo#>\n" + "PREFIX foaf:<http://xmlns.com/foaf/0.1/>\n" + "PREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n" + "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n" + "PREFIX dc:<http://purl.org/dc/elements/1.1/>\n" + "SELECT distinct ?ser ?serAddress ?elat ?elong ?sType ?sCategory ?sTypeIta ?sName ?email ?note ?multimedia ?description ?x WHERE {\n" + " ?ser rdf:type km4c:Service" + (sparqlType.equals("virtuoso") ? " OPTION (inference \"urn:ontology\")" : "") + ".\n" + " OPTIONAL {?ser <http://schema.org/name> ?sName}\n" + " ?ser <http://schema.org/streetAddress> ?serAddress.\n" + " OPTIONAL {?ser skos:note ?note}\n" + " OPTIONAL {?ser dc:description ?description" + " FILTER(LANG(?description) = \"it\")" + " }\n" + " OPTIONAL {?ser km4c:multimediaResource ?multimedia}\n" + " OPTIONAL {?ser schema:email ?email }\n" + ServiceMap.textSearchQueryFragment("?ser", "?p", textToSearch) + " {\n" + " ?ser km4c:hasAccess ?entry.\n" + " ?entry geo:lat ?elat.\n" + " ?entry geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?entry", coords, raggioServizi) + " } UNION {\n" + " ?ser geo:lat ?elat.\n" + " ?ser geo:long ?elong.\n" + ServiceMap.geoSearchQueryFragment("?ser", coords, raggioServizi) + " }\n" + fc + (!km4cVersion.equals("old") ? " graph ?g {?ser a ?sType. FILTER(?sType!=km4c:RegularService && ?sType!=km4c:Service && ?sType!=km4c:DigitalLocation && ?sType!=km4c:TransverseService)}\n" + " ?sType rdfs:subClassOf ?sCategory. FILTER(?sCategory != <http://www.w3.org/2003/01/geo/wgs84_pos#SpatialThing>) " + " ?sType rdfs:label ?sTypeIta. FILTER(LANG(?sTypeIta)=\"it\")\n" : "") + "} ORDER BY ?dist"; if (!risultatiServizi.equals("0")) { queryStringServiceNear += " LIMIT " + risultatiServizi; } TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryStringServiceNear); TupleQueryResult result = tupleQuery.evaluate(); //if (!listaCategorieServizi.contains("NearBusStops") && !listaCategorieServizi.contains("RoadSensor")) { if (!listaCategorieServizi.contains("BusStop") && !listaCategorieServizi.contains("SensorSite")) { out.println("{\"Servizi\": "); } else { out.println(", \"Servizi\": "); } out.println("{ " + "\"type\": \"FeatureCollection\", " + "\"features\": [ "); int w = 0; while (result.hasNext()) { BindingSet bindingSet = result.next(); String valueOfSer = bindingSet.getValue("ser").stringValue(); String valueOfSerAddress = ""; if (bindingSet.getValue("serAddress") != null) { valueOfSerAddress = bindingSet.getValue("serAddress").stringValue(); } String valueOfSType = ""; if (bindingSet.getValue("sType") != null) { valueOfSType = bindingSet.getValue("sType").stringValue(); } String valueOfSTypeIta = ""; if (bindingSet.getValue("sTypeIta") != null) { valueOfSTypeIta = bindingSet.getValue("sTypeIta").stringValue(); //valueOfSTypeIta = Character.toLowerCase(valueOfSTypeIta.charAt(0)) + valueOfSTypeIta.substring(1); valueOfSTypeIta = valueOfSTypeIta.replace(" ", "_"); valueOfSTypeIta = valueOfSTypeIta.replace("'", ""); } // DICHIARAZIONE VARIABILI serviceType e serviceCategory per ICONA String subCategory = ""; if (bindingSet.getValue("sType") != null) { subCategory = bindingSet.getValue("sType").stringValue(); subCategory = subCategory.replace("http://www.disit.org/km4city/schema#", ""); subCategory = Character.toLowerCase(subCategory.charAt(0)) + subCategory.substring(1); subCategory = subCategory.replace(" ", "_"); } String category = ""; if (bindingSet.getValue("sCategory") != null) { category = bindingSet.getValue("sCategory").stringValue(); category = category.replace("http://www.disit.org/km4city/schema#", ""); category = Character.toLowerCase(category.charAt(0)) + category.substring(1); category = category.replace(" ", "_"); } String serviceType = category + "_" + subCategory; String valueOfSName = ""; if (bindingSet.getValue("sName") != null) { valueOfSName = bindingSet.getValue("sName").stringValue(); } else { valueOfSName = subCategory.replace("_", " ").toUpperCase(); } String valueOfELat = bindingSet.getValue("elat").stringValue(); String valueOfELong = bindingSet.getValue("elong").stringValue(); String valueOfNote = ""; if (bindingSet.getValue("note") != null) { valueOfNote = bindingSet.getValue("note").stringValue(); } String valueOfEmail = ""; if (bindingSet.getValue("email") != null) { valueOfEmail = bindingSet.getValue("email").stringValue(); } Normalizer.normalize(valueOfNote, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", ""); valueOfNote = valueOfNote.replaceAll("[^A-Za-z0-9 ]+", ""); if (w != 0) { out.println(", "); } out.println("{ " + " \"geometry\": { " + " \"type\": \"Point\", " + " \"coordinates\": [ " + " " + valueOfELong + ", " + " " + valueOfELat + " " + " ] " + "}, " + "\"type\": \"Feature\", " + "\"properties\": { " + " \"nome\": \"" + escapeJSON(valueOfSName) + "\", " + " \"tipo\": \"" + escapeJSON(valueOfSTypeIta) + "\", " // *** INSERIMENTO serviceType + " \"serviceType\": \"" + escapeJSON(mapServiceType(serviceType)) + "\", " // ********************************************** + " \"email\": \"" + escapeJSON(valueOfEmail) + "\", " + " \"note\": \"" + escapeJSON(valueOfNote) + "\", " + " \"serviceUri\": \"" + escapeJSON(valueOfSer) + "\", " + " \"indirizzo\": \"" + escapeJSON(valueOfSerAddress) + "\" " + "}, " + "\"id\": " + Integer.toString(w + 1) + " " + "}"); w++; numeroServizi++; } out.println("]}}"); } else { if (categorie.equals("SensorSite;BusStop") || categorie.equals("BusStop;SensorSite")) { out.println("}"); } } }