1 22 23 package com.dotmarketing.cms.factories; 24 25 import java.io.BufferedInputStream ; 26 import java.io.ByteArrayOutputStream ; 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.util.ArrayList ; 30 import java.util.List ; 31 32 import javax.servlet.ServletContext ; 33 34 import com.dotmarketing.exception.DotRuntimeException; 35 import com.dotmarketing.util.Config; 36 import com.liferay.portal.SystemException; 37 import com.liferay.portal.ejb.CompanyLocalManagerUtil; 38 import com.liferay.portal.ejb.CompanyUtil; 39 import com.liferay.portal.ejb.ImageManagerUtil; 40 import com.liferay.portal.model.Company; 41 42 49 public class PublicCompanyFactory extends CompanyUtil { 50 51 public static Company getDefaultCompany() { 52 try { 53 54 return findByPrimaryKey(getDefaultCompanyId()); 55 56 } catch (Exception e) { 57 throw new DotRuntimeException("No Company!"); 58 59 } 60 } 61 62 public static String getDefaultCompanyId() { 63 try { 64 ServletContext c = Config.CONTEXT; 65 return c.getInitParameter("company_id"); 66 67 } catch (Exception e) { 68 throw new DotRuntimeException("No Default Company Id!"); 69 70 } 71 } 72 73 74 75 public static List getCompanies() { 76 77 try { 78 return findAll(); 79 } catch (SystemException e) { 80 e.printStackTrace(); 82 } 83 return new ArrayList (); 84 85 } 86 87 88 93 public static void createDefaultCompany() { 94 try { 95 Company c = getDefaultCompany(); 96 c.setPortalURL("localhost"); 97 c 98 .setKey("rO0ABXNyABRqYXZhLnNlY3VyaXR5LktleVJlcL35T7OImqVDAgAETAAJYWxnb3JpdGhtdAASTGphdmEvbGFuZy9TdHJpbmc7WwAHZW5jb2RlZHQAAltCTAAGZm9ybWF0cQB+AAFMAAR0eXBldAAbTGphdmEvc2VjdXJpdHkvS2V5UmVwJFR5cGU7eHB0AANERVN1cgACW0Ks8xf4BghU4AIAAHhwAAAACBksSlj3ReywdAADUkFXfnIAGWphdmEuc2VjdXJpdHkuS2V5UmVwJFR5cGUAAAAAAAAAABIAAHhyAA5qYXZhLmxhbmcuRW51bQAAAAAAAAAAEgAAeHB0AAZTRUNSRVQ="); 99 c.setHomeURL("localhost"); 100 c.setMx("localhost"); 101 c.setName("dotcms.org"); 102 c.setShortName("dotcms.org"); 103 c.setType("biz"); 104 c.setSize("100"); 105 c.setState("FL"); 106 c.setStreet("2424 S. Dixie Hwy."); 107 c.setCity("Miami"); 108 c.setZip("33133"); 109 c.setPhone("3058581422"); 110 c.setEmailAddress("support@dotcms.org"); 111 c.setAuthType("emailAddress"); 112 c.setStrangers(false); 113 c.setAutoLogin(true); 114 c.setModified(true); 115 116 CompanyUtil.update(c); 117 118 119 File f = new File (Config.CONTEXT.getRealPath("/portal/images/logo.gif")); 120 121 BufferedInputStream in = new BufferedInputStream (new FileInputStream (f)); 122 123 ByteArrayOutputStream baout = new ByteArrayOutputStream (); 124 125 byte[] buf = new byte[2048]; 126 int i = 0; 127 while ((i = in.read(buf)) != -1) { 128 baout.write(buf, 0, i); 129 } 130 131 in.close(); 132 133 ImageManagerUtil.updateImage("dotcms.org", baout.toByteArray()); 134 135 } catch (Exception e) { 136 e.printStackTrace(System.out); 137 } 138 139 } 140 141 } | Popular Tags |