1 19 20 package org.apache.excalibur.instrument.manager.http; 21 22 import java.io.IOException ; 23 import java.io.PrintWriter ; 24 import java.util.Map ; 25 26 import org.apache.excalibur.instrument.manager.http.server.HTTPRedirect; 27 import org.apache.excalibur.instrument.manager.DefaultInstrumentManager; 28 import org.apache.excalibur.instrument.manager.InstrumentSampleDescriptor; 29 import org.apache.excalibur.instrument.manager.NoSuchInstrumentSampleException; 30 31 37 public class HTMLSampleLeaseHandler 38 extends AbstractHTMLHandler 39 { 40 43 49 public HTMLSampleLeaseHandler( DefaultInstrumentManager manager, 50 InstrumentManagerHTTPConnector connector ) 51 { 52 super( "/sample-lease.html", manager, connector ); 53 } 54 55 58 65 public void doGet( String path, Map parameters, PrintWriter out ) 66 throws IOException 67 { 68 String name = getParameter( parameters, "name" ); 69 long lease = getLongParameter( parameters, "lease" ); 70 String instrument = getParameter( parameters, "instrument", null ); 71 String chart = getParameter( parameters, "chart", null ); 72 73 InstrumentSampleDescriptor desc; 74 try 75 { 76 desc = getInstrumentManager().locateInstrumentSampleDescriptor( name ); 77 } 78 catch ( NoSuchInstrumentSampleException e ) 79 { 80 int pos = name.lastIndexOf( '.' ); 82 if ( pos >= 0 ) 83 { 84 throw new HTTPRedirect( 85 "instrument.html?name=" + urlEncode( name.substring( 0, pos ) ) ); 86 } 87 else 88 { 89 throw new HTTPRedirect( "instrument-manager.html" ); 90 } 91 } 92 93 lease = Math.max( 1, Math.min( lease, getConnector().getMaxLeasedSampleLease() ) ); 97 98 if ( getInstrumentManager().getLeaseSampleCount() >= getConnector().getMaxLeasedSamples() ) 99 { 100 lease = 1; 101 } 102 103 desc.extendLease( lease ); 105 106 if ( instrument != null ) 107 { 108 int pos = name.lastIndexOf( '.' ); 110 if ( pos >= 0 ) 111 { 112 throw new HTTPRedirect( 113 "instrument.html?name=" + urlEncode( name.substring( 0, pos ) ) ); 114 } 115 else 116 { 117 throw new HTTPRedirect( "instrumentable.html" ); 118 } 119 } 120 else 121 { 122 throw new HTTPRedirect( "sample.html?name=" + urlEncode( desc.getName() ) 124 + ( chart == null ? "" : "&chart=true" ) ); 125 } 126 127 } 128 129 132 } 133 134 | Popular Tags |