...
Blok kódu | ||
---|---|---|
| ||
package app.runnables; import app.wrappers.E$SmartWeb_Demo__$WRAPPER$__; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.HashMap; import java.util.List; public class E$SmartWeb_Demo extends E$SmartWeb_Demo__$WRAPPER$__ { public byte[] reportContract_PDF(byte[] urlParamsBytes) throws IOException { // naparsovanie poslaných URL paramatrov do hash-mapy final HashMap<String, String> parameters = getParametersFromUrlQueryString(urlParamsBytes); // Vyparsovanie parametra id do premennej final long contractId = Long.parseLong(parameters.get("id")); System.out.println("DEBUG: Downloading contract with id " + contractId); // Vyrobenie cesty k súboru s daným reportom Path path = Paths.get("D:/D2000/Contract" + contractId + ".pdf"); // Načítanie obsahu súboru a jeho vrátenie ako pole bajtov return Files.readAllBytes(path); } /** * Utility metóda, vráti naparsované URL parametre zoz vstupného poľa byte[] **/ private HashMap<String, String> getParametersFromUrlQueryString(byte[] urlQueryStringBytes) throws UnsupportedEncodingException { final String urlParamsString = new String(urlQueryStringBytes, "UTF-8"); final List<String> paramPartsList = Arrays.asList(urlParamsString.split("&")); final HashMap<String, String> parameters = new HashMap<String, String>(); for (String paramPartsString : paramPartsList) { final String[] paramParts = paramPartsString.split("="); final String paramName = paramParts[0]; final String paramValue = paramParts.length > 1 ? paramParts[1] : null; parameters.put(paramName, paramValue); } return parameters; } }; |
...