cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: rev 55229 - cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam
Date Thu, 21 Oct 2004 16:06:41 GMT
Author: reinhard
Date: Thu Oct 21 09:06:41 2004
New Revision: 55229

Added:
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Team.java
   cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/TeamMember.java
Log:
add "dreamteam" application by Helma van der Linden (issue 31813)


Added: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Manager.java
Thu Oct 21 09:06:41 2004
@@ -0,0 +1,136 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.samples.dreamteam;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+
+/**
+ * Manager
+ */
+public class Manager {
+    private static Manager manager = new Manager();
+    private List allPersons = null;
+    private Team dreamTeam = null;
+
+    private Manager() {
+        super();
+    }
+    
+    public static Manager getManager() {
+        if (manager == null) {
+            manager = new Manager();
+        }
+        return manager;
+    }
+    public Hashtable getAllPersonsByPosition() {
+        Hashtable list = new Hashtable();
+        Team team = null;
+        TeamMember teamMember = null;
+        String position = null;
+        for (int i = 0; i < allPersons.size(); i++) {
+            teamMember = (TeamMember)allPersons.get(i);
+            position = teamMember.getPosition();
+            if (list.containsKey(position)) {
+                team = (Team)list.get(position);
+            }
+            else {
+                team = new Team();
+                list.put(position, team);
+            }
+            team.addMember(teamMember);
+        }
+        return list;
+        
+    }
+    public TeamMember getPerson(String memberID) {
+        TeamMember member = null;
+        if (allPersons == null) {
+            return null;
+        }
+        for (Iterator iter = allPersons.iterator(); iter.hasNext();) {
+            member = (TeamMember) iter.next();
+            if (member.getMemberId().equals(memberID)) {
+                return member;
+            }
+        }
+        return null;
+    }
+    
+    public void buildDreamTeam(Team dreamlist) {
+        if (dreamTeam != null) {
+            dreamTeam.getTeam().clear();
+        }
+        dreamTeam = new Team();
+        TeamMember listMember = null;
+        TeamMember dreamMember = null;
+        for (Iterator iter = dreamlist.getTeam().iterator(); iter.hasNext();) {
+            listMember = (TeamMember) iter.next();
+            dreamMember = getPerson(listMember.getMemberId());
+            dreamTeam.addMember(dreamMember);
+        }
+    }
+    
+    public Team getDreamTeam() {
+        if (dreamTeam == null) {
+            dreamTeam = new Team();
+            dreamTeam.setTeam(allPersons);
+        }
+        return dreamTeam;
+    }
+    
+    public void readPlayers(Document doc) {
+        NodeList players = doc.getElementsByTagName("player");
+        Node player = null;
+        int size = players.getLength(); 
+        for (int i = 0; i < size; i++) {
+            player = players.item(i);
+            addPlayer((Element)player);
+        }
+    }
+    
+    private void addPlayer(Element player) {
+        // convert the XML node to a TeamMember
+        if (allPersons == null) {
+            allPersons = new ArrayList();
+        }
+        TeamMember member = null;
+        member = new TeamMember();
+        member.setMemberId("" + (allPersons.size() + 1));
+        member.setName(getElementValue(player, "name"));
+        member.setPosition(getElementValue(player, "position"));
+        member.setCountry(getElementValue(player, "country"));
+//        System.out.println(member.toString());
+        allPersons.add(member);
+    }
+
+    private String getElementValue(Element element, String tag) {
+        String result = null;
+        NodeList nodes = element.getElementsByTagName(tag);
+        result = nodes.item(0).getFirstChild().getNodeValue();
+//        System.out.println("element: " + tag + "=" + result);
+        return result;
+    }
+
+}

Added: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Team.java
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/Team.java
Thu Oct 21 09:06:41 2004
@@ -0,0 +1,57 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.samples.dreamteam;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Team
+ */
+public class Team {
+
+	private Collection team = new ArrayList();
+
+	public Team() {
+	}
+
+	public Collection getTeam() {
+		return team;
+	}
+
+	public void setTeam(Collection _team) {
+		team = _team;
+	}
+
+	public void addMember(TeamMember member) {
+		team.add(member);
+	}
+
+	public TeamMember getMember(String memberID) {
+		TeamMember member = null;
+		if (team == null) {
+			return null;
+		}
+		for (Iterator iter = team.iterator(); iter.hasNext();) {
+			member = (TeamMember) iter.next();
+			if (member.getMemberId().equals(memberID)) {
+				return member;
+			}
+		}
+		return null;
+	}
+}
\ No newline at end of file

Added: cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/TeamMember.java
==============================================================================
--- (empty file)
+++ cocoon/trunk/src/blocks/forms/java/org/apache/cocoon/forms/samples/dreamteam/TeamMember.java
Thu Oct 21 09:06:41 2004
@@ -0,0 +1,81 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.forms.samples.dreamteam;
+
+/**
+ * TeamMember
+ */
+public class TeamMember {
+	private String memberId = null;
+	private String name = null;
+	private String position = null;
+	private String country = null;
+
+	public TeamMember() {
+		super();
+	}
+
+	public String getMemberId() {
+		return memberId;
+	}
+
+	public void setMemberId(String memberID) {
+		this.memberId = memberID;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public String getLastName() {
+		if (name == null) {
+			return "Name not set!";
+		}
+		String lastName = name.substring(name.indexOf(" ") + 1);
+		if (lastName.equals("")) {
+			lastName = name;
+		}
+		return lastName;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPosition() {
+		return position;
+	}
+
+	public void setPosition(String profession) {
+		this.position = profession;
+	}
+
+	public String getCountry() {
+		return country;
+	}
+
+	public void setCountry(String country) {
+		this.country = country;
+	}
+
+	public String toString() {
+		String result = "<member id='" + memberId + "'><name>" + name
+				+ "</name><position>" + position + "</position><country>"
+				+ country + "</country></member>";
+		return result;
+	}
+
+}
\ No newline at end of file

Mime
View raw message