KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > cms > factories > PublicCompanyFactory


1 /**
2  * Copyright (c) 2000-2004 Liferay, LLC. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */

22
23 package com.dotmarketing.cms.factories;
24
25 import java.io.BufferedInputStream JavaDoc;
26 import java.io.ByteArrayOutputStream JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.FileInputStream JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31
32 import javax.servlet.ServletContext JavaDoc;
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 /**
43  * <a HREF="AddressUtil.java.htm"><b><i>View Source</i></b></a>
44  *
45  * @author Brian Wing Shun Chan
46  * @version $Revision: 1.1 $
47  *
48  */

49 public class PublicCompanyFactory extends CompanyUtil {
50
51     public static Company getDefaultCompany() {
52         try {
53
54             return findByPrimaryKey(getDefaultCompanyId());
55
56         } catch (Exception JavaDoc e) {
57             throw new DotRuntimeException("No Company!");
58
59         }
60     }
61
62     public static String JavaDoc getDefaultCompanyId() {
63         try {
64             ServletContext JavaDoc c = Config.CONTEXT;
65             return c.getInitParameter("company_id");
66
67         } catch (Exception JavaDoc e) {
68             throw new DotRuntimeException("No Default Company Id!");
69
70         }
71     }
72     
73     
74
75     public static List JavaDoc getCompanies() {
76             
77             try {
78                 return findAll();
79             } catch (SystemException e) {
80                 // TODO Auto-generated catch block
81
e.printStackTrace();
82             }
83             return new ArrayList JavaDoc();
84     
85     }
86     
87
88     /*
89      * This method runs the first time a server is started. It creates the
90      * default company and default logo.
91      *
92      */

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             /* Set the DM logo */
119             File JavaDoc f = new File JavaDoc(Config.CONTEXT.getRealPath("/portal/images/logo.gif"));
120
121             BufferedInputStream JavaDoc in = new BufferedInputStream JavaDoc(new FileInputStream JavaDoc(f));
122
123             ByteArrayOutputStream JavaDoc baout = new ByteArrayOutputStream JavaDoc();
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 JavaDoc e) {
136             e.printStackTrace(System.out);
137         }
138
139     }
140
141 }
Popular Tags