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

📄 resourcecustompropertiestaghandler.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
字号:
/*************************************************************************** *                                                                         * *   This program is free software; you can redistribute it and/or modify  * *   it under the terms of the GNU General Public License as published by  * *   the Free Software Foundation; either version 2 of the License, or     * *   (at your option) any later version.                                   * *                                                                         * ***************************************************************************/package net.sourceforge.ganttproject.parser;import java.util.ArrayList;import java.util.GregorianCalendar;import java.util.Iterator;import java.util.List;import net.sourceforge.ganttproject.GanttCalendar;import net.sourceforge.ganttproject.Mediator;import net.sourceforge.ganttproject.resource.HumanResource;import net.sourceforge.ganttproject.resource.HumanResourceManager;import org.w3c.util.DateParser;import org.w3c.util.InvalidDateException;import org.xml.sax.Attributes;/** * This class parses the custom properties for tasks. */public class ResourceCustomPropertiesTagHandler implements TagHandler,        ParsingListener {    private HumanResourceManager manager = null;    private ParsingContext parsingContext = null;    private List listStructure = null;    public ResourceCustomPropertiesTagHandler(ParsingContext context,            HumanResourceManager manager) {        this.manager = manager;        this.parsingContext = context;        this.listStructure = new ArrayList();    }    /**     * Parses the element's attributes.     */    public void startElement(String namespaceURI, String sName, String qName,            Attributes attrs) throws FileFormatException {        if (qName.equals("rescustomproperty"))            loadProperty(attrs);    }    /**     * @see net.sourceforge.ganttproject.parser.TagHandler#endElement(java.lang.String,     *      java.lang.String, java.lang.String)     */    public void endElement(String namespaceURI, String sName, String qName) {        parsingFinished();    }    /**     * @see net.sourceforge.ganttproject.parser.ParsingListener#parsingStarted()     */    public void parsingStarted() {        // nothing to do.    }    /**     * Applies the parsed element to the resources     */    public void parsingFinished() {        Iterator it = this.listStructure.iterator();        while (it.hasNext()) {            CustomPropertiesStructure cps = (CustomPropertiesStructure) it                    .next();            HumanResource resource = (HumanResource) manager                    .getById(parsingContext.getResourceID());            String valueStr = cps.value;            Object value = null;            Class cla = manager.getCustomFieldType(cps.propertyName);            if (cla.equals(String.class))                value = valueStr.toString();            else if (cla.equals(Boolean.class))                value = Boolean.valueOf(valueStr);            else if (cla.equals(Integer.class))                value = Integer.valueOf(valueStr);            else if (cla.equals(Double.class))                value = Double.valueOf(valueStr);            else if (GregorianCalendar.class.isAssignableFrom(cla))                try {                    value = new GanttCalendar(DateParser.parse(valueStr));                } catch (InvalidDateException e) {                    e.printStackTrace();                }            resource.setCustomFieldVal(cps.propertyName, value);        }    }    private void loadProperty(Attributes attrs) {        if (attrs != null) {            CustomPropertiesStructure cps = new CustomPropertiesStructure();            cps.setResourceID(this.parsingContext.getResourceID());            cps.setPropertyName(attrs.getValue("property_name"));            cps.setValue(attrs.getValue("value"));            this.listStructure.add(cps);        }    }    private class CustomPropertiesStructure {        public int resourceID;        public String propertyName = null;        public String value = null;        public CustomPropertiesStructure() {        }        public void setResourceID(int id) {            resourceID = id;        }        public void setPropertyName(String name) {            propertyName = name;        }        public void setValue(String val) {            this.value = val;        }    }}

⌨️ 快捷键说明

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