/** * @param header the complete HTTP header of the request * @param post any arguments for this servlet, the request carried with (GET as well as POST) * @param env the serverSwitch object holding all runtime-data * @return the rewrite-properties for the template */ public static serverObjects respond( final RequestHeader header, final serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); // getting the http host header final String hostSocket = header.get(HeaderFramework.CONNECTION_PROP_HOST); String host = hostSocket; int port = 80; final int pos = hostSocket.indexOf(":"); if (pos != -1) { port = Integer.parseInt(hostSocket.substring(pos + 1)); host = hostSocket.substring(0, pos); } prop.put("host", host); prop.put("port", port); prop.putHTML("name", sb.peers.mySeed().getName()); return prop; }
/** * Generates a proxy-autoconfig-file (application/x-ns-proxy-autoconfig) See: <a * href="http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html">Proxy Auto-Config * File Format</a> * * @param header the complete HTTP header of the request * @param post any arguments for this servlet, the request carried with (GET as well as POST) * @param env the serverSwitch object holding all runtime-data * @return the rewrite-properties for the template */ public static serverObjects respond( final RequestHeader header, final serverObjects post, final serverSwitch env) { final serverObjects prop = new serverObjects(); final boolean yacyonly = env.getConfigBool(SwitchboardConstants.PROXY_YACY_ONLY, false); // get the http host header final String hostSocket = header.get(HeaderFramework.CONNECTION_PROP_HOST); String host = hostSocket; int port = 80; final int pos = hostSocket.indexOf(':', 0); if (pos != -1) { port = Integer.parseInt(hostSocket.substring(pos + 1)); host = hostSocket.substring(0, pos); } prop.put("yacy", yacyonly ? "0" : "1"); prop.put("yacy_host", host); prop.put("yacy_port", port); return prop; }
public static serverObjects respond( final RequestHeader header, final serverObjects post, final serverSwitch env) { final Switchboard sb = (Switchboard) env; final serverObjects prop = new serverObjects(); final String EXT = header.get("EXT", ""); final boolean html = EXT.equals("html"); final boolean xml = EXT.equals("xml"); String table = (post == null) ? null : post.get("table"); if (post == null || (!post.containsKey("commitrow") && table != null && !sb.tables.hasHeap(table))) table = null; prop.put("showtable", 0); prop.put("tablecount", sb.tables.size()); // apply deletion requests if (table != null && post != null && post.containsKey("deletetable")) { sb.tables.clear(table); table = null; } if (table == null) { // list all tables that we know int c = 0; for (final String name : sb.tables) { try { if (html) { prop.putHTML("showtable_tables_" + c + "_table", name); } if (xml) { prop.putXML("showtable_tables_" + c + "_table", name); } prop.put("showtable_tables_" + c + "_num", sb.tables.size(name)); c++; } catch (final IOException e) { } } prop.put("showtable_tables", c); prop.put("tablecount", c); return prop; } final boolean showpk = post.containsKey("pk"); final String selectKey = post.containsKey("selectKey") ? post.get("selectKey") : null; final String selectValue = (selectKey != null && post.containsKey("selectValue")) ? post.get("selectValue") : null; final String counts = post.get("count", null); int maxcount = (counts == null || counts.equals("all")) ? Integer.MAX_VALUE : post.getInt("count", 10); final String pattern = post.get("search", ""); final Pattern matcher = (pattern.length() == 0 || pattern.equals(".*")) ? null : Pattern.compile(".*" + pattern + ".*"); if (post.containsKey("deleterows")) { for (final Map.Entry<String, String> entry : post.entrySet()) { if (entry.getValue().startsWith("pk_")) try { sb.tables.delete(table, entry.getValue().substring(3).getBytes()); } catch (final IOException e) { Log.logException(e); } } } if (post.containsKey("commitrow")) { final String pk = post.get("pk"); final Map<String, byte[]> map = new HashMap<String, byte[]>(); for (final Map.Entry<String, String> entry : post.entrySet()) { if (entry.getKey().startsWith("col_")) { map.put(entry.getKey().substring(4), entry.getValue().getBytes()); } } try { if (pk == null || pk.length() == 0) { sb.tables.insert(table, map); } else { sb.tables.update(table, pk.getBytes(), map); } } catch (final IOException e) { Log.logException(e); } catch (final RowSpaceExceededException e) { Log.logException(e); } } // generate table prop.put("showtable", 1); prop.put("showtable_table", table); // insert the columns ArrayList<String> columns = null; try { columns = sb.tables.columns(table); } catch (final IOException e) { Log.logException(e); columns = new ArrayList<String>(); } // if a row attribute is given // then order the columns according to the given order final String[] row = post.get("row", "").split(","); for (int i = 0; i < row.length; i++) { if (columns.contains(row[i])) { columns.remove(row[i]); if (i < columns.size()) columns.add(i, row[i]); } } prop.put("showtable_showpk", showpk ? 1 : 0); for (int i = 0; i < columns.size(); i++) { prop.putHTML("showtable_columns_" + i + "_header", columns.get(i)); } prop.put("showtable_columns", columns.size()); // insert all rows try { maxcount = Math.min(maxcount, sb.tables.size(table)); } catch (final IOException e) { Log.logException(e); maxcount = 0; } int count = 0; try { final Iterator<Tables.Row> plainIterator = sb.tables.iterator(table, matcher); final Iterator<Tables.Row> mapIterator = sb.tables.orderByPK(plainIterator, maxcount).iterator(); Tables.Row trow; boolean dark = true; String cellName, cellValue; rowloop: while ((mapIterator.hasNext()) && (count < maxcount)) { trow = mapIterator.next(); if (row == null) continue; prop.put("showtable_list_" + count + "_dark", ((dark) ? 1 : 0)); dark = !dark; prop.put("showtable_list_" + count + "_showpk", showpk ? 1 : 0); prop.put("showtable_list_" + count + "_showpk_pk", UTF8.String(trow.getPK())); prop.put("showtable_list_" + count + "_count", count); for (int i = 0; i < columns.size(); i++) { cellName = columns.get(i); if (trow.containsKey(cellName)) { cellValue = UTF8.String(trow.get(cellName)); if (selectKey != null && cellName.equals(selectKey) && !cellValue.matches(selectValue)) continue rowloop; } else { cellValue = ""; } if (html) { prop.putHTML("showtable_list_" + count + "_columns_" + i + "_column", cellName); prop.putHTML("showtable_list_" + count + "_columns_" + i + "_cell", cellValue); } if (xml) { prop.putXML("showtable_list_" + count + "_columns_" + i + "_column", cellName); prop.putXML("showtable_list_" + count + "_columns_" + i + "_cell", cellValue); } } prop.put("showtable_list_" + count + "_columns", columns.size()); count++; } } catch (final IOException e) { Log.logException(e); } prop.put("showtable_list", count); prop.put("showtable_num", count); // return rewrite properties return prop; }