001: /*
002: * JBoss, a division of Red Hat
003: * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
004: * by the @authors tag. See the copyright.txt in the distribution for a
005: * full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022:
023: package org.jboss.portal.widget.google.directory;
024:
025: import org.jboss.xb.binding.GenericObjectModelFactory;
026: import org.jboss.xb.binding.UnmarshallingContext;
027: import org.jboss.portal.widget.google.metadata.GGWidgetMetaData;
028: import org.xml.sax.Attributes;
029:
030: import java.util.ArrayList;
031: import java.util.List;
032:
033: /**
034: * @author <a href="mailto:boleslaw dot dawidowicz at redhat anotherdot com">Boleslaw Dawidowicz</a>
035: * @version $Revision: 0.1 $
036: */
037: public class GGWidgetDirectoryFactory implements
038: GenericObjectModelFactory {
039:
040: public static final String GHAPI_URI = "http://www.google.com/apis/homepage";
041:
042: public Object newRoot(Object root,
043: UnmarshallingContext unmarshallingContext,
044: String namespaceURI, String localname, Attributes attributes) {
045: return new ArrayList();
046: }
047:
048: public Object completeRoot(Object root,
049: UnmarshallingContext unmarshallingContext,
050: String namespaceURI, String localname) {
051: return root;
052: }
053:
054: public Object newChild(Object parent,
055: UnmarshallingContext unmarshallingContext,
056: String namespaceURI, String localName, Attributes attributes) {
057: if ("channel".equals(localName)) {
058: return parent;
059: }
060: if ("item".equals(localName)) {
061: return new GGWidgetMetaData();
062: }
063: return null;
064: }
065:
066: public void addChild(Object parent, Object child,
067: UnmarshallingContext unmarshallingContext,
068: String namespaceURI, String localname) {
069: if (child instanceof GGWidgetMetaData) {
070: ((List) parent).add(child);
071: }
072: }
073:
074: public void setValue(Object object,
075: UnmarshallingContext unmarshallingContext,
076: String namespaceURI, String localName, String value) {
077: if (object instanceof GGWidgetMetaData) {
078: GGWidgetMetaData widget = (GGWidgetMetaData) object;
079: if (GHAPI_URI.equals(namespaceURI)) {
080: if ("author_email".equals(localName)) {
081: widget.setAuthorEmail(value);
082: } else if ("screenshot".equals(localName)) {
083: widget.setScreenshot(value);
084: } else if ("thumbnail".equals(localName)) {
085: widget.setThumbnail(value);
086: } else if ("author_location".equals(localName)) {
087: widget.setAuthorLocaltion(value);
088: } else if ("author_affiliation".equals(localName)) {
089: widget.setAuthorAffiliation(value);
090: } else if ("title_url".equals(localName)) {
091: widget.setTitleURL(value);
092: } else if ("directory_title".equals(localName)) {
093: widget.setDirectoryTitle(value);
094: } else if ("author_photo".equals(localName)) {
095: widget.setAuthorPhoto(value);
096: } else if ("author_aboutme".equals(localName)) {
097: widget.setAuthorAboutme(value);
098: } else if ("author_link".equals(localName)) {
099: widget.setAuthorLink(value);
100: } else if ("author_quote".equals(localName)) {
101: widget.setAuthorQuote(value);
102: }
103: if ("width".equals(localName)) {
104: widget.setWidth(value);
105: }
106: if ("height".equals(localName)) {
107: widget.setHeight(value);
108: }
109: } else {
110: if ("title".equals(localName)) {
111: widget.setTitle(value);
112: } else if ("link".equals(localName)) {
113: widget.setLink(value);
114: } else if ("guid".equals(localName)) {
115: //doubles 'link' tag
116: } else if ("description".equals(localName)) {
117: widget.setDescription(value);
118: } else if ("author".equals(localName)) {
119: widget.setAuthor(value);
120: }
121: }
122: }
123: }
124: }
|