Source Code Cross Referenced for BasketTransformer.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » portal » coplets » basket » 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 » apache lenya 2.0 » org.apache.cocoon.portal.coplets.basket 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.cocoon.portal.coplets.basket;
018:
019:        import java.io.IOException;
020:        import java.util.Iterator;
021:        import java.util.List;
022:
023:        import org.apache.avalon.framework.configuration.Configuration;
024:        import org.apache.avalon.framework.configuration.ConfigurationException;
025:        import org.apache.avalon.framework.service.ServiceException;
026:        import org.apache.cocoon.ProcessingException;
027:        import org.apache.cocoon.portal.PortalService;
028:        import org.apache.cocoon.portal.coplet.CopletInstanceData;
029:        import org.apache.cocoon.portal.coplets.basket.BasketManager.ActionInfo;
030:        import org.apache.cocoon.portal.coplets.basket.events.AddItemEvent;
031:        import org.apache.cocoon.portal.event.Event;
032:        import org.apache.cocoon.xml.AttributesImpl;
033:        import org.apache.cocoon.xml.XMLUtils;
034:        import org.xml.sax.Attributes;
035:        import org.xml.sax.SAXException;
036:
037:        /**
038:         * This transformer supports the basket and briefcase feature. It can generate links to
039:         * add content into a content store.
040:         *
041:         * @version CVS $Id: BasketTransformer.java 433543 2006-08-22 06:22:54Z crossley $
042:         */
043:        public class BasketTransformer extends AbstractBasketTransformer {
044:
045:            /** Element to add a link */
046:            protected static final String ADD_ITEM_ELEMENT = "add-item";
047:
048:            /** Element to show all actions */
049:            protected static final String SHOW_ACTIONS_ELEMENT = "show-actions";
050:
051:            /** The default store: briefcase or basket */
052:            protected String defaultStoreName = "basket";
053:
054:            /** The default link element name */
055:            protected String defaultLinkElement = "a";
056:
057:            /** The default namespace for the link element */
058:            protected String defaultLinkElementNS = "";
059:
060:            /* (non-Javadoc)
061:             * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
062:             */
063:            public void configure(Configuration configuration)
064:                    throws ConfigurationException {
065:                super .configure(configuration);
066:                this .defaultStoreName = configuration.getChild("default-store")
067:                        .getValue(this .defaultStoreName);
068:                this .defaultLinkElement = configuration.getChild(
069:                        "default-link-element").getValue(
070:                        this .defaultLinkElement);
071:                this .defaultLinkElementNS = configuration.getChild(
072:                        "default-link-element-ns").getValue(
073:                        this .defaultLinkElementNS);
074:            }
075:
076:            /* (non-Javadoc)
077:             * @see org.apache.cocoon.transformation.AbstractSAXTransformer#endTransformingElement(java.lang.String, java.lang.String, java.lang.String)
078:             */
079:            public void endTransformingElement(String uri, String name,
080:                    String raw) throws ProcessingException, IOException,
081:                    SAXException {
082:                if (ADD_ITEM_ELEMENT.equals(name)) {
083:                    final String linkElementName = this .parameters
084:                            .getParameter("link-element",
085:                                    this .defaultLinkElement);
086:                    final String linkElementNS = this .parameters.getParameter(
087:                            "link-element-ns", this .defaultLinkElementNS);
088:                    XMLUtils.endElement(this .contentHandler, linkElementNS,
089:                            linkElementName);
090:                } else if (SHOW_ACTIONS_ELEMENT.equals(name)) {
091:                    // nothing to do here
092:                }
093:            }
094:
095:            /* (non-Javadoc)
096:             * @see org.apache.cocoon.transformation.AbstractSAXTransformer#startTransformingElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
097:             */
098:            public void startTransformingElement(String uri, String name,
099:                    String raw, Attributes attr) throws ProcessingException,
100:                    IOException, SAXException {
101:                if (ADD_ITEM_ELEMENT.equals(name)) {
102:                    PortalService service = null;
103:                    try {
104:                        service = (PortalService) this .manager
105:                                .lookup(PortalService.ROLE);
106:
107:                        // do we want to add content or a link?
108:                        boolean addContent = false;
109:                        final String value = attr.getValue("content");
110:                        if (value != null) {
111:                            addContent = new Boolean(value).booleanValue();
112:                        }
113:
114:                        // do we want to add a url or a coplet?
115:                        final ContentItem ci;
116:                        final String href = attr.getValue("href");
117:                        if (href != null) {
118:                            ci = new ContentItem(href, addContent);
119:                        } else {
120:                            final String copletId = attr.getValue("coplet");
121:                            final CopletInstanceData cid = service
122:                                    .getComponentManager().getProfileManager()
123:                                    .getCopletInstanceData(copletId);
124:                            ci = new ContentItem(cid, addContent);
125:                        }
126:
127:                        // if a title is present set the title
128:                        final String title = attr.getValue("title");
129:                        if (title != null) {
130:                            ci.setTitle(title);
131:                        }
132:
133:                        // do we want to add the content to the basket or to the briefcase
134:                        final ContentStore store;
135:                        final String storeName = (attr.getValue("store") == null ? this .defaultStoreName
136:                                : attr.getValue("store"));
137:                        if ("basket".equalsIgnoreCase(storeName)) {
138:                            store = this .basketManager.getBasket();
139:                        } else {
140:                            store = this .basketManager.getBriefcase();
141:                        }
142:
143:                        final Event e = new AddItemEvent(store, ci);
144:                        final AttributesImpl ai = new AttributesImpl();
145:                        String newLink = service.getComponentManager()
146:                                .getLinkService().getLinkURI(e);
147:                        // check for bockmark
148:                        final String bookmark = attr.getValue("bookmark");
149:                        if (bookmark != null && bookmark.length() > 0) {
150:                            int pos = newLink.indexOf('?') + 1;
151:                            final char separator;
152:                            if (bookmark.indexOf('?') == -1) {
153:                                separator = '?';
154:                            } else {
155:                                separator = '&';
156:                            }
157:                            newLink = bookmark + separator
158:                                    + newLink.substring(pos);
159:                        }
160:                        ai.addCDATAAttribute("href", newLink);
161:
162:                        final String linkElementName = this .parameters
163:                                .getParameter("link-element",
164:                                        this .defaultLinkElement);
165:                        final String linkElementNS = this .parameters
166:                                .getParameter("link-element-ns",
167:                                        this .defaultLinkElementNS);
168:                        XMLUtils.startElement(this .contentHandler,
169:                                linkElementNS, linkElementName, ai);
170:                    } catch (ServiceException se) {
171:                        throw new SAXException(
172:                                "Unable to lookup portal service.", se);
173:                    } finally {
174:                        this .manager.release(service);
175:                    }
176:                } else if (SHOW_ACTIONS_ELEMENT.equals(name)) {
177:                    // basket or briefcase
178:                    final List actions;
179:                    final String storeName = (attr.getValue("store") == null ? this .defaultStoreName
180:                            : attr.getValue("store"));
181:                    if ("basket".equalsIgnoreCase(storeName)) {
182:                        actions = this .basketManager.getBasketActions();
183:                    } else {
184:                        actions = this .basketManager.getBriefcaseActions();
185:                    }
186:                    final String checkedAction = attr.getValue("checked");
187:                    final Iterator i = actions.iterator();
188:                    AttributesImpl a = new AttributesImpl();
189:                    while (i.hasNext()) {
190:                        final BasketManager.ActionInfo current = (ActionInfo) i
191:                                .next();
192:                        a.addCDATAAttribute("name", current.name);
193:                        if (current.name.equals(checkedAction)) {
194:                            a.addCDATAAttribute("checked", "true");
195:                        }
196:                        XMLUtils.createElement(this .xmlConsumer, "action", a);
197:                        a.clear();
198:                    }
199:                }
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.