⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dbdataimport.java

📁 java开发的一套非常好用的oa系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            doCreateUser = false;
            userCreated = false;
        }

        public void addProperty(String name, String value) {
            properties.put(name,value);
         }

        public void startElement(String uri, String localName, String tag,
                Attributes attribs)
                throws SAXParseException
        {
            if (localName.equals("Username")) {
                mode = USERNAME;
            }
            else if (localName.equals("Password")) {
                mode = PASSWORD;
            }
            else if (localName.equals("Email")) {
                mode = EMAIL;
                nameVisible = Boolean.valueOf(attribs.getValue(0)).booleanValue();
            }
            else if (localName.equals("Name")) {
                mode = NAME;
                emailVisible = Boolean.valueOf(attribs.getValue(0)).booleanValue();
            }
            else if (localName.equals("CreationDate")) {
                mode = CREATION_DATE;
            }
            else if (localName.equals("ModifiedDate")) {
                mode = MODIFIED_DATE;
            }
            else if (localName.equals("PropertyList")) {
                propertyListHandler.setParentHandler(this);
                propertyListHandler.setPropertyStore(this);
                parser.setContentHandler(propertyListHandler);
            }
        }

        public void characters(char[] buf, int start, int length)
                throws SAXParseException
        {
            switch (mode) {
                case USERNAME:
                    username.append(buf,start,length);
                    isUsernameSet = true;
                    break;
                case PASSWORD:
                    password.append(buf,start,length);
                    isPasswordSet = true;
                    break;
                case EMAIL:
                    email.append(buf,start,length);
                    isEmailSet = true;
                    break;
                case NAME:
                    name.append(buf,start,length);
                    break;
                case CREATION_DATE:
                    creationDate.append(buf,start,length);
                    break;
                case MODIFIED_DATE:
                    modifiedDate.append(buf,start,length);
                    break;
            }
            // check and see if we can create a message
            doCreateUser = (isUsernameSet && isPasswordSet && isEmailSet);
        }
        public void endElement(String uri, String localName, String tag)
                throws SAXParseException
        {
            // reset the mode now -- (fixes whitespace padding)
            mode = 0;

            if (localName.equals("User") && doCreateUser) {
                // create the user
                createUser();
                // Let parent resume handling SAX events
                parser.setContentHandler(parentHandler);
            }
        }

        private void createUser() {
            try {
                // Create the user. We pass in a map of properties at creation
                // time because this is the most efficient way to add
                // extended properties
                newUser = userManager.createUser(
                    username.toString(),
                    password.toString(),
                    name.toString(),
                    email.toString(),
                    nameVisible,emailVisible,properties
                );
                // Set the password hash -- the XML file gives us the password
                // hash, not the original password
                newUser.setPasswordHash(password.toString());
                // Set the creation date of the user
                try {
                    newUser.setCreationDate(dateFormatter.parse(creationDate.toString()));
                } catch(ParseException pe) {}
                // Set the modified date of the user
                try {
                    newUser.setModifiedDate(dateFormatter.parse(creationDate.toString()));
                } catch(ParseException pe) {}
            }
            catch (UserAlreadyExistsException uaee) {
                //print("User '" + username + "' already exists.");
            }
            catch (UnauthorizedException ue) {
                ue.printStackTrace();
            }
        }
    }

    /**
     *
     */
    private class GroupListHandler extends DefaultHandler {

        private ContentHandler parentHandler;

        /**
         * Sets the parentHandler of the handler. Control will be passed back
         * to the parent when this handler is done parsing the XML it knows
         * how to handle.
         */
        public void setParentHandler(DefaultHandler parentHandler) {
            this.parentHandler = parentHandler;
        }

        public void startElement(String uri, String localName, String tag,
                Attributes attribs)
                throws SAXParseException
        {
            if (localName.equals("Group")) {
                groupHandler.setParentHandler(this);
                parser.setContentHandler(groupHandler);
            }
        }
        public void endElement(String uri, String localName, String tag)
                throws SAXParseException
        {
            if (localName.equals("GroupList")) {
                // Let parent resume handling SAX events
                parser.setContentHandler(parentHandler);
            }
        }
    }

    /**
     *
     */
    private class GroupHandler extends DefaultHandler {

        private ContentHandler parentHandler;
        private Group group;

        private boolean isNameSet = false;
        private boolean isDescriptionSet = false;

        private StringBuffer username = new StringBuffer();
        private StringBuffer password = new StringBuffer();
        private StringBuffer email = new StringBuffer();
        private StringBuffer name = new StringBuffer();
        private StringBuffer creationDate = new StringBuffer();
        private StringBuffer modifiedDate = new StringBuffer();
        private boolean nameVisible = false;
        private boolean emailVisible = false;
        private Map properties = null;

        private boolean doCreateUser = false;
        private boolean userCreated = false;

        public void setParentHandler(DefaultHandler parentHandler) {
            this.parentHandler = parentHandler;

            //reset data
            group = null;
            isNameSet = false;
            isDescriptionSet = false;
            username.setLength(0);
            password.setLength(0);
            email.setLength(0);
            name.setLength(0);
            creationDate.setLength(0);
            modifiedDate.setLength(0);
            nameVisible = false;
            emailVisible = false;
            properties = new HashMap();
            doCreateUser = false;
            userCreated = false;
        }
/*
        public void addProperty(String name, String value) {
            properties.put(name,value);
         }

        public void startElement(String uri, String localName, String tag,
                Attributes attribs)
                throws SAXParseException
        {
            if (localName.equals("Username")) {
                mode = USERNAME;
            }
            else if (localName.equals("Password")) {
                mode = PASSWORD;
            }
            else if (localName.equals("Email")) {
                mode = EMAIL;
                nameVisible = Boolean.valueOf(attribs.getValue(0)).booleanValue();
            }
            else if (localName.equals("Name")) {
                mode = NAME;
                emailVisible = Boolean.valueOf(attribs.getValue(0)).booleanValue();
            }
            else if (localName.equals("CreationDate")) {
                mode = CREATION_DATE;
            }
            else if (localName.equals("ModifiedDate")) {
                mode = MODIFIED_DATE;
            }
            else if (localName.equals("PropertyList")) {
                propertyListHandler.setParentHandler(this);
                propertyListHandler.setPropertyStore(this);
                parser.setContentHandler(propertyListHandler);
            }
        }

        public void characters(char[] buf, int start, int length)
                throws SAXParseException
        {
            switch (mode) {
                case USERNAME:
                    username.append(buf,start,length);
                    isUsernameSet = true;
                    break;
                case PASSWORD:
                    password.append(buf,start,length);
                    isPasswordSet = true;
                    break;
                case EMAIL:
                    email.append(buf,start,length);
                    isEmailSet = true;
                    break;
                case NAME:
                    name.append(buf,start,length);
                    break;
                case CREATION_DATE:
                    creationDate.append(buf,start,length);
                    break;
                case MODIFIED_DATE:
                    modifiedDate.append(buf,start,length);
                    break;
            }
            // check and see if we can create a message
            doCreateUser = (isUsernameSet && isPasswordSet && isEmailSet);
        }
        public void endElement(String uri, String localName, String tag)
                throws SAXParseException
        {
            // reset the mode now -- (fixes whitespace padding)
            mode = 0;

            if (localName.equals("GROUP") && doCreateGroup) {
                // create the user
                createGroup();
                // Let parent resume handling SAX events
                parser.setContentHandler(parentHandler);
            }
        }

        /*private void createGroup() {
            try {
                // Create the user. We pass in a map of properties at creation
                // time because this is the most efficient way to add
                // extended properties
                group = groupManager.createGroup(name);
                group.
                );
                // Set the password hash -- the XML file gives us the password
                // hash, not the original password
                newUser.setPasswordHash(password.toString());
                // Set the creation date of the user
                try {
                    newUser.setCreationDate(dateFormatter.parse(creationDate.toString()));
                } catch(ParseException pe) {}
                // Set the modified date of the user
                try {
                    newUser.setModifiedDate(dateFormatter.parse(creationDate.toString()));
                } catch(ParseException pe) {}
            }
            catch (UserAlreadyExistsException uaee) {
                //print("User '" + username + "' already exists.");
            }
            catch (UnauthorizedException ue) {
                ue.printStackTrace();
            }
        }*/
    }

    /**
     *
     */
    private class ForumListHandler extends DefaultHandler {

        private ContentHandler parentHandler;

        /**
         * Sets the parentHandler of the handler. Control will be passed back
         * to the parent when this handler is done parsing the XML it knows
         * how to handle.
         */
        public void setParentHandler(DefaultHandler parentHandler) {
            this.parentHandler = parentHandler;
        }

        public void startElement(String uri, String localName, String tag,
                Attributes attribs)
                throws SAXParseException
        {
            if (localName.equals("Forum")) {
                forumHandler.setParentHandler(this);
                parser.setContentHandler(forumHandler);
            }
        }

        public void endElement(String uri, String localName, String tag)
                throws SAXParseException
        {
            if (localName.equals("ForumList")) {
                parser.setContentHandler(parentHandler);
            }
        }
    }

    /**
     *
     */
    private class ForumHandler extends DefaultHandler implements PropertyStore {

        private boolean doCreateForum = false;
        private boolean forumCreated = false;

        private boolean isNameSet = false;
        private boolean isDescriptionSet = false;
        private boolean isCreationDateSet = false;
        private boolean isModifiedDateSet = false;

        private StringBuffer name = new StringBuffer();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -