Ladies_Man

action1 (proc1)

Jun 8th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.22 KB | None | 0 0
  1. package ru.it.metasonic.workshop.actions;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileNotFoundException;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.text.SimpleDateFormat;
  11. import java.util.Date;
  12. import java.util.Properties;
  13.  
  14. import org.apache.commons.logging.Log;
  15. import org.apache.commons.logging.LogFactory;
  16.  
  17. import ru.it.metasonic.workshop.bo1.BO1View;
  18.  
  19. import de.metasonic.businessobjects.model.rules.AbstractServerAction;
  20.  
  21. public class action1 extends AbstractServerAction {
  22.    
  23.     Log log = LogFactory.getLog(action1.class);
  24.    
  25.     public final static String PROPERTY_HOME = "jcom1.property_home";
  26.     public final static String PROPERTY_FILE = "ru.it.metasonic.workshop.properties";
  27.     public final static String PROPERTY_NAME = "string4Default";
  28.    
  29.     private File dir, currentFile;
  30.     private BufferedReader reader;
  31.    
  32.     public void initBO() {
  33.         log.debug(">>>startting BO");
  34.        
  35.         boolean readingCurrently = false;
  36.         String text = "";
  37.        
  38.         dir = new File("/C:/Users/anthony/Documents/Metasonic Workshop/Development/Metasonic_Suite/plugins/com.jcom1.propertyfiles_5.2.1.201505132000/in_files/");
  39.         File filesList[] = dir.listFiles();
  40.        
  41.         if (null != filesList || 0!= filesList.length) {
  42.            
  43.             currentFile = filesList[0];
  44.             log.debug("-->currFile:" + currentFile.toString());
  45.            
  46.             try {
  47.                 reader = new BufferedReader(new InputStreamReader(
  48.                         new FileInputStream(currentFile)));
  49.                
  50.                 readingCurrently = true;
  51.             } catch (FileNotFoundException e) {
  52.                 // TODO Auto-generated catch block
  53.                 log.error(e);
  54.                 //e.printStackTrace();
  55.             }
  56.         }
  57.        
  58.         if (readingCurrently) {
  59.  
  60.             try {
  61.                
  62.                 String line;
  63.                 while (null != (line = reader.readLine())) {
  64.                     text += line + " ";
  65.                 }
  66.                
  67.                 reader.close();
  68.                 currentFile.delete();
  69.                
  70.                 log.debug("file has been deleted");
  71.                
  72.             } catch (IOException e) {
  73.                 // TODO Auto-generated catch block
  74.                 //e.printStackTrace();
  75.                 log.error(e);
  76.             }
  77.            
  78.            
  79.         }
  80.        
  81.         BO1View bo1View = (BO1View)getBean();
  82.        
  83.         bo1View.setString2(text);
  84.        
  85.         //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
  86.         //bo1View.setString2(sdf.format(new Date()));
  87.         //log.debug("string2: " + bo1View.getString2());
  88.        
  89.        
  90.        
  91.         /*String propertyHome = System.getProperty(PROPERTY_HOME);
  92.         log.debug("propertyHome: " + propertyHome);
  93.        
  94.         Properties properties = new Properties();
  95.        
  96.         File file = new File(propertyHome + "/" + PROPERTY_FILE);
  97.         InputStream inputStream = null;
  98.         try {
  99.             try {
  100.                 inputStream = new FileInputStream(file);
  101.                 properties.load(inputStream);
  102.                
  103.                 String defaultValue = properties.getProperty(PROPERTY_NAME);
  104.                 log.debug("defaultValue: " + defaultValue);
  105.                 bo1View.setString4(defaultValue);
  106.             } finally {
  107.                 if (null != inputStream) {
  108.                     inputStream.close();
  109.                 }
  110.             }
  111.         } catch(Exception e) {
  112.             log.error(e);
  113.         }*/
  114.     }
  115.    
  116.     public void updateBO() {
  117.        
  118.         BO1View bo1View = (BO1View)getBean();
  119.        
  120.         String string1 = bo1View.getString1();
  121.         String string3 = string1.toUpperCase();
  122.        
  123.         bo1View.setString3(string3);
  124.         log.debug("string3: " + bo1View.getString3());
  125.     }
  126.    
  127. }
Add Comment
Please, Sign In to add comment