Advertisement
kugelbergerer

Untitled

Jan 8th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. <?xml version="1.0" encoding="ISO-8859-1" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml"
  4. xmlns:h="http://java.sun.com/jsf/html"
  5. xmlns:ui="http://java.sun.com/jsf/facelets">
  6.  
  7.  
  8. <ui:composition template="ComplexTemplateHeaderMenuDetail.xhtml">
  9. <ui:define name="content">
  10. <h1>Upload Videos to Library</h1>
  11. <h:form enctype="multipart/form-data">
  12. <h:panelGrid border="0" columns="2">
  13. <h:outputText value="Audio/Video Datei"></h:outputText>
  14. <h:inputFile value="#{UploadController.MVFile}"></h:inputFile>
  15. </h:panelGrid>
  16. <h:commandButton value="Upload" action="#{UploadController.uploadMVFile()}" ></h:commandButton>
  17. </h:form>
  18. </ui:define>
  19. </ui:composition>
  20.  
  21. </html>
  22.  
  23.  
  24.  
  25.  
  26. #######################Controller###############
  27.  
  28.  
  29. B_UploadController
  30.  
  31.  
  32. package impl_upload;
  33.  
  34. import javax.enterprise.context.RequestScoped;
  35. import javax.inject.Inject;
  36. import javax.inject.Named;
  37. import javax.servlet.http.Part;
  38.  
  39.  
  40. @Named
  41. @RequestScoped
  42. public class B_UploadController {
  43.  
  44. @Inject
  45. private I_MVFileService mvservice;
  46. private Part mvfile;
  47.  
  48. public Part getMVFile() {
  49. return mvfile;
  50. }
  51.  
  52. public void setMFFile(Part mvfile) {
  53. this.mvfile = mvfile;
  54. }
  55. public String uploadeMVFile() {
  56.  
  57. try {
  58. String fileName = mvfile.getSubmittedFileName();
  59.  
  60. mvservice.addMVFileToRep( fileName, mvfile.getInputStream() );
  61. }
  62. catch( Exception e ) {
  63. e.printStackTrace();
  64. }
  65. return "OVERVIEW";
  66. }
  67. }
  68.  
  69.  
  70.  
  71. ################# I_MVFileService ###############
  72.  
  73.  
  74. package impl_upload;
  75.  
  76. import java.io.IOException;
  77. import java.io.InputStream;
  78.  
  79.  
  80. public interface I_MVFileService {
  81.  
  82. public void addMVFileToRep( String name, InputStream data ) throws IOException;
  83.  
  84.  
  85. }
  86.  
  87.  
  88. #################### C_MVFileServiceLogic #################
  89.  
  90.  
  91. package impl_upload;
  92.  
  93. import java.io.ByteArrayOutputStream;
  94. import java.io.IOException;
  95. import java.io.InputStream;
  96.  
  97. import javax.inject.Inject;
  98.  
  99. public class C_MVFileServiceLogic implements I_MVFileService {
  100. @Inject
  101. I_PostStream pstream;
  102.  
  103. @Inject
  104. I_MVFileRep repository;
  105.  
  106. @Override
  107. private void addMVToRep( String name, InputStream data ) throws IOException {
  108.  
  109. ByteArrayOutputStream bOut = new ByteArrayOutputStream();
  110. byte [] buffer = new byte[1024];
  111. int size;
  112. String filepath;
  113.  
  114. size = data.read( buffer);
  115.  
  116. while( size > 0 ) {
  117. bOut.write( buffer, 0, size );
  118. size = data.read( buffer);
  119. }
  120.  
  121. filepath = pstream.AddStream(name, bOut.toByteArray());
  122. bOut.close();
  123.  
  124.  
  125. M_MVFile mvfile = new M_MVFile (null, name, filepath);
  126.  
  127. repository.storeMVFile( mvfile );
  128. }
  129. }
  130.  
  131.  
  132.  
  133. ###### I_MVFileRep ################
  134.  
  135. package impl_upload;
  136.  
  137. import java.io.IOException;
  138.  
  139. public interface I_MVFileRep {
  140.  
  141. public void storeMVFile(M_MVFile mvfile) throws IOException ;
  142. }
  143.  
  144.  
  145.  
  146. ################ C_MVFileRep ##############
  147.  
  148.  
  149.  
  150. package impl_upload;
  151.  
  152. import java.io.IOException;
  153.  
  154. import javax.persistence.EntityManager;
  155. import javax.persistence.PersistenceContext;
  156.  
  157. import com.sun.xml.ws.api.tx.at.Transactional;
  158.  
  159. public class C_MVFileRepLogic implements I_MVFileRep {
  160.  
  161.  
  162. @PersistenceContext
  163.  
  164. private EntityManager entityManager;
  165.  
  166. private int count;
  167.  
  168. private String makeIdentifier() {
  169. return "IMG_" + System.currentTimeMillis() + "_" + ( count++ ) + ".png";
  170. }
  171.  
  172. @Transactional(TxType.REQUIRED)
  173. public void storeMVFile( M_MVFile mvfile ) throws IOException {
  174. mvfile.setIdentifier(makeIdentifier());
  175. entityManager.persist( mvfile );
  176. }
  177.  
  178. }
  179.  
  180.  
  181. ################### M_MVFile ##################
  182.  
  183.  
  184. package impl_upload;
  185.  
  186.  
  187. import javax.persistence.Access;
  188. import javax.persistence.AccessType;
  189. import javax.persistence.Entity;
  190. import javax.persistence.Id;
  191.  
  192.  
  193. public class M_MVFile {
  194.  
  195. private String identifier;
  196. private String name;
  197. private String link;
  198.  
  199. public M_MVFile(String identifier, String name, String link) {
  200. super();
  201. this.identifier = identifier;
  202. this.name = name;
  203. this.link = link;
  204.  
  205. }
  206.  
  207.  
  208. public M_MVFile() {
  209. super();
  210. }
  211.  
  212. public String getIdentifier() {
  213. return identifier;
  214. }
  215.  
  216. public void setIdentifier(String identifier) {
  217. this.identifier = identifier;
  218. }
  219.  
  220. public String getName() {
  221. return name;
  222. }
  223.  
  224. public void setName(String name) {
  225. this.name = name;
  226. }
  227.  
  228. public String getLink() {
  229. return link;
  230. }
  231.  
  232. public void setLink(String link) {
  233. this.link = link;
  234. }
  235.  
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement