Skip to content
Snippets Groups Projects
Commit c1a3aa50 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

old unused code removed

parent 150b445c
No related branches found
No related tags found
1 merge request!782Resolve "Replace deprecated APIs"
package lcsb.mapviewer.web.bean.utils;
import java.util.Map;
import javax.faces.component.UIComponent;
/**
* Intefrace of the class that access data about connection and PF framework in
* general.
*
* @author Piotr Gawron
*
*/
public interface IPrimefacesUtils {
/**
* Returns value of the request parameter.
*
* @param name
* name of the parameter
* @return value of the request parameter
*/
String getRequestParameter(String name);
/**
* Returns path on hard drive to the project.
*
* @return path where the projest is run
*/
String getPath();
/**
* Returns ip address of current client.
*
* @return IP addresss of the client
*/
String getClientIpAddress();
/**
* Sends an error message to the client.
*
* @param message
* error message to be sent
*/
void error(String message);
/**
* Sends an info message to client.
*
* @param message
* info message to be sent
*/
void info(String message);
/**
* Returns version of primefaces.
*
* @return version of primefaces library
*/
String getVersion();
/**
* Returns a {@link UIComponent} corresponding to the client side component
* with the identifier given in the parameter.
*
* @param id
* identifier of a component
* @return {@link UIComponent} corresponding to the client side component with
* the identifier given in the parameter
*/
UIComponent findComponent(String id);
/**
* Adds parameter to a ajax response.
*
* @param key
* name of the parameter
* @param value
* value of the parameter
*/
void addCallbackParam(String key, Object value);
/**
* Returns request parameters map.
*
* @return request parameters map
*/
Map<String, String> getRequestParameterMap();
/**
* Adds a parameter that will be stored in user session.
*
* @param key
* name of the parameter
* @param value
* value of the parameter
*/
void addSessionParam(String key, Object value);
/**
* Gets a value of the parameter stored in user session.
*
* @param key
* name of the parameter
* @return value of the user session parameter
*/
Object getSessionParam(String key);
/**
* Creates http session if session hasn't been created yet.
*/
void createSession();
/**
* Returns bean identified by {@link Class}.
*
* @param clazz
* class of the bean
* @param <T>
* class of the bean
* @return bean identified by {@link Class}
*/
<T> T findBean(Class<T> clazz);
/**
* Executes javascript code on client.
*
* @param javascript
* code to execute
*/
void executeJavascript(String javascript);
}
\ No newline at end of file
package lcsb.mapviewer.web.bean.utils;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.*;
import org.primefaces.context.RequestContext;
import org.springframework.web.jsf.FacesContextUtils;
/**
* Util class containing some useful methods in Primefaces.
*
* @author Piotr Gawron
*
*/
public class PrimefacesUtils implements IPrimefacesUtils {
/**
* Default class logger.
*/
private final transient Logger logger = LogManager.getLogger(PrimefacesUtils.class);
/**
* Default constructor.
*/
public PrimefacesUtils() {
}
@Override
public String getRequestParameter(final String name) {
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
}
@Override
public String getPath() {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
return context.getExternalContext().getRealPath("/");
} else {
String path;
try {
path = new File(".").getCanonicalPath() + "/";
} catch (IOException e) {
logger.warn("Problem with detecting current path", e);
path = "";
}
return path;
}
}
@Override
public String getClientIpAddress() {
HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
String ipAddress = httpServletRequest.getRemoteAddr();
if (ipAddress == null) {
ipAddress = FacesContext.getCurrentInstance().getExternalContext().getRequestHeaderMap().get("X-FORWARDED-FOR");
}
return ipAddress;
}
@Override
public void error(final String message) {
logger.debug("Error sent to PF: " + message);
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", message));
}
@Override
public void info(final String message) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", message));
}
@Override
public String getVersion() {
return RequestContext.getCurrentInstance().getApplicationContext().getConfig().getBuildVersion();
}
@Override
public UIComponent findComponent(String id) {
return FacesContext.getCurrentInstance().getViewRoot().findComponent(id);
}
@Override
public void addCallbackParam(String key, Object value) {
RequestContext.getCurrentInstance().addCallbackParam(key, value);
}
@Override
public Map<String, String> getRequestParameterMap() {
return FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
}
@Override
public void addSessionParam(String key, Object value) {
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
}
@Override
public Object getSessionParam(String key) {
return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key);
}
@Override
public void createSession() {
FacesContext.getCurrentInstance().getExternalContext().getSession(true);
}
@Override
public <T> T findBean(Class<T> clazz) {
return FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance()).getBean(clazz);
}
@Override
public void executeJavascript(String javascript) {
RequestContext.getCurrentInstance().execute(javascript);
}
}
package lcsb.mapviewer.web.bean.utils;
import java.io.File;
import java.io.IOException;
import javax.faces.application.Resource;
import javax.faces.application.ResourceHandler;
import javax.faces.application.ResourceHandlerWrapper;
import javax.faces.application.ResourceWrapper;
import javax.faces.context.FacesContext;
import lcsb.mapviewer.services.impl.ConfigurationService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.*;
import lcsb.mapviewer.services.impl.ConfigurationService;
/**
* This class is used to provide url for jsf resource files with "?v=version"
......@@ -18,95 +23,114 @@ import org.apache.logging.log4j.*;
*
*/
public class VersionResourceHandler extends ResourceHandlerWrapper {
/**
* Default class logger.
*/
private final Logger logger = LogManager.getLogger(VersionResourceHandler.class);
/**
* SVN version of the system.
*/
private static String version = null;
/**
* Resource for which we generate modified url.
*/
private ResourceHandler wrapped;
/**
* Default constructor.
*
* @param wrapped
* {@link #wrapped}
*/
public VersionResourceHandler(ResourceHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public Resource createResource(String resourceName) {
return createResource(resourceName, null, null);
}
@Override
public Resource createResource(String resourceName, String libraryName) {
return createResource(resourceName, libraryName, null);
}
@Override
public Resource createResource(String resourceName, String libraryName, String contentType) {
final Resource resource = super.createResource(resourceName, libraryName, contentType);
if (resource == null) {
return null;
}
return new ResourceWrapper() {
@Override
public String getRequestPath() {
return super.getRequestPath() + "&m_version=" + getVersion();
}
@Override
public Resource getWrapped() {
return resource;
}
@Override
public String getContentType() {
return getWrapped().getContentType();
}
@Override
public String getResourceName() {
return getWrapped().getResourceName();
}
@Override
public String getLibraryName() {
return getWrapped().getLibraryName();
}
};
}
@Override
public ResourceHandler getWrapped() {
return wrapped;
}
/**
* This method returns git version of the framework.
*
* @return git version of the framework
*/
private String getVersion() {
if (version == null) {
try {
version = new ConfigurationService(null).getSystemGitVersion(new PrimefacesUtils().getPath());
} catch (Exception e) {
logger.error(e, e);
version = "UNKNOWN";
}
}
return version;
}
/**
* Default class logger.
*/
private final Logger logger = LogManager.getLogger(VersionResourceHandler.class);
/**
* GIT version of the system.
*/
private static String version = null;
/**
* Resource for which we generate modified url.
*/
private ResourceHandler wrapped;
/**
* Default constructor.
*
* @param wrapped
* {@link #wrapped}
*/
public VersionResourceHandler(ResourceHandler wrapped) {
this.wrapped = wrapped;
}
@Override
public Resource createResource(String resourceName) {
return createResource(resourceName, null, null);
}
@Override
public Resource createResource(String resourceName, String libraryName) {
return createResource(resourceName, libraryName, null);
}
@Override
public Resource createResource(String resourceName, String libraryName, String contentType) {
final Resource resource = super.createResource(resourceName, libraryName, contentType);
if (resource == null) {
return null;
}
return new ResourceWrapper() {
@Override
public String getRequestPath() {
return super.getRequestPath() + "&m_version=" + getVersion();
}
@Override
public Resource getWrapped() {
return resource;
}
@Override
public String getContentType() {
return getWrapped().getContentType();
}
@Override
public String getResourceName() {
return getWrapped().getResourceName();
}
@Override
public String getLibraryName() {
return getWrapped().getLibraryName();
}
};
}
@Override
public ResourceHandler getWrapped() {
return wrapped;
}
/**
* This method returns git version of the framework.
*
* @return git version of the framework
*/
private String getVersion() {
if (version == null) {
try {
version = new ConfigurationService(null).getSystemGitVersion(getPath());
} catch (Exception e) {
logger.error(e, e);
version = "UNKNOWN";
}
}
return version;
}
private String getPath() {
FacesContext context = FacesContext.getCurrentInstance();
if (context != null) {
return context.getExternalContext().getRealPath("/");
} else {
String path;
try {
path = new File(".").getCanonicalPath() + "/";
} catch (IOException e) {
logger.warn("Problem with detecting current path", e);
path = "";
}
return path;
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment