1 23 24 package org.apache.slide.projector.processor.query; 25 26 import java.util.Map ; 27 28 import org.apache.slide.projector.Context; 29 import org.apache.slide.projector.Processor; 30 import org.apache.slide.projector.Projector; 31 import org.apache.slide.projector.Result; 32 import org.apache.slide.projector.descriptor.ParameterDescriptor; 33 import org.apache.slide.projector.descriptor.ResultDescriptor; 34 import org.apache.slide.projector.descriptor.ResultEntryDescriptor; 35 import org.apache.slide.projector.descriptor.StateDescriptor; 36 import org.apache.slide.projector.descriptor.StringValueDescriptor; 37 import org.apache.slide.projector.i18n.DefaultMessage; 38 import org.apache.slide.projector.i18n.ParameterMessage; 39 import org.apache.slide.projector.processor.SimpleProcessor; 40 import org.apache.slide.projector.value.ArrayValue; 41 import org.apache.slide.projector.value.StringValue; 42 import org.apache.slide.projector.value.Value; 43 44 48 public class ResourceQuery implements Processor { 49 private final static String EMPTY = "empty"; 50 private final static String DASL_QUERY = "query"; 51 52 private static ResultDescriptor resultDescriptor = new ResultDescriptor( 53 new StateDescriptor[] { 54 StateDescriptor.OK_DESCRIPTOR, 55 new StateDescriptor(EMPTY, new DefaultMessage("resourceQuery/state/empty"))}, 56 new ResultEntryDescriptor[] { 57 new ResultEntryDescriptor(SimpleProcessor.OUTPUT, new DefaultMessage("queryResult"), ArrayValue.CONTENT_TYPE, false) 58 }); 59 60 private static ParameterDescriptor []parameterDescriptors = new ParameterDescriptor[] { 61 new ParameterDescriptor(DASL_QUERY, new ParameterMessage("daslQuery"), new StringValueDescriptor()) 62 }; 63 64 public Result process(Map parameter, Context context) throws Exception { 65 String query = ((StringValue)parameter.get(DASL_QUERY)).toString(); 66 Value []values = Projector.getRepository().search(query, context.getCredentials()); 67 if ( values.length == 0 ) return new Result(EMPTY); 68 return new Result(StateDescriptor.OK, SimpleProcessor.OUTPUT, new ArrayValue(values)); 69 } 70 71 public ParameterDescriptor[] getParameterDescriptors() { 72 return parameterDescriptors; 73 } 74 75 public ResultDescriptor getResultDescriptor() { 76 return resultDescriptor; 77 } 78 } | Popular Tags |