Source Code Cross Referenced for Actions.java in  » Content-Management-System » contelligent » de » finix » contelligent » client » remote » 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 » Content Management System » contelligent » de.finix.contelligent.client.remote 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright 2001-2006 C:1 Financial Services GmbH
0003:         *
0004:         * This software is free software; you can redistribute it and/or
0005:         * modify it under the terms of the GNU Lesser General Public
0006:         * License Version 2.1, as published by the Free Software Foundation.
0007:         *
0008:         * This software is distributed in the hope that it will be useful,
0009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0011:         * Lesser General Public License for more details.
0012:         *
0013:         * You should have received a copy of the GNU Lesser General Public
0014:         * License along with this library; if not, write to the Free Software
0015:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
0016:         */
0017:
0018:        package de.finix.contelligent.client.remote;
0019:
0020:        import java.io.File;
0021:        import java.io.IOException;
0022:        import java.io.StringWriter;
0023:        import java.net.URL;
0024:        import java.util.Collection;
0025:        import java.util.HashMap;
0026:        import java.util.Iterator;
0027:        import java.util.List;
0028:        import java.util.Map;
0029:        import java.util.Set;
0030:        import java.util.Vector;
0031:        import java.util.logging.Level;
0032:        import java.util.logging.Logger;
0033:
0034:        import de.finix.contelligent.client.base.ComponentProperty;
0035:        import de.finix.contelligent.client.base.ContelligentComponent;
0036:        import de.finix.contelligent.client.base.ContelligentConstants;
0037:        import de.finix.contelligent.client.base.ServerInfo;
0038:        import de.finix.contelligent.client.base.Session;
0039:        import de.finix.contelligent.client.base.category.ContelligentCategory;
0040:        import de.finix.contelligent.client.base.resource.ContelligentBinaryResource;
0041:        import de.finix.contelligent.client.base.resource.ContelligentBooleanResource;
0042:        import de.finix.contelligent.client.base.resource.ContelligentNumberResource;
0043:        import de.finix.contelligent.client.base.resource.ContelligentResource;
0044:        import de.finix.contelligent.client.base.resource.ContelligentResourceReference;
0045:        import de.finix.contelligent.client.base.resource.ContelligentStringResource;
0046:        import de.finix.contelligent.client.base.resource.ContelligentTextResource;
0047:        import de.finix.contelligent.client.security.ComponentAccess;
0048:        import de.finix.contelligent.client.security.Principal;
0049:        import de.finix.contelligent.client.security.User;
0050:        import de.zeigermann.xml.XMLWriter;
0051:        import de.zeigermann.xml.simpleImporter.SimpleImportHandler;
0052:
0053:        /**
0054:         * Central class for calling server action.
0055:         */
0056:        public class Actions extends ServerConnector {
0057:
0058:            private static Logger logger = Logger.getLogger(Actions.class
0059:                    .getName());
0060:
0061:            private final static RemoteAction SERVER_INFO = new RemoteAction(
0062:                    "/ServerInfo/");
0063:
0064:            private final static RemoteAction GET_CONFIGURATION = new RemoteAction(
0065:                    "/contelligent/core/action/view.act");
0066:
0067:            private final static RemoteAction GET_TYPES = new RemoteAction(
0068:                    "/contelligent/core/action/exportTypes.act");
0069:
0070:            private final static RemoteAction GET_BLUEPRINTS = new RemoteAction(
0071:                    "/contelligent/core/action/exportBlueprint.act");
0072:
0073:            private final static RemoteAction LOGIN = new RemoteAction(
0074:                    "/contelligent/core/action/login.act");
0075:
0076:            private final static RemoteAction LOGOUT = new RemoteAction(
0077:                    "/contelligent/core/action/logout.act");
0078:
0079:            private final static RemoteAction EXPORT = new RemoteAction(
0080:                    "/contelligent/core/action/export.act");
0081:
0082:            private final static RemoteAction DELETE = new RemoteAction(
0083:                    "/contelligent/core/action/delete.act");
0084:
0085:            private final static RemoteAction CREATE = new RemoteAction(
0086:                    "/contelligent/core/action/addComponent.act");
0087:
0088:            private final static RemoteAction LOAD = new RemoteAction(
0089:                    "/contelligent/core/action/detailedComponentView.act");
0090:
0091:            private final static RemoteAction COPY = new RemoteAction(
0092:                    "/contelligent/core/action/copy.act");
0093:
0094:            private final static RemoteAction MOVE = new RemoteAction(
0095:                    "/contelligent/core/action/move.act");
0096:
0097:            private final static RemoteAction SORT = new RemoteAction(
0098:                    "/contelligent/core/action/moveSortedContent.act");
0099:
0100:            private final static RemoteAction CREATE_FROM_TYPE = new RemoteAction(
0101:                    "/contelligent/core/action/createComponent.act");
0102:
0103:            private final static RemoteAction CREATE_TYPE = new RemoteAction(
0104:                    "/contelligent/core/action/registerType.act");
0105:
0106:            private final static RemoteAction DELETE_TYPE = new RemoteAction(
0107:                    "/contelligent/core/action/deleteType.act");
0108:
0109:            private final static RemoteAction UPDATE_TYPE = new RemoteAction(
0110:                    "/contelligent/core/action/updateType.act");
0111:
0112:            private final static RemoteAction RENAME_TYPE = new RemoteAction(
0113:                    "/contelligent/core/action/renameType.act");
0114:
0115:            private final static RemoteAction TYPE_USAGES = new RemoteAction(
0116:                    "/contelligent/core/action/typeUsages.act");
0117:
0118:            private final static RemoteAction USAGES = new RemoteAction(
0119:                    "/contelligent/core/action/relationsAction.act");
0120:
0121:            private final static RemoteAction MODIFIED_COMPONENTS = new RemoteAction(
0122:                    "/contelligent/core/action/modifiedComponents.act");
0123:
0124:            private final static RemoteAction UPLOAD = new RemoteAction(
0125:                    "/contelligent/core/action/fileUpload.act");
0126:
0127:            private final static RemoteAction JSP_UPLOAD = new RemoteAction(
0128:                    "/contelligent/core/action/jspUpload.act");
0129:
0130:            private final static RemoteAction SET_ACL = new RemoteAction(
0131:                    "/contelligent/core/action/setACL.act");
0132:
0133:            private final static RemoteAction SET_PROPERTIES = new RemoteAction(
0134:                    "/contelligent/core/action/setProperties.act");
0135:
0136:            private final static RemoteAction LOCK = new RemoteAction(
0137:                    "/contelligent/core/action/lockComponent.act");
0138:
0139:            private final static RemoteAction LIST_SUBCOMPONENTS = new RemoteAction(
0140:                    "/contelligent/core/action/listSubcomponents.act");
0141:
0142:            private final static RemoteAction PULL_COMPONENT_SYSTEM_EVENTS = new RemoteAction(
0143:                    "/contelligent/core/action/pullComponentSystemEvents.act");
0144:
0145:            private final static RemoteAction SEND_MESSAGE = new RemoteAction(
0146:                    "/contelligent/core/action/message.act");
0147:
0148:            private final static RemoteAction CONTEXT = new RemoteAction(
0149:                    "/contelligent/core/action/cmAction.act");
0150:
0151:            private final static RemoteAction UPDATE_COMPONENT = new RemoteAction(
0152:                    "/contelligent/core/action/updateComponent.act");
0153:
0154:            private final static RemoteAction PRINCIPAL = new RemoteAction(
0155:                    "/contelligent/core/action/principalAction.act");
0156:
0157:            private final static RemoteAction FIND = new RemoteAction(
0158:                    "/contelligent/core/action/SystemIndexSearchAction.act");
0159:
0160:            private final static RemoteAction NAME_FIND = new RemoteAction(
0161:                    "/contelligent/core/action/NameSearchAction.act");
0162:
0163:            private final static RemoteAction LOAD_CONFIGURATION = new RemoteAction(
0164:                    "/contelligent/core/action/exportConfiguration.act");
0165:
0166:            private final static RemoteAction CHANGE_TYPE = new RemoteAction(
0167:                    "/contelligent/core/action/changeBlueprintType.act");
0168:
0169:            private final static RemoteAction REFACTOR_BLUEPRINT = new RemoteAction(
0170:                    "/contelligent/core/action/refactorBlueprint.act");
0171:
0172:            private final static RemoteAction WORKFLOW = new RemoteAction(
0173:                    "/contelligent/core/action/workflow.act");
0174:
0175:            private final static RemoteAction TOGGLE_FINAL = new RemoteAction(
0176:                    "/contelligent/core/action/componentMetainfo.act");
0177:
0178:            private final static RemoteAction PUBLISHER = new RemoteAction(
0179:                    "/contelligent/core/action/publisherAction.act");
0180:
0181:            private final static RemoteAction SUBTREE_SIZE = new RemoteAction(
0182:                    "/contelligent/core/action/subtreeSizeAction.act");
0183:
0184:            private final static RemoteAction JMX = new RemoteAction(
0185:                    "/contelligent/core/action/jmxAction.act");
0186:
0187:            private final static RemoteAction CREATE_USER_CONTENT = new RemoteAction(
0188:                    "/contelligent/core/action/createUserContentAction.act");
0189:
0190:            public final static int UP = 0;
0191:
0192:            public final static int DOWN = 1;
0193:
0194:            public final static int TOP = 2;
0195:
0196:            public final static int BOTTOM = 3;
0197:
0198:            private final static String[] directions = { "up", "down", "top",
0199:                    "bottom" };
0200:
0201:            public final static boolean performLogout() {
0202:                String sessionHandle = Session.getInstance().getSessionHandle();
0203:                if (sessionHandle != null) {
0204:                    URL server = ServerInfo.getInstance().getServer();
0205:                    RemoteAction action = Actions.LOGOUT;
0206:                    try {
0207:
0208:                        ActionResult actionResult = performAction(action,
0209:                                server);
0210:                        return actionResult.getState().equals(ActionResult.OK);
0211:                    } catch (Throwable e) {
0212:                        logger.log(Level.WARNING, "Error while logging out", e);
0213:                        return false;
0214:                    }
0215:                }
0216:                return true;
0217:            }
0218:
0219:            public final static synchronized ActionResult login(User user,
0220:                    int clientCallBackPort, boolean clientCallBackKeepAlive,
0221:                    int sessionTimeout) throws RemoteActionException {
0222:                String[][] parameter = {
0223:                        { "userId", user.getLogin() },
0224:                        { "groupId", user.getGroup() },
0225:                        { "password", user.getPassword() },
0226:                        { "clientSession", "true" },
0227:                        { "clientCallBackPort",
0228:                                Integer.toString(clientCallBackPort) },
0229:                        { "clientCallBackKeepAlive",
0230:                                Boolean.toString(clientCallBackKeepAlive) },
0231:                        { "sessionTimeout", String.valueOf(sessionTimeout) } };
0232:
0233:                return performAction(Actions.LOGIN, parameter);
0234:            }
0235:
0236:            /**
0237:             * This is the direct low level blocking copy action call to the server.<br>
0238:             * No events are generated.
0239:             */
0240:            public final static synchronized ActionResult copy(
0241:                    String environment, String sourceEnvironment,
0242:                    ContelligentComponent sourceComponent,
0243:                    ContelligentComponent targetComponent, String name,
0244:                    boolean createLink, boolean overwrite)
0245:                    throws RemoteActionException {
0246:                return copy(environment, sourceEnvironment, sourceComponent
0247:                        .getPath(), targetComponent.getDir()
0248:                        + targetComponent.getName(), name, createLink,
0249:                        overwrite, false, false);
0250:            }
0251:
0252:            public final static synchronized ActionResult copy(
0253:                    String environment, String sourceEnvironment,
0254:                    ContelligentComponent sourceComponent,
0255:                    ContelligentComponent targetComponent, String name,
0256:                    boolean createLink, boolean overwrite,
0257:                    boolean overrideFinals, boolean cloningCopy)
0258:                    throws RemoteActionException {
0259:                return copy(environment, sourceEnvironment, sourceComponent
0260:                        .getPath(), targetComponent.getDir()
0261:                        + targetComponent.getName(), name, createLink,
0262:                        overwrite, overrideFinals, cloningCopy);
0263:            }
0264:
0265:            /**
0266:             * This is the direct low level blocking copy action call to the server.<br>
0267:             * No events are generated.
0268:             */
0269:            public final static synchronized ActionResult copy(
0270:                    String environment, String sourceEnvironment,
0271:                    String sourcePath, String targetPath, String name,
0272:                    boolean createLink, boolean overwrite,
0273:                    boolean overrideFinals, boolean cloningCopy)
0274:                    throws RemoteActionException {
0275:                logger.log(Level.FINE, "Trying to copy '" + sourcePath
0276:                        + "' to '" + targetPath + "' with name '" + name + "'");
0277:                String[][] parameter = { { "FROM", sourcePath },
0278:                        { "TODIR", targetPath }, { "TONAME", name },
0279:                        { "OVERWRITE", Boolean.toString(overwrite) },
0280:                        { "CREATELINK", Boolean.toString(createLink) },
0281:                        { "OVERRIDEFINALS", Boolean.toString(overrideFinals) },
0282:                        { "CLONINGCOPY", Boolean.toString(cloningCopy) },
0283:                        { "environment", environment },
0284:                        { "sourceEnvironment", sourceEnvironment } };
0285:                ActionResult response = Actions.performAction(Actions.COPY,
0286:                        parameter);
0287:                return response;
0288:            }
0289:
0290:            /**
0291:             * This is the direct low level blocking move action call to the server.<br>
0292:             * No events are generated. passing null as targetComponent will be interpreted as a rename.
0293:             */
0294:            public final synchronized static ActionResult move(
0295:                    String environment, String sourceEnvironment,
0296:                    ContelligentComponent sourceComponent,
0297:                    ContelligentComponent targetComponent, String name,
0298:                    boolean overwrite, boolean forceMove)
0299:                    throws RemoteActionException {
0300:                if (targetComponent != null) {
0301:                    logger.log(Level.FINE, "Trying to move '"
0302:                            + sourceComponent.getPath() + "' to '"
0303:                            + targetComponent.getPath() + "' with name '"
0304:                            + name + "'");
0305:                } else {
0306:                    logger
0307:                            .log(Level.FINE, "Trying to rename '"
0308:                                    + sourceComponent.getPath() + "' to '"
0309:                                    + name + "'");
0310:                }
0311:                String[][] parameter = {
0312:                        { "sourcePath", sourceComponent.getPath() },
0313:                        {
0314:                                "targetDir",
0315:                                targetComponent != null ? targetComponent
0316:                                        .getDir()
0317:                                        + targetComponent.getName() : "" },
0318:                        { "targetName", name },
0319:                        { "overwrite", Boolean.toString(overwrite) },
0320:                        { "forceMove", Boolean.toString(forceMove) },
0321:                        { "environment", environment },
0322:                        { "sourceEnvironment", sourceEnvironment } };
0323:                return performAction(Actions.MOVE, parameter);
0324:            }
0325:
0326:            /**
0327:             * This is the direct low level blocking delete action call to the server.<br>
0328:             * No events are generated.
0329:             */
0330:            public final static synchronized ActionResult delete(
0331:                    String environment, ContelligentComponent component,
0332:                    boolean forceDeletion) throws RemoteActionException {
0333:                return delete(environment, component.getPath(), forceDeletion);
0334:            }
0335:
0336:            public final static synchronized ActionResult delete(
0337:                    String environment, String componentPath)
0338:                    throws RemoteActionException {
0339:                return delete(environment, componentPath, false);
0340:            }
0341:
0342:            public final static synchronized ActionResult delete(
0343:                    String environment, String componentPath,
0344:                    boolean forceDeletion) throws RemoteActionException {
0345:                logger.log(Level.FINE, "Trying to delete '" + componentPath
0346:                        + "'");
0347:                String[][] parameter = { { "deletePath", componentPath },
0348:                        { "forceDeletion", Boolean.toString(forceDeletion) },
0349:                        { "environment", environment } };
0350:                ActionResult response = Actions.performAction(Actions.DELETE,
0351:                        parameter);
0352:                return response;
0353:            }
0354:
0355:            public final static synchronized ActionResult createFromType(
0356:                    String environment, String type, String name, String dir,
0357:                    boolean forceOverwrite) throws RemoteActionException {
0358:                String[][] parameter = { { "TYPE", type }, { "NAME", name },
0359:                        { "DIR", dir },
0360:                        { "OVERWRITE", String.valueOf(forceOverwrite) },
0361:                        { "environment", environment } };
0362:                ActionResult response = Actions.performAction(
0363:                        Actions.CREATE_FROM_TYPE, parameter);
0364:                return response;
0365:            }
0366:
0367:            public final static synchronized ActionResult createType(
0368:                    String environment, String packageName, String typeName,
0369:                    String xml) throws RemoteActionException {
0370:                String[][] parameter = { { "PACKAGE", packageName },
0371:                        { "NAME", typeName }, { "XML", xml },
0372:                        { "environment", environment } };
0373:                ActionResult result = Actions.performAction(
0374:                        Actions.CREATE_TYPE, parameter);
0375:                return result;
0376:            }
0377:
0378:            public final static synchronized ActionResult updateType(
0379:                    String environment, String packageName, String typeName,
0380:                    String xml) throws RemoteActionException {
0381:                String[][] parameter = { { "PACKAGE", packageName },
0382:                        { "NAME", typeName }, { "XML", xml },
0383:                        { "environment", environment } };
0384:                ActionResult result = Actions.performAction(
0385:                        Actions.UPDATE_TYPE, parameter);
0386:                return result;
0387:            }
0388:
0389:            public final static synchronized ActionResult deleteType(
0390:                    String environment, String typeName, boolean force,
0391:                    boolean deleteComponent) throws RemoteActionException {
0392:                String[][] parameter = { { "NAME", typeName },
0393:                        { "FORCE", String.valueOf(force) },
0394:                        { "DELETECOMPONENT", String.valueOf(deleteComponent) },
0395:                        { "environment", environment } };
0396:                ActionResult result = Actions.performAction(
0397:                        Actions.DELETE_TYPE, parameter);
0398:                return result;
0399:            }
0400:
0401:            public final static synchronized ActionResult typeUsages(
0402:                    String typeName, boolean showComponent)
0403:                    throws RemoteActionException {
0404:                String[][] parameter = { { "NAME", typeName },
0405:                        { "SHOWCOMPONENT", String.valueOf(showComponent) } };
0406:                ActionResult result = Actions.performAction(
0407:                        Actions.TYPE_USAGES, parameter);
0408:                return result;
0409:            }
0410:
0411:            public final static synchronized ActionResult usages(
0412:                    String targetPath, boolean tree, boolean includeself)
0413:                    throws RemoteActionException {
0414:                String[][] parameter = { { "targetpath", targetPath },
0415:                        { "tree", String.valueOf(tree) },
0416:                        { "includeself", String.valueOf(includeself) } };
0417:                ActionResult result = Actions.performAction(Actions.USAGES,
0418:                        parameter);
0419:                return result;
0420:            }
0421:
0422:            public final static synchronized ActionResult find(
0423:                    String environment, String searchTerm, String path,
0424:                    String context) throws RemoteActionException {
0425:                String[][] parameter = { { "QUERY", searchTerm },
0426:                        { "PATH", path }, { "CM", context },
0427:                        { "environment", environment } };
0428:                ActionResult result = Actions.performAction(Actions.FIND,
0429:                        parameter);
0430:                return result;
0431:            }
0432:
0433:            public final static synchronized ActionResult nameFind(
0434:                    String searchName, String rootPath)
0435:                    throws RemoteActionException {
0436:                String[][] parameter = { { "NAME", searchName },
0437:                        { "ROOT", rootPath } };
0438:                ActionResult result = Actions.performAction(Actions.NAME_FIND,
0439:                        parameter);
0440:                return result;
0441:            }
0442:
0443:            public final static synchronized ActionResult modifiedComponents(
0444:                    String context, boolean deletedComponents)
0445:                    throws RemoteActionException {
0446:                String[][] parameter = { { "CM", context },
0447:                        { "DELETED", String.valueOf(deletedComponents) } };
0448:                ActionResult result = Actions.performAction(
0449:                        Actions.MODIFIED_COMPONENTS, parameter);
0450:                return result;
0451:            }
0452:
0453:            public final static synchronized ActionResult renameType(
0454:                    String environment, String typeName, String newTypeName)
0455:                    throws RemoteActionException {
0456:                String[][] parameter = { { "NAME", typeName },
0457:                        { "NEWNAME", newTypeName },
0458:                        { "environment", environment } };
0459:                ActionResult result = Actions.performAction(
0460:                        Actions.RENAME_TYPE, parameter);
0461:                return result;
0462:            }
0463:
0464:            private final static ActionResult principals(String groupId,
0465:                    String cmd, String xml, String oldPassword,
0466:                    String newPassword) throws RemoteActionException {
0467:                String[][] parameter = { { "GROUP", groupId }, { "CMD", cmd },
0468:                        { "XML", xml }, { "PASSWD", oldPassword },
0469:                        { "NEWPASSWD", newPassword } };
0470:                ActionResult result = Actions.performAction(Actions.PRINCIPAL,
0471:                        parameter);
0472:                return result;
0473:            }
0474:
0475:            public final static synchronized ActionResult exportPrincipals(
0476:                    String groupId) throws RemoteActionException {
0477:                return principals(groupId, "export", "", "", "");
0478:            }
0479:
0480:            public final static synchronized ActionResult updateOrAddPrincipal(
0481:                    String groupId, String xml) throws RemoteActionException {
0482:                return principals(groupId, "update", xml, "", "");
0483:            }
0484:
0485:            public final static synchronized ActionResult removePrincipal(
0486:                    String groupId, String xml) throws RemoteActionException {
0487:                return principals(groupId, "remove", xml, "", "");
0488:            }
0489:
0490:            public final static synchronized ActionResult changePassword(
0491:                    String oldPassword, String newPassword)
0492:                    throws RemoteActionException {
0493:                return principals("", "setPassword", "", oldPassword,
0494:                        newPassword);
0495:            }
0496:
0497:            public final static synchronized ActionResult exportAdministrablePrincipalGroups()
0498:                    throws RemoteActionException {
0499:                String[][] parameter = { { "CMD", "listAdminGroups" } };
0500:                ActionResult result = Actions.performAction(Actions.PRINCIPAL,
0501:                        parameter);
0502:                return result;
0503:            }
0504:
0505:            public final static synchronized ActionResult getPrivileges()
0506:                    throws RemoteActionException {
0507:                String[][] parameter = { { "CMD", "getPrivileges" } };
0508:                ActionResult result = Actions.performAction(Actions.PRINCIPAL,
0509:                        parameter);
0510:                return result;
0511:            }
0512:
0513:            public final static synchronized ActionResult setPrivileges(
0514:                    String xml) throws RemoteActionException {
0515:                String[][] parameter = { { "CMD", "setPrivileges" },
0516:                        { "XML", xml } };
0517:                ActionResult result = Actions.performAction(Actions.PRINCIPAL,
0518:                        parameter);
0519:                return result;
0520:            }
0521:
0522:            public final static synchronized ActionResult sort(
0523:                    String environment, String path, int direction)
0524:                    throws RemoteActionException {
0525:                String[][] parameter = { { "PATH", path },
0526:                        { "DIRECTION", (directions[direction]) },
0527:                        { "environment", environment } };
0528:                ActionResult response = Actions.performAction(Actions.SORT,
0529:                        parameter);
0530:                return response;
0531:            }
0532:
0533:            public final static synchronized ActionResult create(
0534:                    String environment, String parent, String name,
0535:                    String blueprint) throws RemoteActionException {
0536:                String[][] parameter = { { "PARENT", parent },
0537:                        { "NAME", blueprint }, { "BLUEPRINT", name },
0538:                        { "environment", environment } };
0539:                ActionResult response = Actions.performAction(Actions.CREATE,
0540:                        parameter);
0541:                return response;
0542:            }
0543:
0544:            public final static synchronized ActionResult export(
0545:                    String environment, String name, String dir, String filename)
0546:                    throws RemoteActionException {
0547:                String[][] parameter = { { "NAME", name }, { "DIR", dir },
0548:                        { "FILENAME", filename },
0549:                        { "environment", environment } };
0550:                ActionResult response = Actions.performAction(Actions.EXPORT,
0551:                        parameter);
0552:                return response;
0553:            }
0554:
0555:            public final static synchronized ActionResult upload(
0556:                    String environment, String path, String filename,
0557:                    boolean forceOverwrite, String mimeType, String extension)
0558:                    throws RemoteActionException {
0559:                // invoke upload action
0560:                String[][] parameter = { { "PATH", path },
0561:                        { "FORCEOVERWRITE", Boolean.toString(forceOverwrite) },
0562:                        { "FILE_CONTENT_TYPE", mimeType },
0563:                        { "FILE_EXTENSION", extension },
0564:                        { "environment", environment } };
0565:                ActionResult response = Actions.performUploadAction(
0566:                        Actions.UPLOAD, parameter, filename);
0567:                return response;
0568:            }
0569:
0570:            public final static ActionResult getConfiguration()
0571:                    throws RemoteActionException {
0572:                ActionResult response = Actions
0573:                        .performAction(Actions.GET_CONFIGURATION);
0574:                return response;
0575:            }
0576:
0577:            public final static synchronized ActionResult load(
0578:                    SimpleImportHandler importHandler, String root,
0579:                    String path, int depth, boolean content, boolean followLinks)
0580:                    throws RemoteActionException {
0581:                String[][] parameter = { { "ROOT", root }, { "PATH", path },
0582:                        { "DEPTH", Integer.toString(depth) },
0583:                        { "CONTENT", Boolean.toString(content) },
0584:                        { "FOLLOWLINKS", Boolean.toString(followLinks) } };
0585:                try {
0586:                    ActionResult actionResult = ServerConnector
0587:                            .performActionWithImportHandler(Actions.LOAD,
0588:                                    parameter, importHandler);
0589:                    return actionResult;
0590:                } catch (RemoteActionException rae) {
0591:                    throw rae;
0592:                } catch (Throwable t) {
0593:                    logger
0594:                            .log(
0595:                                    Level.SEVERE,
0596:                                    "Could not load component, error while parsing!",
0597:                                    t);
0598:                    throw new RemoteActionException(
0599:                            "Could not load component, error while parsing!", t);
0600:                }
0601:            }
0602:
0603:            public final static synchronized ActionResult loadConfiguration(
0604:                    String domain, SimpleImportHandler importHandler)
0605:                    throws RemoteActionException {
0606:                String[][] parameter = { { "DOMAIN", domain } };
0607:                try {
0608:                    ActionResult actionResult = ServerConnector
0609:                            .performActionWithImportHandler(
0610:                                    Actions.LOAD_CONFIGURATION, parameter,
0611:                                    importHandler);
0612:                    return actionResult;
0613:                } catch (RemoteActionException rae) {
0614:                    throw rae;
0615:                } catch (Throwable t) {
0616:                    logger.log(Level.SEVERE,
0617:                            "Could not load hotlinks, error while parsing!", t);
0618:                    throw new RemoteActionException(
0619:                            "Could not load component, error while parsing!", t);
0620:                }
0621:            }
0622:
0623:            public final static ActionResult getTypes()
0624:                    throws RemoteActionException {
0625:                ActionResult actionResult = Actions
0626:                        .performAction(Actions.GET_TYPES);
0627:                return actionResult;
0628:            }
0629:
0630:            public final static ActionResult getBlueprints()
0631:                    throws RemoteActionException {
0632:                ActionResult actionResult = Actions
0633:                        .performAction(Actions.GET_BLUEPRINTS);
0634:                return actionResult;
0635:            }
0636:
0637:            public final static synchronized ActionResult getServerInfo(
0638:                    URL server) throws RemoteActionException {
0639:                ActionResult actionResult = Actions.performAction(
0640:                        Actions.SERVER_INFO, server);
0641:                return actionResult;
0642:            }
0643:
0644:            public final static ActionResult pollEvents()
0645:                    throws RemoteActionException {
0646:                ActionResult actionResult = Actions
0647:                        .performAction(Actions.PULL_COMPONENT_SYSTEM_EVENTS);
0648:                return actionResult;
0649:            }
0650:
0651:            public final static synchronized ActionResult lock(
0652:                    String componentPath) throws RemoteActionException {
0653:                String[][] parameter = { { "component", componentPath },
0654:                        { "cmd", "lock" } };
0655:                ActionResult response = Actions.performAction(Actions.LOCK,
0656:                        parameter);
0657:                return response;
0658:            }
0659:
0660:            public final static synchronized ActionResult unlock(
0661:                    String componentPath) throws RemoteActionException {
0662:                String[][] parameter = { { "component", componentPath },
0663:                        { "cmd", "unlock" } };
0664:                ActionResult response = Actions.performAction(Actions.LOCK,
0665:                        parameter);
0666:                return response;
0667:            }
0668:
0669:            public final static synchronized ActionResult sendMessage(
0670:                    String sender, String message, String importance,
0671:                    String receiver) throws RemoteActionException {
0672:                ActionResult response = Actions.performAction(
0673:                        Actions.SEND_MESSAGE, new String[][] {
0674:                                { "sender", sender }, { "message", message },
0675:                                { "importance", importance },
0676:                                { "receiver", receiver } });
0677:                return response;
0678:            }
0679:
0680:            public final static synchronized ActionResult listSubComponents(
0681:                    String path, int start, int amount)
0682:                    throws RemoteActionException {
0683:                String[][] parameter = { { "PATH", path },
0684:                        { "START", String.valueOf(start) },
0685:                        { "AMOUNT", String.valueOf(amount) } };
0686:                ActionResult actionResult = Actions.performAction(
0687:                        Actions.LIST_SUBCOMPONENTS, parameter);
0688:                return actionResult;
0689:            }
0690:
0691:            public final static synchronized ActionResult changeBlueprintType(
0692:                    String environment, String path, String typeName)
0693:                    throws RemoteActionException {
0694:                String[][] parameter = { { "PATH", path },
0695:                        { "TYPE", typeName }, { "environment", environment } };
0696:                ActionResult actionResult = Actions.performAction(
0697:                        Actions.CHANGE_TYPE, parameter);
0698:                return actionResult;
0699:            }
0700:
0701:            public final static synchronized ActionResult addToAllBlueprintInstances(
0702:                    String environment, String path)
0703:                    throws RemoteActionException {
0704:                String[][] parameter = { { "PATH", path }, { "CMD", "add" },
0705:                        { "environment", environment } };
0706:                ActionResult actionResult = Actions.performAction(
0707:                        Actions.REFACTOR_BLUEPRINT, parameter);
0708:                return actionResult;
0709:            }
0710:
0711:            public final static synchronized ActionResult cleanUpBlueprintInstances(
0712:                    String environment, String path)
0713:                    throws RemoteActionException {
0714:                String[][] parameter = { { "PATH", path }, { "CMD", "clean" },
0715:                        { "environment", environment } };
0716:                ActionResult actionResult = Actions.performAction(
0717:                        Actions.REFACTOR_BLUEPRINT, parameter);
0718:                return actionResult;
0719:            }
0720:
0721:            // public final static synchronized ActionResult jspUpload(byte[] data, String contentType)
0722:            // throws RemoteActionException {
0723:            // ActionResult actionResult = Actions.performAction(Actions.JSP_UPLOAD, data, contentType);
0724:            // return actionResult;
0725:            // }
0726:
0727:            // public final static synchronized ActionResult setAcl(byte[] data, String contentType) throws
0728:            // RemoteActionException {
0729:            // ActionResult actionResult = Actions.performAction(Actions.SET_ACL, data, contentType);
0730:            // return actionResult;
0731:            // }
0732:
0733:            // public final static synchronized ActionResult setProperties(byte[] data, String contentType)
0734:            // throws RemoteActionException {
0735:            // ActionResult actionResult = Actions.performAction(Actions.SET_PROPERTIES, data, contentType);
0736:            // return actionResult;
0737:            // }
0738:
0739:            public final static synchronized ActionResult commitChanges(
0740:                    String environment, String context, String componentPath)
0741:                    throws RemoteActionException {
0742:                String[][] parameter = { { "CM", context },
0743:                        { "CMCMD", "commitTree" }, { "ROOT", componentPath },
0744:                        { "environment", environment } };
0745:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0746:                        parameter);
0747:                return response;
0748:            }
0749:
0750:            public final static synchronized ActionResult discardChanges(
0751:                    String environment, String context, String componentPath)
0752:                    throws RemoteActionException {
0753:                String[][] parameter = { { "CM", context },
0754:                        { "CMCMD", "rollbackTree" }, { "ROOT", componentPath },
0755:                        { "environment", environment } };
0756:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0757:                        parameter);
0758:                return response;
0759:            }
0760:
0761:            public final static synchronized ActionResult acquireContext(
0762:                    String context) throws RemoteActionException {
0763:                String[][] parameter = { { "CM", context },
0764:                        { "CMCMD", "acquire" } };
0765:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0766:                        parameter);
0767:                return response;
0768:            }
0769:
0770:            public final static synchronized ActionResult createContext(
0771:                    String context, String xml) throws RemoteActionException {
0772:                String[][] parameter = { { "CM", context },
0773:                        { "CMCMD", "create" }, { "XML", xml } };
0774:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0775:                        parameter);
0776:                return response;
0777:            }
0778:
0779:            public final static synchronized ActionResult discardContext(
0780:                    String environment, String context)
0781:                    throws RemoteActionException {
0782:                String[][] parameter = { { "CM", context },
0783:                        { "CMCMD", "destroy" }, { "environment", environment }
0784:
0785:                };
0786:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0787:                        parameter);
0788:                return response;
0789:            }
0790:
0791:            public final static synchronized ActionResult commitContext(
0792:                    String environment, String context)
0793:                    throws RemoteActionException {
0794:                String[][] parameter = { { "CM", context },
0795:                        { "CMCMD", "commit" }, { "environment", environment } };
0796:                ActionResult response = Actions.performAction(Actions.CONTEXT,
0797:                        parameter);
0798:                return response;
0799:            }
0800:
0801:            public final static synchronized ActionResult loadContextACL(
0802:                    String context, SimpleImportHandler importHandler)
0803:                    throws RemoteActionException {
0804:                String[][] parameter = { { "CM", context },
0805:                        { "CMCMD", "getACL" } };
0806:                try {
0807:                    ActionResult actionResult = ServerConnector
0808:                            .performActionWithImportHandler(Actions.CONTEXT,
0809:                                    parameter, importHandler);
0810:                    return actionResult;
0811:                } catch (RemoteActionException rae) {
0812:                    throw rae;
0813:                } catch (Throwable t) {
0814:                    logger.log(Level.SEVERE, "Could not load ACL for context "
0815:                            + context + ", error while parsing!", t);
0816:                    throw new RemoteActionException(
0817:                            "Could not load ACL for context " + context
0818:                                    + ", error while parsing!", t);
0819:                }
0820:            }
0821:
0822:            public final static synchronized ActionResult saveContextACL(
0823:                    String context, String xml) throws RemoteActionException {
0824:                String[][] parameter = { { "CM", context }, { "XML", xml },
0825:                        { "CMCMD", "setACL" } };
0826:                ActionResult actionResult = ServerConnector.performAction(
0827:                        Actions.CONTEXT, parameter);
0828:                return actionResult;
0829:            }
0830:
0831:            public final static synchronized ActionResult startWorkflow(
0832:                    String workflowDefinitionName, String workflowName,
0833:                    String description) throws RemoteActionException {
0834:                String[][] parameter = { { "CMD", "start" },
0835:                        { "NAME", workflowName },
0836:                        { "DEF", workflowDefinitionName },
0837:                        { "DESC", description } };
0838:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0839:                        parameter);
0840:                return result;
0841:            }
0842:
0843:            public final static synchronized ActionResult listWorkflows()
0844:                    throws RemoteActionException {
0845:                String[][] parameter = { { "CMD", "wflist" } };
0846:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0847:                        parameter);
0848:                return result;
0849:            }
0850:
0851:            public final static synchronized ActionResult listWorkflowDefinitions()
0852:                    throws RemoteActionException {
0853:                String[][] parameter = { { "CMD", "list" } };
0854:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0855:                        parameter);
0856:                return result;
0857:            }
0858:
0859:            public final static synchronized ActionResult listTasks()
0860:                    throws RemoteActionException {
0861:                String[][] parameter = { { "CMD", "tasklist" } };
0862:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0863:                        parameter);
0864:                return result;
0865:            }
0866:
0867:            public final static synchronized ActionResult acquireTask(
0868:                    String taskId) throws RemoteActionException {
0869:                String[][] parameter = { { "CMD", "acquire" }, { "ID", taskId } };
0870:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0871:                        parameter);
0872:                return result;
0873:            }
0874:
0875:            public final static synchronized ActionResult activateTask(
0876:                    String taskId) throws RemoteActionException {
0877:                String[][] parameter = { { "CMD", "activate" },
0878:                        { "ID", taskId } };
0879:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0880:                        parameter);
0881:                return result;
0882:            }
0883:
0884:            public final static synchronized ActionResult taskAction(
0885:                    String taskId, String returnCode, String comment)
0886:                    throws RemoteActionException {
0887:                String[][] parameter = { { "CMD", "taskaction" },
0888:                        { "ID", taskId }, { "ACTION", returnCode },
0889:                        { "COMMENT", comment } };
0890:                ActionResult result = Actions.performAction(Actions.WORKFLOW,
0891:                        parameter);
0892:                return result;
0893:            }
0894:
0895:            public final static synchronized ActionResult toggleFinalFlag(
0896:                    String environment, String component, boolean flag)
0897:                    throws RemoteActionException {
0898:                String[][] parameter = { { "CMD", "setFinal" },
0899:                        { "NAME", component },
0900:                        { "FLAG", String.valueOf(flag) },
0901:                        { "environment", environment } };
0902:                ActionResult result = Actions.performAction(
0903:                        Actions.TOGGLE_FINAL, parameter);
0904:                return result;
0905:            }
0906:
0907:            public final static synchronized ActionResult certifyComponent(
0908:                    String environment, String name, String key,
0909:                    String component, boolean subTree, String type)
0910:                    throws RemoteActionException {
0911:                String[][] parameter = { { "name", name }, { "key", key },
0912:                        { "component", component },
0913:                        { "subTree", String.valueOf(subTree) },
0914:                        { "type", type }, { "environment", environment } };
0915:                ActionResult result = Actions.performAction(Actions.PUBLISHER,
0916:                        parameter);
0917:                return result;
0918:            }
0919:
0920:            public final static synchronized ActionResult subtreeSize(
0921:                    String path) throws RemoteActionException {
0922:                String[][] parameter = { { "PATH", path } };
0923:                ActionResult result = Actions.performAction(
0924:                        Actions.SUBTREE_SIZE, parameter);
0925:                return result;
0926:            }
0927:
0928:            public final static synchronized ActionResult jmxInfo()
0929:                    throws RemoteActionException {
0930:                String[][] parameter = { { "cmd", "info" } };
0931:                ActionResult result = Actions.performAction(Actions.JMX,
0932:                        parameter);
0933:                return result;
0934:            }
0935:
0936:            public final static synchronized ActionResult jmxOperation(
0937:                    String name, String types, String parameters)
0938:                    throws RemoteActionException {
0939:                String[][] parameter = { { "cmd", "operation" },
0940:                        { "name", name }, { "types", types },
0941:                        { "parameters", parameters } };
0942:                ActionResult result = Actions.performAction(Actions.JMX,
0943:                        parameter);
0944:                return result;
0945:            }
0946:
0947:            /**
0948:             * Creates the content in the specified component (if component not exists, a CText component with the specified
0949:             * name will be created) below the user home directory.
0950:             * 
0951:             * Actually only textual content is allowed.
0952:             * 
0953:             * @param value
0954:             *            the user content to be saved.
0955:             * @param relativePath
0956:             *            the component below the user home directory. Actually only a flat component hierarchy (no subfolders)
0957:             *            is allowed.
0958:             * 
0959:             * @return ActionResult
0960:             * 
0961:             * @throws RemoteActionException
0962:             */
0963:            public final static synchronized ActionResult createUserContent(
0964:                    String value, String relativePath)
0965:                    throws RemoteActionException {
0966:
0967:                String[][] parameter = { { "cmd", "operation" },
0968:                        { "VALUE", value }, { "RELATIVEPATH", relativePath } };
0969:                ActionResult result = Actions.performAction(
0970:                        Actions.CREATE_USER_CONTENT, parameter);
0971:
0972:                return result;
0973:            }
0974:
0975:            /**
0976:             * <em>CAUTION: Should only be called from ActionEditor or FActionEditor and from packages</em>.
0977:             */
0978:            public final static synchronized ActionResult tunnelDirectActionCall(
0979:                    RemoteAction action) throws RemoteActionException {
0980:                return performAction(action);
0981:            }
0982:
0983:            /**
0984:             * <em>CAUTION: Should only be called from ActionEditor or FActionEditor and from packages</em>.
0985:             */
0986:            public final static synchronized ActionResult tunnelDirectActionCall(
0987:                    RemoteAction action, String[][] parameter)
0988:                    throws RemoteActionException {
0989:                return performAction(action, parameter);
0990:            }
0991:
0992:            /**
0993:             * Update a component on the server.
0994:             * 
0995:             * @param component
0996:             *            the component to be updated.
0997:             * @return the result of the action.
0998:             */
0999:            public final static synchronized ActionResult updateComponent(
1000:                    String environment, ContelligentComponent component)
1001:                    throws RemoteActionException {
1002:                try {
1003:                    Map<String, String> resourceFileMap = new HashMap<String, String>();
1004:                    String componentAsXml = ContelligentConstants.XML_HEADER
1005:                            + modifiedComponentToXml(component, resourceFileMap);
1006:                    Map<String, byte[]> data = new HashMap<String, byte[]>();
1007:                    logger.finest("## componentAsXML = " + componentAsXml);
1008:                    // System.out.println("abc: "+componentAsXml);
1009:
1010:                    data.put("XML", componentAsXml.getBytes("UTF-8"));
1011:
1012:                    Map<String, String> parameters = new HashMap<String, String>();
1013:                    parameters.put("environment", environment);
1014:
1015:                    return performMultipartAction(UPDATE_COMPONENT, parameters,
1016:                            data, resourceFileMap);
1017:                } catch (IOException ioe) {
1018:                    throw new RemoteActionException(
1019:                            "Could not convert component to XML", ioe);
1020:                }
1021:            }
1022:
1023:            /**
1024:             * Converts a component to its XML representation containing only its modified parts.
1025:             * 
1026:             * @return the XML representation of the component.
1027:             */
1028:            public final static synchronized String modifiedComponentToXml(
1029:                    ContelligentComponent component,
1030:                    Map<String, String> resourceFileMap) throws IOException {
1031:                String composedBlueprint = component.getComposedBlueprint();
1032:                Collection resources = component.getResourceMap().values();
1033:                Collection templates = component.getTemplates();
1034:                StringWriter sw = new StringWriter();
1035:                XMLWriter xmlWriter = new XMLWriter(sw);
1036:                Vector<String> attributeNamesVector = new Vector<String>();
1037:                Vector<String> attributeValuesVector = new Vector<String>();
1038:                String[] attributeNames = null;
1039:                String[] attributeValues = null;
1040:
1041:                xmlWriter.writeStartTag(XMLWriter.createStartTag("component",
1042:                        new String[] { "name", "dir", "type" }, new String[] {
1043:                                component.getName(), component.getDir(),
1044:                                component.getType().getName() }, false));
1045:
1046:                attributeNamesVector.removeAllElements();
1047:                attributeValuesVector.removeAllElements();
1048:                attributeNamesVector.add("lastModified");
1049:                attributeValuesVector.add(String.valueOf(component
1050:                        .getLastModified()));
1051:                attributeNamesVector.add("isFinal");
1052:                attributeValuesVector.add(Boolean.valueOf(component.isFinal())
1053:                        .toString());
1054:                if (composedBlueprint != null) {
1055:                    attributeNamesVector.add("composedBlueprint");
1056:                    attributeValuesVector.add(composedBlueprint);
1057:                }
1058:                attributeNames = new String[attributeNamesVector.size()];
1059:                attributeValues = new String[attributeValuesVector.size()];
1060:                attributeNamesVector.copyInto(attributeNames);
1061:                attributeValuesVector.copyInto(attributeValues);
1062:                xmlWriter.writeStartTag(XMLWriter.createStartTag("meta-info",
1063:                        attributeNames, attributeValues, false));
1064:
1065:                if (component.isAclModified()) {
1066:                    aclToXml(component, xmlWriter);
1067:                }
1068:
1069:                xmlWriter.writeEndTag(XMLWriter.createEndTag("meta-info"));
1070:
1071:                if (component.isModified()) {
1072:                    Collection properties = component.getProperties().values();
1073:
1074:                    for (Iterator i = properties.iterator(); i.hasNext();) {
1075:                        ComponentProperty property = (ComponentProperty) i
1076:                                .next();
1077:                        String propertyName = property.getName();
1078:                        String propertyValue = property.getValue();
1079:                        if (propertyValue != null) {
1080:                            xmlWriter.writeStartTag(XMLWriter.createStartTag(
1081:                                    "component-property",
1082:                                    new String[] { "name" },
1083:                                    new String[] { propertyName }, false),
1084:                                    false);
1085:                            xmlWriter.writeCData(propertyValue);
1086:                            xmlWriter.writeEndTag(XMLWriter
1087:                                    .createEndTag("component-property"));
1088:                        }
1089:                    }
1090:                    List metaKeys = component.getMetadataKeys();
1091:                    List metaValues = component.getMetadataValues();
1092:                    for (int i = 0; i < metaKeys.size(); i++) {
1093:                        xmlWriter.writeStartTag(XMLWriter.createStartTag(
1094:                                "metadata", new String[] {}, new String[] {},
1095:                                false));
1096:                        xmlWriter.writeStartTag(XMLWriter.createStartTag("key",
1097:                                new String[] {}, new String[] {}, false));
1098:                        xmlWriter.writeCData((String) metaKeys.get(i));
1099:                        xmlWriter.writeEndTag(XMLWriter.createEndTag("key"));
1100:                        xmlWriter.writeStartTag(XMLWriter.createStartTag(
1101:                                "value", new String[] {}, new String[] {},
1102:                                false));
1103:                        xmlWriter.writeCData((String) metaValues.get(i));
1104:                        xmlWriter.writeEndTag(XMLWriter.createEndTag("value"));
1105:                        xmlWriter.writeEndTag(XMLWriter
1106:                                .createEndTag("metadata"));
1107:                    }
1108:
1109:                }
1110:
1111:                xmlWriter.writeStartTag(XMLWriter.createStartTag("content",
1112:                        new String[0], new String[0], false));
1113:
1114:                sensitiveCategoriesToXml(xmlWriter, component
1115:                        .getContentCategories());
1116:
1117:                for (Iterator i = resources.iterator(); i.hasNext();) {
1118:                    ContelligentResource resource = null;
1119:                    Object resourceOrReference = i.next();
1120:
1121:                    if (resourceOrReference instanceof  ContelligentResource) {
1122:                        resource = (ContelligentResource) resourceOrReference;
1123:                        List contentCats = component.getContentCategories();
1124:
1125:                        boolean contentResourceSupported = isResourceSupported(
1126:                                resource, contentCats);
1127:                        if (resource.isModified() && contentResourceSupported) {
1128:                            resourceToXml(xmlWriter, resource, resourceFileMap);
1129:                        }
1130:                        if (!contentResourceSupported) {
1131:                            invalidatedResourceToXml(xmlWriter, resource,
1132:                                    resourceFileMap);
1133:                        }
1134:                    } else if (resourceOrReference instanceof  ContelligentResourceReference) {
1135:                        logger.log(Level.INFO,
1136:                                "Resource reference will not be sent to server: "
1137:                                        + resource);
1138:                        // resource = ((ContelligentResourceReference)
1139:                        // resourceOrReference).getResource();
1140:                    } else {
1141:                        // Can not be handled as a resource.
1142:                        logger.log(Level.SEVERE, "Resource can not be handled "
1143:                                + resource);
1144:                    }
1145:                }
1146:
1147:                xmlWriter.writeEndTag(XMLWriter.createEndTag("content"));
1148:
1149:                xmlWriter.writeStartTag(XMLWriter.createStartTag("renderer",
1150:                        new String[] { "type" }, new String[] { component
1151:                                .getRenderer() }, false));
1152:
1153:                sensitiveCategoriesToXml(xmlWriter, component
1154:                        .getTemplateCategories());
1155:                for (Iterator i = templates.iterator(); i.hasNext();) {
1156:                    ContelligentResource resource = null;
1157:                    Object resourceOrReference = i.next();
1158:
1159:                    if (resourceOrReference instanceof  ContelligentResource) {
1160:                        resource = (ContelligentResource) resourceOrReference;
1161:                    } else if (resourceOrReference instanceof  ContelligentResourceReference) {
1162:                        resource = ((ContelligentResourceReference) resourceOrReference)
1163:                                .getResource();
1164:                    } else {
1165:                        // Can not be handled as a resource.
1166:                    }
1167:                    List templateCats = component.getTemplateCategories();
1168:
1169:                    boolean templateResourceSupported = isResourceSupported(
1170:                            resource, templateCats);
1171:                    if (resource.isModified() && templateResourceSupported) {
1172:                        resourceToXml(xmlWriter, resource, resourceFileMap);
1173:                    }
1174:                    if (!templateResourceSupported) {
1175:                        invalidatedResourceToXml(xmlWriter, resource,
1176:                                resourceFileMap);
1177:                    }
1178:                }
1179:                xmlWriter.writeEndTag(XMLWriter.createEndTag("renderer"));
1180:
1181:                // Subcomponents are not converted.
1182:
1183:                xmlWriter.writeEndTag(XMLWriter.createEndTag("component"));
1184:
1185:                xmlWriter.flush();
1186:                return sw.toString();
1187:            }
1188:
1189:            /**
1190:             * This method checks whether the category map of a resource is still a valid subset of the supported categories of
1191:             * a component. This is to prevent zombie resources from remaining in the database after restricting the supported
1192:             * categories.
1193:             */
1194:            private final static boolean isResourceSupported(
1195:                    ContelligentResource resource,
1196:                    Collection sensitiveCategories) {
1197:                boolean valid = true;
1198:                Map resourceCatMap = resource.getCategoryMap();
1199:                // If the category map of the resource is null, it means that the
1200:                // resource is not dependent on any category; so we always return true
1201:                // in that special case.
1202:                if (resourceCatMap != null) {
1203:                    Iterator rescatKeys = resourceCatMap.keySet().iterator();
1204:                    while (rescatKeys.hasNext()) {
1205:                        String key = (String) rescatKeys.next();
1206:                        String value = (String) resourceCatMap.get(key);
1207:                        Iterator i = sensitiveCategories.iterator();
1208:                        while (i.hasNext()) {
1209:                            ContelligentCategory category = (ContelligentCategory) i
1210:                                    .next();
1211:                            String name = category.getName();
1212:                            if (name.equals(key)) {
1213:                                if (!category.isValueSupported(value)) {
1214:                                    valid = false;
1215:                                }
1216:                            }
1217:                        }
1218:                    }
1219:                }
1220:                return valid;
1221:            }
1222:
1223:            private final static void aclToXml(ContelligentComponent component,
1224:                    XMLWriter xmlWriter) throws IOException {
1225:                Collection owners = component.getOwners();
1226:                Collection acl = component.getACL();
1227:
1228:                xmlWriter.writeStartTag(XMLWriter.createStartTag("security",
1229:                        new String[] { "definesSecureTransfer" },
1230:                        new String[] { Boolean.valueOf(
1231:                                component.getDefinesSecureTransfer())
1232:                                .toString() }, false));
1233:
1234:                for (Iterator i = owners.iterator(); i.hasNext();) {
1235:                    Principal principal = (Principal) i.next();
1236:
1237:                    xmlWriter.writeEmptyElement(XMLWriter
1238:                            .createEmptyTag("owner", new String[] {
1239:                                    "principalGroupId", "principalId" },
1240:                                    new String[] { principal.getGroupId(),
1241:                                            principal.getId() }));
1242:                }
1243:                for (Iterator i = acl.iterator(); i.hasNext();) {
1244:                    ComponentAccess access = (ComponentAccess) i.next();
1245:
1246:                    xmlWriter.writeEmptyElement(XMLWriter.createEmptyTag(
1247:                            "access", new String[] { "principalGroupId",
1248:                                    "principalId", "accessType", "mode",
1249:                                    "parentMode", "validFrom", "validTo",
1250:                                    "period", "duration" }, new String[] {
1251:                                    access.getPrincipal().getGroupId(),
1252:                                    access.getPrincipal().getId(),
1253:                                    access.getPermission(), access.getMode(),
1254:                                    access.getParentMode(),
1255:                                    Long.toString(access.getValidFrom()),
1256:                                    Long.toString(access.getValidTo()),
1257:                                    Long.toString(access.getPeriod()),
1258:                                    Long.toString(access.getDuration()), }));
1259:                }
1260:                xmlWriter.writeEndTag(XMLWriter.createEndTag("security"));
1261:            }
1262:
1263:            /**
1264:             * Converts sensitive categories to XML.
1265:             * 
1266:             * @param xmlWriter
1267:             *            the object to which the XML representation is written.
1268:             * @param sensitiveCategories
1269:             *            the sensitive categories to be converted.
1270:             */
1271:            private final static void sensitiveCategoriesToXml(
1272:                    XMLWriter xmlWriter, Collection sensitiveCategories)
1273:                    throws IOException {
1274:                synchronized (sensitiveCategories) {
1275:                    for (Iterator i = sensitiveCategories.iterator(); i
1276:                            .hasNext();) {
1277:                        ContelligentCategory category = (ContelligentCategory) i
1278:                                .next();
1279:                        String name = category.getName();
1280:                        String[] values = category.getSupportedValues();
1281:                        StringBuffer valuesBuffer = new StringBuffer();
1282:
1283:                        valuesBuffer.append(values[0]);
1284:                        for (int j = 1; j < values.length; j++) {
1285:                            valuesBuffer.append(",");
1286:                            valuesBuffer.append(values[j]);
1287:                        }
1288:
1289:                        xmlWriter.writeEmptyElement(XMLWriter.createStartTag(
1290:                                "sensitive-category", new String[] { "name",
1291:                                        "supportedValues" }, new String[] {
1292:                                        name, valuesBuffer.toString() }, true));
1293:                    }
1294:                }
1295:            }
1296:
1297:            private final static void invalidatedResourceToXml(
1298:                    XMLWriter xmlWriter, ContelligentResource resource,
1299:                    Map resourceFileMap) throws IOException {
1300:                xmlWriter.writeStartTag(XMLWriter.createStartTag("resource",
1301:                        new String[0], new String[0], false));
1302:                if (resource.getCategoryMap() != null) {
1303:                    Set categoryEntries = resource.getCategoryMap().entrySet();
1304:                    for (Iterator i = categoryEntries.iterator(); i.hasNext();) {
1305:                        Map.Entry categoryEntry = (Map.Entry) i.next();
1306:
1307:                        xmlWriter.writeEmptyElement(XMLWriter.createStartTag(
1308:                                "supported-category", new String[] { "name",
1309:                                        "value" }, new String[] {
1310:                                        (String) categoryEntry.getKey(),
1311:                                        (String) categoryEntry.getValue() },
1312:                                true));
1313:                    }
1314:                }
1315:                xmlWriter.writeEmptyElement(XMLWriter
1316:                        .createEmptyTag("invalidated"));
1317:                xmlWriter.writeEndTag(XMLWriter.createEndTag("resource"));
1318:            }
1319:
1320:            /**
1321:             * Converts a resource to XML.
1322:             * 
1323:             * @param xmlWriter
1324:             *            the object to which the XML representation is written.
1325:             * @param resource
1326:             *            the resource to be converted.
1327:             * @param resourceFileMap
1328:             *            [String/String] binary source names mapped to the absolute path names of their respective files
1329:             */
1330:            private final static void resourceToXml(XMLWriter xmlWriter,
1331:                    ContelligentResource resource,
1332:                    Map<String, String> resourceFileMap) throws IOException {
1333:
1334:                xmlWriter.writeStartTag(XMLWriter.createStartTag("resource",
1335:                        new String[0], new String[0], false));
1336:                if (resource.getCategoryMap() != null) {
1337:                    Set categoryEntries = resource.getCategoryMap().entrySet();
1338:                    for (Iterator i = categoryEntries.iterator(); i.hasNext();) {
1339:                        Map.Entry categoryEntry = (Map.Entry) i.next();
1340:
1341:                        xmlWriter.writeEmptyElement(XMLWriter.createStartTag(
1342:                                "supported-category", new String[] { "name",
1343:                                        "value" }, new String[] {
1344:                                        (String) categoryEntry.getKey(),
1345:                                        (String) categoryEntry.getValue() },
1346:                                true));
1347:                    }
1348:                }
1349:
1350:                if (resource instanceof  ContelligentBinaryResource) {
1351:                    ContelligentBinaryResource binaryResource = (ContelligentBinaryResource) resource;
1352:                    String contentType = binaryResource.getContentType();
1353:                    String extension = binaryResource.getExtension();
1354:                    String source = "binary" + resourceFileMap.size();
1355:                    File referencedFile = binaryResource.getReferencedFile();
1356:                    if (referencedFile != null) {
1357:                        xmlWriter
1358:                                .writeEmptyElement(XMLWriter.createStartTag(
1359:                                        "binary", new String[] { "contentType",
1360:                                                "extension", "src" },
1361:                                        new String[] { contentType, extension,
1362:                                                source }, true));
1363:
1364:                        resourceFileMap.put(source, referencedFile
1365:                                .getAbsolutePath());
1366:                    }
1367:                } else if (resource instanceof  ContelligentBooleanResource) {
1368:                    ContelligentBooleanResource booleanResource = (ContelligentBooleanResource) resource;
1369:
1370:                    xmlWriter.writeEmptyElement(XMLWriter.createStartTag(
1371:                            "boolean", new String[] { "value" },
1372:                            new String[] { Boolean.valueOf(
1373:                                    booleanResource.getValue()).toString() },
1374:                            true));
1375:                } else if (resource instanceof  ContelligentNumberResource) {
1376:                    ContelligentNumberResource numberResource = (ContelligentNumberResource) resource;
1377:                    XMLWriter.generateAndWriteElementWithCData(xmlWriter,
1378:                            "number", new String[][] { { "constraints",
1379:                                    numberResource.getConstraints() } },
1380:                            numberResource.getNumber().toString());
1381:                } else if (resource instanceof  ContelligentStringResource) {
1382:                    ContelligentStringResource stringResource = (ContelligentStringResource) resource;
1383:
1384:                    xmlWriter.writeStartTag(XMLWriter.createStartTag("string",
1385:                            new String[] { "constraints" },
1386:                            new String[] { stringResource.getConstraints() },
1387:                            false));
1388:                    logger.finest("##String=" + stringResource.getString());
1389:                    xmlWriter.writeCData(stringResource.getString());
1390:                    xmlWriter.writeEndTag(XMLWriter.createEndTag("string"));
1391:                } else if (resource instanceof  ContelligentTextResource) {
1392:                    ContelligentTextResource textResource = (ContelligentTextResource) resource;
1393:
1394:                    xmlWriter.writeStartTag(XMLWriter.createStartTag("text",
1395:                            new String[0], new String[0], false));
1396:                    if (textResource.getText() == null) {
1397:                        logger.log(Level.SEVERE, "Can not write null text: "
1398:                                + textResource);
1399:                    } else {
1400:                        xmlWriter.writeCData(textResource.getText());
1401:                    }
1402:                    xmlWriter.writeEndTag(XMLWriter.createEndTag("text"));
1403:                } else {
1404:                    // Resource type is unknown.
1405:                }
1406:                xmlWriter.writeEndTag(XMLWriter.createEndTag("resource"));
1407:            }
1408:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.