Source Code Cross Referenced for DlmLayoutExporter.java in  » Portal » uPortal_rel-2-6-1-GA » org » jasig » portal » layout » dlm » publisher » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » uPortal_rel 2 6 1 GA » org.jasig.portal.layout.dlm.publisher 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright 2006 The JA-SIG Collaborative.  All rights reserved.
002:         *  See license distributed with this file and
003:         *  available online at http://www.uportal.org/license.html
004:         */
005:
006:        package org.jasig.portal.layout.dlm.publisher;
007:
008:        import java.io.FileOutputStream;
009:        import java.util.Enumeration;
010:
011:        import javax.xml.transform.OutputKeys;
012:        import javax.xml.transform.Result;
013:        import javax.xml.transform.Source;
014:        import javax.xml.transform.Transformer;
015:        import javax.xml.transform.TransformerFactory;
016:        import javax.xml.transform.dom.DOMSource;
017:        import javax.xml.transform.stream.StreamResult;
018:
019:        import org.apache.commons.logging.Log;
020:        import org.apache.commons.logging.LogFactory;
021:
022:        import org.jasig.portal.PortalException;
023:        import org.jasig.portal.StructureStylesheetUserPreferences;
024:        import org.jasig.portal.UserProfile;
025:        import org.jasig.portal.i18n.LocaleManager;
026:        import org.jasig.portal.layout.IUserLayout;
027:        import org.jasig.portal.layout.IUserLayoutManager;
028:        import org.jasig.portal.layout.IUserLayoutStore;
029:        import org.jasig.portal.layout.TransientUserLayoutManagerWrapper;
030:        import org.jasig.portal.layout.UserLayoutManagerFactory;
031:        import org.jasig.portal.layout.dlm.RDBMDistributedLayoutStore;
032:        import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
033:        import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
034:        import org.jasig.portal.layout.node.IUserLayoutNodeDescription;
035:        import org.jasig.portal.layout.node.UserLayoutFolderDescription;
036:        import org.jasig.portal.security.IPerson;
037:        import org.jasig.portal.security.PersonFactory;
038:        import org.jasig.portal.utils.DocumentFactory;
039:        import org.w3c.dom.Document;
040:        import org.w3c.dom.Element;
041:
042:        public class DlmLayoutExporter {
043:
044:            // Static Members.
045:            private static final Log log = LogFactory
046:                    .getLog(DlmLayoutExporter.class);
047:            private static final int PROFILE_ID = 1;
048:            private static final int LAYOUT_ID = 1;
049:            private static final int STYLESHEET_ID = 4;
050:            private static final int THEME_ID = 3;
051:
052:            public static void main(String[] args) {
053:
054:                // PrintWriter out = new PrintWriter(System.out);
055:                log.info("DLM Layout Exporter Tool");
056:                log.info("");
057:
058:                switch (args.length) {
059:                case 2:
060:
061:                    try {
062:
063:                        // Set up the layout store...
064:                        IUserLayoutStore store = new RDBMDistributedLayoutStore();
065:
066:                        // The first argument should be a valid username...
067:                        String uName = (args[0]);
068:                        System.out.print("Exporting layout for user '" + uName
069:                                + "'...");
070:                        int uId = DlmLayoutPublisher.lookupUserId(uName);
071:                        IPerson usr = PersonFactory.createGuestPerson();
072:                        usr.setAttribute(IPerson.USERNAME, uName);
073:                        usr.setID(uId);
074:
075:                        // Construct the layout manager...
076:                        UserProfile prf = new UserProfile(PROFILE_ID,
077:                                "User Profile for " + uName, "User Profile",
078:                                LAYOUT_ID, STYLESHEET_ID, THEME_ID);
079:                        LocaleManager lm = new LocaleManager(usr);
080:                        prf.setLocaleManager(lm);
081:                        IUserLayoutManager dlm = ((TransientUserLayoutManagerWrapper) UserLayoutManagerFactory
082:                                .getUserLayoutManager(usr, prf))
083:                                .getOriginalLayoutManager();
084:
085:                        // Retrieve the layout...
086:                        StructureStylesheetUserPreferences ssup = store
087:                                .getStructureStylesheetUserPreferences(usr,
088:                                        PROFILE_ID, STYLESHEET_ID);
089:                        IUserLayout layout = dlm.getUserLayout();
090:                        String rootId = layout.getRootId();
091:                        IUserLayoutNodeDescription root = layout
092:                                .getNodeDescription(rootId);
093:
094:                        // Set up the Document...
095:                        Document doc = DocumentFactory.getNewDocument();
096:                        Element layoutElement = doc.createElement("layout");
097:                        doc.appendChild(layoutElement);
098:                        layoutElement.setAttribute("user", uName);
099:                        Element rootFolderElement = doc
100:                                .createElement("root-folder");
101:                        layoutElement.appendChild(rootFolderElement);
102:
103:                        // Analyze the layout...
104:                        populateChildren(rootFolderElement,
105:                                (IUserLayoutFolderDescription) root, dlm, ssup);
106:
107:                        // Write to the indicated file...
108:                        // JAXP serializing
109:                        TransformerFactory xformFactory = TransformerFactory
110:                                .newInstance();
111:                        Transformer idTransform = xformFactory.newTransformer();
112:                        Source input = new DOMSource(doc);
113:                        Result output = new StreamResult(new FileOutputStream(
114:                                args[1]));
115:                        idTransform.setOutputProperty(OutputKeys.INDENT, "yes");
116:                        idTransform.setOutputProperty(
117:                                "{http://xml.apache.org/xslt}indent-amount",
118:                                "4");
119:                        idTransform.transform(input, output);
120:
121:                    } catch (Throwable t) {
122:                        log.error("The exporter tool terminated unexpectedly.",
123:                                t);
124:                        System.out
125:                                .println("The exporter tool terminated unexpectedly.");
126:                        t.printStackTrace(System.out);
127:                        System.exit(7);
128:                    }
129:
130:                    break;
131:
132:                default:
133:
134:                    log
135:                            .info("Usage:  java org.jasig.portal.layout.dlm.publisher <username> <file_path>");
136:                    log.info("");
137:                    log.info("where <username> is a valid portal user and ");
138:                    log
139:                            .info("<file_path> is the name of a file NOT in existance.");
140:                    break;
141:
142:                }
143:
144:                log.info("The publisher tool completed successfully.");
145:                System.exit(0);
146:
147:            }
148:
149:            private static void populateChildren(Element folderElement,
150:                    IUserLayoutFolderDescription folder,
151:                    IUserLayoutManager dlm,
152:                    StructureStylesheetUserPreferences ssup) throws Exception {
153:
154:                // Assertions.
155:                if (folderElement == null) {
156:                    String msg = "Argument 'folderElement' cannot be null.";
157:                    throw new IllegalArgumentException(msg);
158:                }
159:                if (folder == null) {
160:                    String msg = "Argument 'folder' cannot be null.";
161:                    throw new IllegalArgumentException(msg);
162:                }
163:                if (dlm == null) {
164:                    String msg = "Argument 'dlm' cannot be null.";
165:                    throw new IllegalArgumentException(msg);
166:                }
167:                if (ssup == null) {
168:                    String msg = "Argument 'ssup' cannot be null.";
169:                    throw new IllegalArgumentException(msg);
170:                }
171:
172:                // Child Nodes...
173:                for (Enumeration e = dlm.getChildIds(folder.getId()); e
174:                        .hasMoreElements();) {
175:
176:                    String chldId = (String) e.nextElement();
177:                    IUserLayoutNodeDescription chldNd = null;
178:                    try {
179:                        chldNd = dlm.getNode(chldId);
180:                    } catch (PortalException pe) {
181:                        // NB:  This really isn't a very satisfactory way to handle the
182:                        // issue here, which is that DLM embeds "dlm:editSet" elements
183:                        // in layouts to persist customization of layout fragments (I
184:                        // think).  Anyhow uPortal (even via DLM) can't give you a node
185:                        // description for one of these b/c it's neither a folder nor a
186:                        // channel.  For now, we'll drop the editSet data on layout export.
187:                        continue;
188:                    }
189:
190:                    Document doc = folderElement.getOwnerDocument();
191:                    switch (chldNd.getType()) {
192:
193:                    case IUserLayoutNodeDescription.FOLDER:
194:
195:                        Element childFolderElement = doc
196:                                .createElement("folder");
197:                        folderElement.appendChild(childFolderElement);
198:
199:                        // Type...
200:                        switch (((IUserLayoutFolderDescription) chldNd)
201:                                .getFolderType()) {
202:                        case UserLayoutFolderDescription.HEADER_TYPE:
203:                            childFolderElement.setAttribute("type", "header");
204:                            break;
205:                        case UserLayoutFolderDescription.FOOTER_TYPE:
206:                            childFolderElement.setAttribute("type", "footer");
207:                            break;
208:                        case UserLayoutFolderDescription.REGULAR_TYPE:
209:                            childFolderElement.setAttribute("type", "regular");
210:                            break;
211:                        }
212:
213:                        // Removable...
214:                        if (chldNd.isUnremovable()) {
215:                            childFolderElement.setAttribute("removable",
216:                                    "False");
217:                        } else {
218:                            childFolderElement
219:                                    .setAttribute("removable", "True");
220:                        }
221:
222:                        // Mutable...
223:                        if (chldNd.isEditAllowed()) {
224:                            childFolderElement.setAttribute("mutable", "True");
225:                        } else {
226:                            childFolderElement.setAttribute("mutable", "False");
227:                        }
228:
229:                        // Width... where applicable...
230:                        String width = ssup.getDefinedFolderAttributeValue(
231:                                chldNd.getId(), "width");
232:                        if (width != null && width.trim().length() != 0) {
233:                            childFolderElement.setAttribute("width", width);
234:                        }
235:
236:                        // Name...
237:                        Element nameElement = doc.createElement("name");
238:                        childFolderElement.appendChild(nameElement);
239:
240:                        nameElement.appendChild(doc.createTextNode(chldNd
241:                                .getName()));
242:
243:                        populateChildren(childFolderElement,
244:                                (IUserLayoutFolderDescription) chldNd, dlm,
245:                                ssup);
246:
247:                        break;
248:
249:                    case IUserLayoutNodeDescription.CHANNEL:
250:
251:                        Element channelElement = doc.createElement("channel");
252:                        folderElement.appendChild(channelElement);
253:                        channelElement.setAttribute("fName",
254:                                ((IUserLayoutChannelDescription) chldNd)
255:                                        .getFunctionalName());
256:
257:                        break;
258:
259:                    }
260:
261:                }
262:
263:            }
264:
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.