001/** 002 * Copyright (C) 2014 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/ 003 * 004 * This file is part of Dicoogle/dicoogle. 005 * 006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Dicoogle/dicoogle is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU General Public License for more details. 015 * 016 * You should have received a copy of the GNU General Public License 017 * along with Dicoogle. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package pt.ua.dicoogle.server.web.rest; 020 021import java.io.StringWriter; 022import java.util.Set; 023import org.slf4j.Logger; 024import org.slf4j.LoggerFactory; 025import org.slf4j.Logger; 026import org.slf4j.LoggerFactory; 027import javax.xml.bind.JAXBContext; 028import javax.xml.bind.Marshaller; 029import org.restlet.data.MediaType; 030import org.restlet.representation.Representation; 031import org.restlet.representation.StringRepresentation; 032import org.restlet.resource.Get; 033import org.restlet.resource.ServerResource; 034import pt.ua.dicoogle.server.web.rest.elements.JaxbStrList; 035 036/** 037 * 038 * @author Samuel Campos <samuelcampos@ua.pt> 039 */ 040public class RestEnumField extends ServerResource{ 041 042 043 044 @Get 045 public Representation represent(){ 046 StringRepresentation sr; 047 /* 048 IndexEngine core = IndexEngine.getInstance(); 049 String field = getRequest().getResourceRef().getQueryAsForm().getValues("field"); 050 String type = getRequest().getResourceRef().getQueryAsForm().getValues("type"); 051 052 if(field == null){ 053 return new StringRepresentation("", MediaType.APPLICATION_XML); 054 } 055 056 if(type == null){ 057 type = "text"; 058 } 059 060 Set<String> enumList = null; 061 062 if(type.equalsIgnoreCase("text")){ 063 enumList = core.enumField(field, false); 064 } 065 else if(type.equalsIgnoreCase("float")){ 066 enumList = core.enumField(field, true); 067 } 068 069 JaxbStrList jaxbList = new JaxbStrList(enumList); 070 071 StringWriter sw = new StringWriter(); 072 073 try { 074 JAXBContext context = JAXBContext.newInstance(JaxbStrList.class); 075 Marshaller m = context.createMarshaller(); 076 m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); 077 078 m.marshal(jaxbList, sw); 079 080 sr = new StringRepresentation(sw.toString(), MediaType.APPLICATION_XML); 081 082 } catch (Exception ex) { 083 LoggerFactory.getLogger(RestTagsResource.class).error(ex.getMessage(), ex); 084 085 sr = new StringRepresentation("", MediaType.APPLICATION_XML); 086 } 087 088 return sr;*/ 089 throw new UnsupportedOperationException(); 090 } 091}