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.common.util.MediaType;
025: import org.jboss.portal.theme.metadata.RenderSetMetaData;
026: import org.jboss.portal.theme.metadata.RendererSetMetaData;
027: import org.jboss.xb.binding.ObjectModelFactory;
028: import org.jboss.xb.binding.UnmarshallingContext;
029: import org.xml.sax.Attributes;
030:
031: import javax.activation.MimeTypeParseException;
032: import java.util.ArrayList;
033:
034: /**
035: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
036: * @version $Revision: 8784 $
037: */
038: public class RenderSetMetaDataFactory 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 ("renderSet".equals(localName)) {
053: String name = attrs.getValue("name");
054: RenderSetMetaData renderSet = new RenderSetMetaData();
055: renderSet.setName(name);
056: return renderSet;
057: }
058: return null;
059: }
060:
061: public void addChild(ArrayList list, RenderSetMetaData renderSet,
062: UnmarshallingContext nav, String nsURI, String localName) {
063: list.add(renderSet);
064: }
065:
066: public Object newChild(RenderSetMetaData renderSet,
067: UnmarshallingContext nav, String nsURI, String localName,
068: Attributes attrs) throws MimeTypeParseException {
069: if ("set".equals(localName)) {
070: RendererSetMetaData rendererSet = new RendererSetMetaData();
071: String contentType = attrs.getValue("content-type");
072: rendererSet.setContentType(MediaType
073: .parseMimeType(contentType));
074: return rendererSet;
075: }
076: return null;
077: }
078:
079: public void addChild(RenderSetMetaData renderSet,
080: RendererSetMetaData rendererSet, UnmarshallingContext nav,
081: String nsURI, String localName) {
082: renderSet.getRendererSet().add(rendererSet);
083: }
084:
085: public void setValue(RendererSetMetaData rendererSet,
086: UnmarshallingContext nav, String nsURI, String localName,
087: String value) {
088: if ("region-renderer".equals(localName)) {
089: rendererSet.setRegionRenderer(value);
090: } else if ("window-renderer".equals(localName)) {
091: rendererSet.setWindowRenderer(value);
092: } else if ("portlet-renderer".equals(localName)) {
093: rendererSet.setPortletRenderer(value);
094: } else if ("decoration-renderer".equals(localName)) {
095: rendererSet.setDecorationRenderer(value);
096: } else if (localName.equals("ajax-enabled")) {
097: rendererSet.setAjaxEnabled(value.equals("true"));
098: }
099: }
100: }
|