001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
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 edu.iu.uis.eden.xml;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.util.ArrayList;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import javax.xml.parsers.DocumentBuilderFactory;
026: import javax.xml.parsers.FactoryConfigurationError;
027: import javax.xml.parsers.ParserConfigurationException;
028:
029: import org.jdom.Document;
030: import org.jdom.Element;
031: import org.jdom.JDOMException;
032: import org.jdom.Namespace;
033: import org.jdom.input.DOMBuilder;
034: import org.xml.sax.SAXException;
035:
036: import edu.iu.uis.eden.user.AuthenticationUserId;
037: import edu.iu.uis.eden.user.EmplId;
038: import edu.iu.uis.eden.user.UserService;
039: import edu.iu.uis.eden.user.UuId;
040: import edu.iu.uis.eden.user.WorkflowUser;
041: import edu.iu.uis.eden.user.WorkflowUserId;
042:
043: /**
044: * Parses users from XML.
045: *
046: * @see WorkflowUser
047: *
048: * @author rkirkend
049: */
050: public class UserXmlHandler {
051:
052: private static final Namespace NAMESPACE = Namespace.getNamespace(
053: "", "ns:workflow/User");
054:
055: private static final String USERS_ELEMENT = "users";
056: private static final String USER_ELEMENT = "user";
057: private static final String WORKFLOW_ID_ELEMENT = "workflowId";
058: private static final String EMPL_ID_ELEMENT = "emplId";
059: private static final String AUTHENTICATION_ID_ELEMENT = "authenticationId";
060: private static final String UUID_ELEMENT = "uuId";
061: private static final String EMAIL_ELEMENT = "emailAddress";
062: private static final String DISPLAY_NAME_ELEMENT = "displayName";
063: private static final String GIVEN_NAME_ELEMENT = "givenName";
064: private static final String LAST_NAME_ELEMENT = "lastName";
065:
066: //private static final String CREATE_DATE_ELEMENT = "createDate";
067: //private static final String LAST_UPDATE_DATE_ELEMENT = "lastUpdateDate";
068: //private static final String ID_MISSING_INDICATOR_ELEMENT = "identificationMissingIndicator";
069:
070: public List parseUserEntries(UserService userService,
071: InputStream file) throws JDOMException, SAXException,
072: IOException, ParserConfigurationException,
073: FactoryConfigurationError {
074: List userEntries = new ArrayList();
075:
076: org.w3c.dom.Document w3cDocument = DocumentBuilderFactory
077: .newInstance().newDocumentBuilder().parse(file);
078: //LOG.debug("parsing document: " + XmlHelper.jotNode(w3cDocument.getFirstChild()));
079: Document document = new DOMBuilder().build(w3cDocument);
080: Element root = document.getRootElement();
081:
082: for (Iterator usersElementIt = root.getChildren(USERS_ELEMENT,
083: NAMESPACE).iterator(); usersElementIt.hasNext();) {
084: Element usersElement = (Element) usersElementIt.next();
085: for (Iterator iterator = usersElement.getChildren(
086: USER_ELEMENT, NAMESPACE).iterator(); iterator
087: .hasNext();) {
088: Element userElement = (Element) iterator.next();
089:
090: WorkflowUser userEntry = userService.getBlankUser();
091: userEntry
092: .setAuthenticationUserId(new AuthenticationUserId(
093: userElement.getChildTextTrim(
094: AUTHENTICATION_ID_ELEMENT,
095: NAMESPACE)));
096:
097: userEntry.setDisplayName(userElement.getChildTextTrim(
098: DISPLAY_NAME_ELEMENT, NAMESPACE));
099: userEntry.setEmailAddress(userElement.getChildTextTrim(
100: EMAIL_ELEMENT, NAMESPACE));
101: userEntry.setEmplId(new EmplId(userElement
102: .getChildTextTrim(EMPL_ID_ELEMENT, NAMESPACE)));
103: userEntry.setGivenName(userElement.getChildTextTrim(
104: GIVEN_NAME_ELEMENT, NAMESPACE));
105: userEntry.setLastName(userElement.getChildTextTrim(
106: LAST_NAME_ELEMENT, NAMESPACE));
107: userEntry.setUuId(new UuId(userElement
108: .getChildTextTrim(UUID_ELEMENT, NAMESPACE)));
109: userEntry.setWorkflowUserId(new WorkflowUserId(
110: userElement.getChildTextTrim(
111: WORKFLOW_ID_ELEMENT, NAMESPACE)));
112: userEntries.add(userEntry);
113: }
114: }
115: return userEntries;
116: }
117: }
|