001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme.deployment.jboss;
023:
024: import org.jboss.portal.theme.metadata.PortalThemeMetaData;
025: import org.jboss.portal.theme.metadata.ThemeLinkMetaData;
026: import org.jboss.portal.theme.metadata.ThemeScriptMetaData;
027: import org.jboss.xb.binding.ObjectModelFactory;
028: import org.jboss.xb.binding.UnmarshallingContext;
029: import org.xml.sax.Attributes;
030:
031: import java.util.ArrayList;
032:
033: /**
034: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
035: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
036: * @version $Revision: 8784 $
037: */
038: public class PortalThemeMetaDataFactory implements ObjectModelFactory {
039:
040: public Object newRoot(Object root, UnmarshallingContext nav,
041: String nsURI, String localName, Attributes attrs) {
042: return new ArrayList();
043: }
044:
045: public Object completeRoot(Object root, UnmarshallingContext nav,
046: String nsURI, String localName) {
047: return root;
048: }
049:
050: public Object newChild(ArrayList list, UnmarshallingContext nav,
051: String nsURI, String localName, Attributes attrs) {
052: if ("theme".equals(localName)) {
053: return new PortalThemeMetaData();
054: }
055: return null;
056: }
057:
058: public void addChild(ArrayList list,
059: PortalThemeMetaData portalTheme, UnmarshallingContext nav,
060: String nsURI, String localName) {
061: list.add(portalTheme);
062: }
063:
064: public void setValue(PortalThemeMetaData portalTheme,
065: UnmarshallingContext nav, String nsURI, String localName,
066: String value) {
067: if ("name".equals(localName)) {
068: portalTheme.setName(value);
069: } else if ("theme-implementation".equals(localName)) {
070: portalTheme.setClassName(value);
071: }
072: }
073:
074: public Object newChild(PortalThemeMetaData portalTheme,
075: UnmarshallingContext nav, String nsURI, String localName,
076: Attributes attrs) {
077: if ("script".equals(localName)) {
078: ThemeScriptMetaData script = new ThemeScriptMetaData();
079: script.setSrc(attrs.getValue("src"));
080: script.setId(attrs.getValue("id"));
081: script.setType(attrs.getValue("type"));
082: script.setCharset(attrs.getValue("charset"));
083: return script;
084: } else if ("link".equals(localName)) {
085: ThemeLinkMetaData link = new ThemeLinkMetaData();
086: link.setHref(attrs.getValue("href"));
087: link.setId(attrs.getValue("id"));
088: link.setType(attrs.getValue("type"));
089: link.setTitle(attrs.getValue("title"));
090: link.setMedia(attrs.getValue("media"));
091: link.setRel(attrs.getValue("rel"));
092: return link;
093: }
094: return null;
095: }
096:
097: public void setValue(ThemeScriptMetaData script,
098: UnmarshallingContext nav, String nsURI, String localName,
099: String value) {
100: if ("script".equals(localName)) {
101: script.setBodyContent(value);
102: }
103: }
104:
105: public void addChild(PortalThemeMetaData portalTheme,
106: ThemeScriptMetaData script, UnmarshallingContext nav,
107: String nsURI, String localName) {
108: portalTheme.getScripts().add(script);
109: }
110:
111: public void addChild(PortalThemeMetaData portalTheme,
112: ThemeLinkMetaData link, UnmarshallingContext nav,
113: String nsURI, String localName) {
114: portalTheme.getLinks().add(link);
115: }
116: }
|