Source Code Cross Referenced for PDDPUpdater.java in  » Portal » Open-Portal » com » sun » portal » portlet » cli » 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 » Open Portal » com.sun.portal.portlet.cli 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2002 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:
006:        package com.sun.portal.portlet.cli;
007:
008:        import java.util.List;
009:        import java.util.ArrayList;
010:
011:        import java.io.InputStream;
012:        import java.io.StringReader;
013:        import java.io.Reader;
014:        import java.io.BufferedReader;
015:        import java.io.IOException;
016:
017:        import com.sun.portal.desktop.context.DSAMEAdminDPContext;
018:        import com.sun.portal.desktop.dp.DPRoot;
019:        import com.sun.portal.desktop.dp.DPProvider;
020:
021:        import com.sun.portal.desktop.DesktopError;
022:
023:        import com.sun.portal.desktop.dp.xml.XMLDPTags;
024:        import com.sun.portal.desktop.dp.xml.XMLDPFactory;
025:        import com.sun.portal.desktop.dp.xml.XMLDPRoot;
026:
027:        import javax.xml.parsers.DocumentBuilderFactory;
028:        import javax.xml.parsers.DocumentBuilder;
029:        import org.w3c.dom.Element;
030:        import org.w3c.dom.Document;
031:        import org.w3c.dom.DOMException;
032:        import org.xml.sax.SAXParseException;
033:
034:        /**
035:         * PDDPUpdater is responsible for adding the provider
036:         * entries created by PDProviderEntryGenerator class to
037:         * the DP document and storing the updated DP document.
038:         */
039:        public class PDDPUpdater {
040:
041:            private DSAMEAdminDPContext dadc = null;
042:            private String dn = null;
043:            private boolean verbose = false;
044:            private boolean global = false;
045:
046:            public static final int CONTEXT_LINE_NUM = 5;
047:
048:            // XML DP Factory
049:            XMLDPFactory dpf = XMLDPFactory.getInstance();
050:
051:            public PDDPUpdater(DSAMEAdminDPContext dadc, String dn,
052:                    boolean global, boolean verbose) {
053:                this .dadc = dadc;
054:                this .dn = dn;
055:                this .global = global;
056:                this .verbose = verbose;
057:            }
058:
059:            public void addProviders(List providerElements)
060:                    throws PortletDeployerException {
061:
062:                // build dproot
063:                DPRoot dpr = getDPRoot();
064:                dpr.setDummy(false);
065:                // add dp obj.
066:                for (int i = 0; i < providerElements.size(); i++) {
067:                    Element element = (Element) providerElements.get(i);
068:                    dpr = addProvider(dpr, element);
069:                }
070:
071:                if (verbose) {
072:                    PortletDeployerLocalizer.debug("dbgValidatingDP");
073:                }
074:
075:                // check for invalid XML
076:                String dpDoc = null;
077:                try {
078:                    //
079:                    // set dirty to false before writing out.
080:                    // not doing this will cause "dirty=true" attribute to
081:                    // be added which will then cause validation error.
082:                    //
083:                    dpr = setDirty(dpr);
084:                    dpDoc = dpr.toString();
085:                    dpf.createRoot(dadc, dpDoc);
086:                } catch (DesktopError de) {
087:                    Throwable wrapped = de.getCause();
088:                    if (wrapped != null && wrapped instanceof  SAXParseException) {
089:                        SAXParseException spe = (SAXParseException) wrapped;
090:                        int linenum = spe.getLineNumber();
091:                        Object[] tokens = { getLines(new StringReader(dpDoc),
092:                                linenum) };
093:                        throw new PortletDeployerException(
094:                                "errorInvalidXMLText", de, tokens);
095:                    }
096:                } catch (Throwable ex) {
097:                    throw new PortletDeployerException("errorInvalidXML", ex);
098:                }
099:
100:                storeDPDocument(dpr);
101:
102:            }
103:
104:            public DPRoot addProvider(DPRoot dpr, Element element)
105:                    throws PortletDeployerException {
106:                if (verbose) {
107:                    Object[] tokens = { element.getAttribute("name") };
108:                    PortletDeployerLocalizer.debug("dbgAddingProvider", tokens);
109:                    PortletDeployerLocalizer.debug("dbgCreatingDPProvider");
110:                }
111:                DPProvider p = null;
112:                try {
113:                    p = dpf.getProvider(dadc, dpr, element);
114:                } catch (Throwable ex) {
115:                    throw new PortletDeployerException("errorCreateDPProvider",
116:                            ex);
117:                }
118:
119:                if (verbose) {
120:                    Object[] tokens = { p.getName() };
121:                    PortletDeployerLocalizer.debug("dbgCheckDupName", tokens);
122:                }
123:                boolean dupFound = false;
124:                try {
125:                    //
126:                    // only need to check for dupe channel
127:                    // name at the root level
128:                    //
129:                    XMLDPRoot xdpr = (XMLDPRoot) dpr;
130:                    dupFound = (xdpr.getChannelFromThis(p.getName()) != null);
131:                    if (!dupFound) {
132:                        dupFound = (xdpr.getProviderFromThis(p.getName()) != null);
133:                    }
134:                } catch (Throwable ex) {
135:                    throw new PortletDeployerException("errorCheckDupName", ex);
136:                }
137:                if (dupFound) {
138:                    //Changing this part of code to log a warning message 
139:                    //for multi-instance deployment.
140:                    //throw new PortletDeployerException("errorDupName");
141:                    Object[] tokens = { p.getName() };
142:                    PortletDeployerLocalizer.warning("WarningDupName", tokens);
143:                }
144:
145:                try {
146:                    dpr.addProvider(p);
147:                } catch (Throwable ex) {
148:                    Object[] tokens = { p.getName() };
149:                    throw new PortletDeployerException("errorAddProvider", ex,
150:                            tokens);
151:                }
152:
153:                return dpr;
154:            }
155:
156:            public void removeProviders(List providers)
157:                    throws PortletDeployerException {
158:                DPRoot dpr = getDPRoot();
159:
160:                // remove providers.
161:                for (int i = 0; i < providers.size(); i++) {
162:                    String name = (String) providers.get(i);
163:                    dpr = removeProvider(dpr, name);
164:                }
165:                dpr = setDirty(dpr);
166:                storeDPDocument(dpr);
167:            }
168:
169:            public DPRoot removeProvider(DPRoot dpr, String name)
170:                    throws PortletDeployerException {
171:                if (verbose) {
172:                    Object[] tokens = { name };
173:                    PortletDeployerLocalizer.debug("dbgRemovingProvider",
174:                            tokens);
175:                }
176:
177:                if (verbose) {
178:                    PortletDeployerLocalizer.debug("dbgCheckExistingProvider");
179:                }
180:                boolean exists = false;
181:                try {
182:                    XMLDPRoot xdpr = (XMLDPRoot) dpr;
183:                    exists = (xdpr.getProviderFromThis(name) != null);
184:                } catch (Throwable ex) {
185:                    Object[] tokens = { name };
186:                    throw new PortletDeployerException("errorLookupProvider",
187:                            ex, tokens);
188:                }
189:                if (!exists) {
190:                    Object[] tokens = { name };
191:                    //Changing this part of code to log a warning message 
192:                    //for multi-instance deployment.
193:                    //throw new PortletDeployerException("errorFindProvider", tokens);
194:                    PortletDeployerLocalizer.warning("WarningFindProvider",
195:                            tokens);
196:                }
197:
198:                try {
199:                    dpr.removeProvider(name);
200:                } catch (Throwable ex) {
201:                    Object[] tokens = { name };
202:                    throw new PortletDeployerException("errorRemoveProvider",
203:                            ex, tokens);
204:                }
205:
206:                return dpr;
207:
208:            }
209:
210:            private DPRoot getDPRoot() throws PortletDeployerException {
211:                // get document
212:                String doc = null;
213:                try {
214:                    if (!global) {
215:                        doc = dadc.getDPDocumentByDN(dn);
216:                    } else {
217:                        doc = dadc.getGlobalDPDocument();
218:                    }
219:                } catch (Throwable ex) {
220:                    Object[] tokens = { global ? PortletDeployerLocalizer
221:                            .getLocalizedString("msgGlobal") : dn };
222:                    throw new PortletDeployerException("errorRetrieveDP", ex,
223:                            tokens);
224:                }
225:
226:                // build dproot
227:                DPRoot dpr = null;
228:                try {
229:                    if (doc == null) {
230:                        dpr = dpf.createRoot(dadc);
231:                    } else {
232:                        dpr = dpf.createRoot(dadc, doc);
233:                    }
234:                } catch (Throwable ex) {
235:                    Object[] tokens = { dn };
236:                    throw new PortletDeployerException("errorCreateDPRoot", ex,
237:                            tokens);
238:                }
239:                return dpr;
240:
241:            }
242:
243:            private void storeDPDocument(DPRoot dpr)
244:                    throws PortletDeployerException {
245:                if (verbose) {
246:                    PortletDeployerLocalizer.debug("dbgWritingDP");
247:                }
248:                try {
249:                    if (!global) {
250:                        dadc.storeDPDocumentByDN(dn, dpr.toString());
251:                    } else {
252:                        dadc.storeGlobalDPDocument(dpr.toString());
253:                    }
254:                } catch (Throwable ex) {
255:                    throw new PortletDeployerException("errorStoreDP", ex);
256:                }
257:            }
258:
259:            private DPRoot setDirty(DPRoot dpr) throws PortletDeployerException {
260:                try {
261:                    if (dpr.isDirty()) {
262:                        dpr.setDirty(false);
263:                    }
264:                } catch (Throwable ex) {
265:                    throw new PortletDeployerException("errorSetDirty", ex);
266:                }
267:                return dpr;
268:            }
269:
270:            public static String getLines(Reader reader, int linenum) {
271:                StringBuffer buf = new StringBuffer();
272:                String line = null;
273:                BufferedReader br = new BufferedReader(reader);
274:
275:                try {
276:                    int i = 1;
277:                    int beg = linenum - CONTEXT_LINE_NUM;
278:                    int end = linenum + CONTEXT_LINE_NUM;
279:                    buf.append("\n");
280:                    while ((line = br.readLine()) != null) {
281:                        if (i == linenum) {
282:                            buf.append("(*)").append(line).append("\n");
283:                        } else if (i >= beg && i <= end) {
284:                            buf.append("   ").append(line).append("\n");
285:                        }
286:                        ++i;
287:                    }
288:                    buf.append("\n");
289:                } catch (IOException ioe) {
290:                    return "";
291:                }
292:                return buf.toString();
293:            }
294:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.