Skip to content

Instantly share code, notes, and snippets.

View Kotlin-Native's full-sized avatar

Pierre Liebsch Kotlin-Native

View GitHub Profile
class FluentELResolver extends BeanELResolver {
public boolean isReadOnly(ELContext context, Object base, Object property) {
if (base == null || !(property instanceof String)) {
return true;
}
Method method = getFluentMethod(context, base, property.toString());
if (method == null) {
return true;
}
@Kotlin-Native
Kotlin-Native / faces-config.xml
Created July 10, 2015 07:24
faces-config.xml
<faces-config>
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
<application>
<el-resolver>
de.openknowledge.extensions.el.FluentELResolver
</el-resolver>
</application>
public class DateAdapter extends XmlAdapter<String, XMLGregorianCalendar> {
@Override
public XMLGregorianCalendar unmarshal(String value) throws Exception {
...
}
@Override
public String marshal(XMLGregorianCalendar value) throws Exception {
...
@XmlJavaTypeAdapter(DateAdapter.class)
protected XMLGregorianCalendar dateOfBirth;
private static SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
...
@Override
public XMLGregorianCalendar unmarshal(String value)throws Exception {
...
Date date=format.parse(value);
GregorianCalendar calendar=new GregorianCalendar();
// Das Attribut 'format' wird als 'ThreadLocal' definiert:
private static ThreadLocal<SimpleDateFormat> format = new ThreadLocal<SimpleDateFormat>();
// Beim ersten Zugriff innerhalb eines Threads wird das Objekt initialisiert
private SimpleDateFormat getFormat() {
if (format.get() == null) {
format.set(new SimpleDateFormat("yyyy-MM-dd"));
}
return format.get();
}
private BigDecimal processNumberInput(String numberString)
throws ParseException {
Number number = numFormatGerman.parse(numberString);
...
String internalAmountString = numFormatEnglish.format(number);
...
return new BigDecimal(internalAmountString);
}
var messageReceived = function(event) {
var eventData = event.data.toString();
console.log("Received via socket: "+eventData);
};
var socket = new WebSocket("ws://www.example.com/mywebsocketapp/myspecializedsocket/do.connect");
socket.onmessage = messageReceived;
//send text to server
socket.send("testtext");
public class MyWebSocketApplication extends WebSocketApplication {
public boolean isApplicationRequest(Request request) {
// determine if this application is responsible for this websocket request (identification by incoming request)
return request.toString().contains("/mywebsocketapp/myspecializedsocket/do.connect");
}
public WebSocket createWebSocket(ProtocolHandler protocolHandler, WebSocketListener... listeners) {
// create a new WebSocket and add it to the list of Sockets hold by this app
WebSocket socket = new MyWebSocket(protocolHandler, listeners);
Map<String, Object> requestDataStore = new HashMap<String, Object>();
boundRequestContext.associate(requestDataStore);
boundRequestContext.activate();
useRequestScopeInHere();
try {
boundRequestContext.invalidate();
boundRequestContext.deactivate();
} finally {
boundRequestContext.dissociate(requestDataStore);
}