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


001:        /**
002:         * $Id: Rewriter.java,v 1.12 2006/10/05 07:26:49 vp154433 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.rewriter.admin.mbeans;
014:
015:        import com.iplanet.sso.SSOToken;
016:        import com.sun.identity.sm.ServiceConfig;
017:        import com.sun.identity.sm.ServiceConfigManager;
018:
019:        import java.util.*;
020:        import java.util.logging.Logger;
021:        import java.util.logging.Level;
022:        import com.sun.portal.log.common.PortalLogger;
023:
024:        import com.sun.portal.admin.server.mbeans.PSResource;
025:        import com.sun.portal.admin.server.AdminServerUtil;
026:        import com.sun.portal.admin.common.PSMBeanException;
027:
028:        import com.sun.portal.rewriter.rom.RuleSetManager;
029:        import com.sun.portal.rewriter.rom.InvalidXMLException;
030:        import com.sun.portal.rewriter.services.idsame.IDSAMEDataService;
031:        import com.sun.portal.rewriter.util.Constants;
032:        import org.xml.sax.SAXParseException;
033:        import org.xml.sax.SAXException;
034:
035:        /**
036:         *
037:         * @author  Francis Sujai
038:         */
039:        public class Rewriter extends PSResource implements  RewriterMBean {
040:
041:            private static final String SERVICE_NAME = "SunPortalRewriterService";
042:            private static final String SERVICE_SCHEMA_NAME = "SunPortalRewriterGlobal";
043:            private static final String ATTRIBUTE_NAME = "sunPortalRewriterRuleset";
044:            private static final String SUBCONFIG_ID = "SunPortalRewriterRuleSets";
045:
046:            // holds the config node SERVICE_SCHEMA_NAME
047:            private ServiceConfig config;
048:            private ServiceConfigManager configManager;
049:
050:            public RuleSetManager rulesetManager;
051:
052:            private static Logger _logger = PortalLogger
053:                    .getLogger(Rewriter.class);
054:
055:            public Rewriter() {
056:                config = null;
057:            }
058:
059:            public Rewriter(SSOToken aSSOToken) {
060:                try {
061:                    config = getConfig(aSSOToken);
062:                } catch (PSMBeanException e) {
063:                    //Internal Error
064:                }
065:            }
066:
067:            private ServiceConfig getConfig(SSOToken token)
068:                    throws PSMBeanException {
069:                try {
070:                    rulesetManager = new RuleSetManager(new IDSAMEDataService(
071:                            token));
072:                    configManager = new ServiceConfigManager(SERVICE_NAME,
073:                            token);
074:                    ServiceConfig globalConfig = configManager
075:                            .getGlobalConfig(null);
076:                    return globalConfig.getSubConfig(SERVICE_SCHEMA_NAME);
077:                } catch (Exception e) {
078:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
079:                    throw new PSMBeanException(
080:                            "psadmin.error.rewriter.unknownerror");
081:                }
082:            }
083:
084:            public Set listRules() throws PSMBeanException {
085:                config = getConfig(AdminServerUtil.getSSOToken());
086:                try {
087:                    Set rules = rulesetManager.getRuleSetNames();
088:                    final String[] listOfRules = (String[]) (rules
089:                            .toArray(Constants.EMPTY_STRING_ARRAY));
090:                    if (listOfRules.length == 0) {
091:                        throw new PSMBeanException(
092:                                "psadmin.error.rewriter.norulesetsfound");
093:                    }
094:                    return rules;
095:                    //return Collections.unmodifiableSet( config.getSubConfigNames() );
096:                } catch (Exception e) {
097:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
098:                    throw new PSMBeanException(
099:                            "psadmin.error.rewriter.unknownerror");
100:                }
101:            }
102:
103:            public String displayRule(String ruleSetID) throws PSMBeanException {
104:                config = getConfig(AdminServerUtil.getSSOToken());
105:                try {
106:                    final String xmlString = rulesetManager.retrieve(ruleSetID);
107:
108:                    Set rules = rulesetManager.getRuleSetNames();
109:                    if (!rules.contains(ruleSetID))
110:                        throw new PSMBeanException(
111:                                "psadmin.error.rewriter.doesntexists");
112:
113:                    if (xmlString == null) {
114:                        throw new PSMBeanException(
115:                                "psadmin.error.rewriter.rulesetxmlmissing");
116:                    }
117:
118:                    return xmlString;
119:
120:                    //            ServiceConfig subConfig = config.getSubConfig( ruleSetID );
121:                    //            if ( null == subConfig ) {
122:                    //                return null;
123:                    //            }
124:                    //
125:                    //            Map attributes = subConfig.getAttributes();
126:                    //            Set values = (Set) attributes.get( ATTRIBUTE_NAME );
127:                    //            Iterator itr = values.iterator();
128:                    //            return (String) itr.next();
129:                } catch (PSMBeanException e) {
130:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
131:                    throw new PSMBeanException(e.getErrorKey());
132:                }
133:
134:            }
135:
136:            public Boolean storeRule(String aXMLRuleSet)
137:                    throws PSMBeanException {
138:
139:                config = getConfig(AdminServerUtil.getSSOToken());
140:                //            HashSet set = new HashSet( 1 );
141:                //            Map map = new HashMap( 1 );
142:                //            set.add( aXMLRuleSet );
143:                //            map.put( ATTRIBUTE_NAME, set );
144:                //            config.addSubConfig( rule.toLowerCase(), SUBCONFIG_ID, 0, map);
145:                //            return Boolean.TRUE;
146:
147:                if (aXMLRuleSet.trim().length() == 0) {
148:                    throw new PSMBeanException(
149:                            "psadmin.error.rewriter.xmlcontentinvalid");
150:                } else {
151:                    try {
152:                        String matchID = rulesetManager
153:                                .matchesWithID(aXMLRuleSet);
154:                        if (matchID == null) {
155:                            rulesetManager.store(aXMLRuleSet);
156:                            return Boolean.TRUE;
157:                        } else {
158:                            _logger.log(Level.SEVERE,
159:                                    "PSRW_CSPR_ADM_MBEANS001", matchID);
160:                            throw new PSMBeanException(
161:                                    "psadmin.error.rewriter.alreadyexists");
162:                        }
163:                    } catch (InvalidXMLException e) {
164:                        _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
165:                        processException(e);
166:                        //throw new PSMBeanException("psadmin.error.rewriter.xmlcontentinvalid");
167:                    }
168:                }//if
169:                return Boolean.TRUE;
170:            }
171:
172:            public Boolean removeRule(String ruleSetID) throws PSMBeanException {
173:                config = getConfig(AdminServerUtil.getSSOToken());
174:                String result = null;
175:                //config.removeSubConfig( ruleSetID );
176:                Set rules = rulesetManager.getRuleSetNames();
177:                if (!rules.contains(ruleSetID))
178:                    throw new PSMBeanException(
179:                            "psadmin.error.rewriter.doesntexists");
180:
181:                result = rulesetManager.delete(ruleSetID);
182:                if (result != null) {
183:                    return Boolean.TRUE;
184:                }
185:                throw new PSMBeanException(
186:                        "psadmin.error.rewriter.rulesetxmlmissing");
187:            }
188:
189:            public Boolean setRule(String aXMLRuleSet) throws PSMBeanException {
190:
191:                config = getConfig(AdminServerUtil.getSSOToken());
192:                try {
193:                    String matchID = rulesetManager.matchesWithID(aXMLRuleSet);
194:                    if (matchID != null) {
195:                        rulesetManager.store(aXMLRuleSet);
196:                        return Boolean.TRUE;
197:                    } else {
198:                        throw new PSMBeanException(
199:                                "psadmin.error.rewriter.doesntexists");
200:                        /*config.removeSubConfig( matchID );
201:                        HashSet set = new HashSet( 1 );
202:                        Map map = new HashMap( 1 );
203:                        set.add( aXMLRuleSet );
204:                        map.put( ATTRIBUTE_NAME, set );
205:                        config.addSubConfig( matchID.toLowerCase(), SUBCONFIG_ID, 0, map );
206:                        return Boolean.TRUE;*/
207:                    }
208:                } catch (PSMBeanException e) {
209:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
210:                    throw new PSMBeanException(e.getErrorKey());
211:                } catch (InvalidXMLException e) {
212:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
213:                    //throw new PSMBeanException("psadmin.error.rewriter.xmlcontentinvalid");
214:                    processException(e);
215:                } catch (Exception e) {
216:                    _logger.log(Level.INFO, "PSRW_CSPR_ADM_MBEANS000", e);
217:                    throw new PSMBeanException(
218:                            "psadmin.error.rewriter.unknownerror");
219:                }
220:                return Boolean.TRUE;
221:            }
222:
223:            protected void processException(InvalidXMLException ixe)
224:                    throws PSMBeanException {
225:                int code = ixe.getLocaleID();
226:                Throwable t = ixe.getCause();
227:                switch (code) {
228:                case InvalidXMLException.SAX_EXCEPTION:
229:                    if ((t != null) && (t instanceof  SAXParseException)) {
230:                        SAXParseException spe = (org.xml.sax.SAXParseException) t;
231:                        Object[] params = {
232:                                new Integer(spe.getLineNumber()).toString(),
233:                                new Integer(spe.getColumnNumber()).toString(),
234:                                spe.getMessage(),
235:
236:                        };
237:                        throw new PSMBeanException(
238:                                "psadmin.error.rewriter.saxparseerr.msg",
239:                                params);
240:                    } else if ((t != null) && (t instanceof  SAXException)) {
241:                        SAXException se = (org.xml.sax.SAXException) t;
242:                        Object[] params = { se.getMessage() };
243:                        throw new PSMBeanException(
244:                                "psadmin.error.rewriter.saxerr.msg", params);
245:                    } else {
246:                        throw new PSMBeanException(
247:                                "psadmin.error.rewriter.generr.msg");
248:                    }
249:                case InvalidXMLException.KEY_DOES_NOT_EXIST:
250:                    throw new PSMBeanException(
251:                            "psadmin.error.rewriter.keyerr.msg");
252:                case InvalidXMLException.REPEATED_TAG:
253:                    throw new PSMBeanException(
254:                            "psadmin.error.rewriter.reptagerr.msg");
255:                case InvalidXMLException.INVALID_ID:
256:                    Object[] params = { ixe.getErrorInfo() };
257:                    throw new PSMBeanException(
258:                            "psadmin.error.rewriter.invalididerr.msg", params);
259:                default:
260:                    throw new PSMBeanException(
261:                            "psadmin.error.rewriter.generr.msg");
262:                }
263:            }
264:
265:            //    public static void main( String[] args ) {
266:            //        Rewriter rwadmin = new Rewriter(AdminServerUtil.getSSOToken());
267:            //        System.out.println("Rule 0 is"+ rwadmin.getRule("","","wml_ruleset"));
268:            //        System.out.println("Rule 1 is"+ rwadmin.getRule("","","default_ruleset"));
269:            //    }
270:
271:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.