tabular-data-manager/src/main/java/org/gcube/portlets/user/td/server/TabularDataServiceImpl.java

78 lines
2.5 KiB
Java

package org.gcube.portlets.user.td.server;
import javax.servlet.ServletException;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.portlets.user.csvimportwizardgxt3.server.csv.CSVTargetRegistry;
import org.gcube.portlets.user.csvimportwizardgxt3.server.csv.DemoCSVTarget;
import org.gcube.portlets.user.td.ciw.server.CSVTDImporter;
import org.gcube.portlets.user.td.client.rpc.TabularDataService;
import org.gcube.portlets.user.td.importer.server.TabularDataImporterManager;
import org.gcube.portlets.user.td.shared.FieldVerifier;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
/**
* The server side implementation of the RPC service.
*/
@SuppressWarnings("serial")
public class TabularDataServiceImpl extends RemoteServiceServlet implements TabularDataService {
/**
* {@inheritDoc}
*/
@Override
public void init() throws ServletException {
super.init();
System.out.println("initializing the TabularDataImporterManager");
TabularDataImporterManager importerManager = new TabularDataImporterManager();
//importerManager.scanAvailableImporters();
importerManager.add(new CSVTDImporter());
importerManager.setupImporters();
//register the demo csv target
//CSVTargetRegistry.getInstance().add(new DemoCSVTarget());
//System.out.println("Registered DemoCSVTarget");
ScopeProvider.instance.set("/gcube/devsec");
}
/**
* {@inheritDoc}
*/
public String greetServer(String input) throws IllegalArgumentException {
// Verify that the input is valid.
if (!FieldVerifier.isValidName(input)) {
// If the input is not valid, throw an IllegalArgumentException back to
// the client.
throw new IllegalArgumentException(
"Name must be at least 4 characters long");
}
String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");
// Escape data from the client to avoid cross-site script vulnerabilities.
input = escapeHtml(input);
userAgent = escapeHtml(userAgent);
return "Hello, " + input + "!<br><br>I am running " + serverInfo
+ ".<br><br>It looks like you are using:<br>" + userAgent;
}
/**
* Escape an html string. Escaping data received from the client helps to
* prevent cross-site script vulnerabilities.
*
* @param html the html string to escape
* @return the escaped string
*/
private String escapeHtml(String html) {
if (html == null) {
return null;
}
return html.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(
">", "&gt;");
}
}