Skip to content
Permalink
Browse files

Fixed #1826

  • Loading branch information...
mertsincan committed Oct 11, 2016
1 parent 2d90f25 commit 7a30345e2dccfa2dad628d051dda75e8772fd3d9
@@ -21,21 +21,20 @@
import javax.faces.context.FacesContext;
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
import org.primefaces.context.RequestContext;
import org.primefaces.util.Constants;
import org.primefaces.util.StringEncrypter;

public class QRCodeHandler extends BaseDynamicContentHandler {

public void handle(FacesContext context) throws IOException {
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
String encryptedValue = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM);
ExternalContext externalContext = context.getExternalContext();
String sessionKey = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM);
Map<String,Object> session = externalContext.getSessionMap();
Map<String,String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING);
String value = barcodeMapping.get(sessionKey);

if(encryptedValue != null) {
boolean cache = Boolean.valueOf(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM));
StringEncrypter strEn = RequestContext.getCurrentInstance().getEncrypter();
String value = strEn.decrypt(encryptedValue);
ExternalContext externalContext = context.getExternalContext();
if(value != null) {
boolean cache = Boolean.valueOf(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM));

externalContext.setResponseStatus(200);
externalContext.setResponseContentType("image/png");
@@ -31,10 +31,8 @@
import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
import org.krysalis.barcode4j.output.svg.SVGCanvasProvider;
import org.primefaces.application.resource.BaseDynamicContentHandler;
import org.primefaces.context.RequestContext;
import org.primefaces.util.AgentUtils;
import org.primefaces.util.Constants;
import org.primefaces.util.StringEncrypter;
import org.w3c.dom.DocumentFragment;

public class BarcodeHandler extends BaseDynamicContentHandler {
@@ -61,16 +59,17 @@ public BarcodeHandler() {
public void handle(FacesContext context) throws IOException {
Map<String,String> params = context.getExternalContext().getRequestParameterMap();
ExternalContext externalContext = context.getExternalContext();
String encryptedValue = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM);

if(encryptedValue != null) {
String sessionKey = (String) params.get(Constants.DYNAMIC_CONTENT_PARAM);
Map<String,Object> session = externalContext.getSessionMap();
Map<String,String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING);
String value = barcodeMapping.get(sessionKey);

if(value != null) {
try {
BarcodeGenerator generator = generators.get(params.get("gen"));
String format = params.get("fmt");
int orientation = Integer.parseInt(params.get("ori"));
boolean cache = Boolean.valueOf(params.get(Constants.DYNAMIC_CONTENT_CACHE_PARAM));
StringEncrypter strEn = RequestContext.getCurrentInstance().getEncrypter();
String value = strEn.decrypt(encryptedValue);

if(AgentUtils.isLessThanIE(context, 9)) {
format = "png";
@@ -18,17 +18,18 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.faces.application.Resource;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import org.primefaces.application.resource.DynamicContentType;
import org.primefaces.context.RequestContext;
import org.primefaces.renderkit.CoreRenderer;
import org.primefaces.util.Constants;
import org.primefaces.util.HTML;
import org.primefaces.util.SharedStringBuilder;
import org.primefaces.util.StringEncrypter;

public class BarcodeRenderer extends CoreRenderer {

@@ -52,11 +53,18 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
try {
Resource resource = context.getApplication().getResourceHandler().createResource("dynamiccontent.properties", "primefaces", "image/png");
String resourcePath = resource.getRequestPath();
StringEncrypter encrypter = RequestContext.getCurrentInstance().getEncrypter();
String rid = encrypter.encrypt((String) value);

String sessionKey = UUID.randomUUID().toString();
Map<String,Object> session = context.getExternalContext().getSessionMap();
Map<String,String> barcodeMapping = (Map) session.get(Constants.BARCODE_MAPPING);
if(barcodeMapping == null) {
barcodeMapping = new HashMap<String, String>();
session.put(Constants.BARCODE_MAPPING, barcodeMapping);
}
barcodeMapping.put(sessionKey, (String) value);
StringBuilder builder = SharedStringBuilder.get(context, SB_BUILD);

src = builder.append(resourcePath).append("&").append(Constants.DYNAMIC_CONTENT_PARAM).append("=").append(URLEncoder.encode(rid, "UTF-8"))
src = builder.append(resourcePath).append("&").append(Constants.DYNAMIC_CONTENT_PARAM).append("=").append(URLEncoder.encode(sessionKey, "UTF-8"))
.append("&").append(Constants.DYNAMIC_CONTENT_TYPE_PARAM).append("=").append(dynamicContentType.toString())
.append("&gen=").append(type)
.append("&fmt=").append(barcode.getFormat())
@@ -72,7 +80,7 @@ public void encodeEnd(FacesContext context, UIComponent component) throws IOExce
if(shouldWriteId(component)) writer.writeAttribute("id", clientId, "id");
if(styleClass != null) writer.writeAttribute("class", styleClass, "styleClass");

writer.writeAttribute("src", src, null);
writer.writeAttribute("src", context.getExternalContext().encodeResourceURL(src), null);

renderPassThruAttributes(context, barcode, HTML.IMG_ATTRS);

@@ -66,6 +66,8 @@
public static final String DYNAMIC_CONTENT_TYPE_PARAM = "pfdrt";
public static final String DYNAMIC_RESOURCES_MAPPING = "primefaces.dynamicResourcesMapping";

public static final String BARCODE_MAPPING = "primefaces.barcodeMapping";

public final static String FRAGMENT_ID = "primefaces.fragment";
public final static String FRAGMENT_AUTO_RENDERED = "primefaces.fragment.autorendered";

0 comments on commit 7a30345

Please sign in to comment.
You can’t perform that action at this time.