blob: ba8cd824fee21d93a5ce2cfcb3301015d480f227 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.openaz.xacml.admin.util;
import java.io.IOException;
import com.vaadin.server.FileDownloader;
import com.vaadin.server.StreamResource;
import com.vaadin.server.StreamResource.StreamSource;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinResponse;
import com.vaadin.ui.UI;
public class OnDemandFileDownloader extends FileDownloader {
private static final long serialVersionUID = 1L;
private final OnDemandStreamResource resource;
public interface OnDemandStreamResource extends StreamSource {
String getFilename ();
}
public OnDemandFileDownloader(OnDemandStreamResource resource) {
super(new StreamResource(resource, ""));
this.resource = resource;
if (this.resource == null) {
throw new NullPointerException("Can't send null resource");
}
}
@Override
public boolean handleConnectorRequest(VaadinRequest request,
VaadinResponse response, String path) throws IOException {
this.getResource().setFilename(this.resource.getFilename());
return super.handleConnectorRequest(request, response, path);
}
private StreamResource getResource() {
StreamResource resource = null;
UI.getCurrent().getSession().lock();
try {
resource = (StreamResource) this.getResource("dl");
} finally {
UI.getCurrent().getSession().unlock();
}
return resource;
}
}