1   package eu.fbk.dkm.pikes.tintop.server;
2   
3   import eu.fbk.dkm.pikes.tintop.AnnotationPipeline;
4   import ixa.kaflib.KAFDocument;
5   import org.apache.log4j.Logger;
6   import org.glassfish.grizzly.http.server.Request;
7   import org.glassfish.grizzly.http.server.Response;
8   
9   import java.io.File;
10  
11  /**
12   * Created with IntelliJ IDEA.
13   * User: alessio
14   * Date: 21/07/14
15   * Time: 15:30
16   * This class convert a raw NAF to a parsed one
17   */
18  
19  public class NafHandler extends AbstractHandler {
20  
21      static Logger logger = Logger.getLogger(NafHandler.class.getName());
22  
23      public NafHandler(AnnotationPipeline pipeline) {
24          super(pipeline);
25      }
26  
27      @Override
28      public void service(Request request, Response response) throws Exception {
29  
30          logger.debug("Starting service");
31          super.service(request, response);
32  
33          String naf = request.getParameter("naf");
34          KAFDocument doc;
35  
36          try {
37              doc = pipeline.parseFromString(naf);
38          } catch (Exception e) {
39              e.printStackTrace();
40              throw new Exception(e);
41          }
42  
43  //        File temp = File.createTempFile("temp-file-name", ".tmp");
44  //        logger.info("Created temp file " + temp.getAbsolutePath());
45  //        doc.save(temp);
46  
47          logger.trace(doc.toString());
48  
49          writeOutput(response, "text/xml", doc.toString());
50      }
51  }