Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="ISO-8859-1" ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml"
- xmlns:h="http://java.sun.com/jsf/html"
- xmlns:ui="http://java.sun.com/jsf/facelets">
- <ui:composition template="ComplexTemplateHeaderMenuDetail.xhtml">
- <ui:define name="content">
- <h1>Upload Videos to Library</h1>
- <h:form enctype="multipart/form-data">
- <h:panelGrid border="0" columns="2">
- <h:outputText value="Audio/Video Datei"></h:outputText>
- <h:inputFile value="#{UploadController.MVFile}"></h:inputFile>
- </h:panelGrid>
- <h:commandButton value="Upload" action="#{UploadController.uploadMVFile()}" ></h:commandButton>
- </h:form>
- </ui:define>
- </ui:composition>
- </html>
- #######################Controller###############
- B_UploadController
- package impl_upload;
- import javax.enterprise.context.RequestScoped;
- import javax.inject.Inject;
- import javax.inject.Named;
- import javax.servlet.http.Part;
- @Named
- @RequestScoped
- public class B_UploadController {
- @Inject
- private I_MVFileService mvservice;
- private Part mvfile;
- public Part getMVFile() {
- return mvfile;
- }
- public void setMFFile(Part mvfile) {
- this.mvfile = mvfile;
- }
- public String uploadeMVFile() {
- try {
- String fileName = mvfile.getSubmittedFileName();
- mvservice.addMVFileToRep( fileName, mvfile.getInputStream() );
- }
- catch( Exception e ) {
- e.printStackTrace();
- }
- return "OVERVIEW";
- }
- }
- ################# I_MVFileService ###############
- package impl_upload;
- import java.io.IOException;
- import java.io.InputStream;
- public interface I_MVFileService {
- public void addMVFileToRep( String name, InputStream data ) throws IOException;
- }
- #################### C_MVFileServiceLogic #################
- package impl_upload;
- import java.io.ByteArrayOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import javax.inject.Inject;
- public class C_MVFileServiceLogic implements I_MVFileService {
- @Inject
- I_PostStream pstream;
- @Inject
- I_MVFileRep repository;
- @Override
- private void addMVToRep( String name, InputStream data ) throws IOException {
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
- byte [] buffer = new byte[1024];
- int size;
- String filepath;
- size = data.read( buffer);
- while( size > 0 ) {
- bOut.write( buffer, 0, size );
- size = data.read( buffer);
- }
- filepath = pstream.AddStream(name, bOut.toByteArray());
- bOut.close();
- M_MVFile mvfile = new M_MVFile (null, name, filepath);
- repository.storeMVFile( mvfile );
- }
- }
- ###### I_MVFileRep ################
- package impl_upload;
- import java.io.IOException;
- public interface I_MVFileRep {
- public void storeMVFile(M_MVFile mvfile) throws IOException ;
- }
- ################ C_MVFileRep ##############
- package impl_upload;
- import java.io.IOException;
- import javax.persistence.EntityManager;
- import javax.persistence.PersistenceContext;
- import com.sun.xml.ws.api.tx.at.Transactional;
- public class C_MVFileRepLogic implements I_MVFileRep {
- @PersistenceContext
- private EntityManager entityManager;
- private int count;
- private String makeIdentifier() {
- return "IMG_" + System.currentTimeMillis() + "_" + ( count++ ) + ".png";
- }
- @Transactional(TxType.REQUIRED)
- public void storeMVFile( M_MVFile mvfile ) throws IOException {
- mvfile.setIdentifier(makeIdentifier());
- entityManager.persist( mvfile );
- }
- }
- ################### M_MVFile ##################
- package impl_upload;
- import javax.persistence.Access;
- import javax.persistence.AccessType;
- import javax.persistence.Entity;
- import javax.persistence.Id;
- public class M_MVFile {
- private String identifier;
- private String name;
- private String link;
- public M_MVFile(String identifier, String name, String link) {
- super();
- this.identifier = identifier;
- this.name = name;
- this.link = link;
- }
- public M_MVFile() {
- super();
- }
- public String getIdentifier() {
- return identifier;
- }
- public void setIdentifier(String identifier) {
- this.identifier = identifier;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getLink() {
- return link;
- }
- public void setLink(String link) {
- this.link = link;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement