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

📄 xmlmodel.java

📁 Owing to the applet Gantt chart source yard, already Chinese melt, Gantt chart can demonstrate a Chi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		}		task.setCompleted(Integer.parseInt(getChildText(doc, "completed")));		String s = getChildText(doc, "comments");		if (s != null)			task.setComments(s);		s = getChildText(doc, "notes");		if (s != null)			task.setNotes(s);		// Asignment		Node a = getChildByName(doc, XML_ASIGNMENT);		while (a != null) {			if (a.getNodeName().equals(XML_ASIGNMENT)) {				Asignation asign = readAsignation(project, a);				task.resources.add(asign);			}			a = a.getNextSibling();		}		// leer las subtareas		Node t = getChildByName(doc, XML_TASK);		while (t != null) {			if (t.getNodeName().equals(XML_TASK)) {				task.addChild(readTask(project, t));			}			t = t.getNextSibling();		}		// Snapshots		Node snapshots = getChildByName(doc, "snapshots");		if (snapshots != null) {			Node item = getChildByName(snapshots, "snapshot");			while (item != null) {				if (!item.getNodeName().equals("snapshot"))					break;				Date date = df.parse(getChildText(item,"id"));				Date start = df.parse(getChildText(item, "start"));				Date end = df.parse(getChildText(item, "end"));				int completed = Integer						.parseInt(getChildText(item, "completed"));				task.snapshots.add(new Task.SnapShot(date, start, end,						completed));				item = item.getNextSibling();			}		}		return task;	}	/**	 * @resource,	 * @units	 */	static public Asignation readAsignation(Project project, Node doc)			throws ParseException, GanttException {		// System.out.println("XMLModel.readAsignation()");		Asignation asign = new Asignation();		int id = Integer.parseInt(getChildText(doc, "resource"));		int units = Integer.parseInt(getChildText(doc, "percent"));		asign.setResource((Resource) (project.getResources().get(id - 1)));		asign.setUnits(units);		return asign;	}	/**	 * @resource,	 * @units	 */	static public Resource readResource(Project project, Node doc)			throws ParseException, GanttException {		int id = Integer.parseInt(getChildText(doc, "id"));		String name = getChildText(doc, XML_NAME);		String initials = getChildText(doc, "initials");		String alias = getChildText(doc, "alias");		Resource res = project.createResource(id, name, alias, initials);		return res;	}	// =============================================================================	// Lectura de Colores y otros datos	// =============================================================================	static Color parseColor(String s) {		if (s == null)			return Color.gray;		return new Color(Integer.parseInt(s, 16));	}	static String formatColor(Color c) {		return Integer.toHexString(c.getRGB() & 0x00ffffff);	}	// =============================================================================	// Lectura de Font	// =============================================================================	static Font parseFont(String s) {		StringTokenizer st = new StringTokenizer(s, ",");		String name = st.nextToken();		int style = Integer.parseInt(st.nextToken());		int size = Integer.parseInt(st.nextToken());		return new Font(name, style, size);	}	static String formatFont(Font f) {		return f.getFontName() + "," + f.getStyle() + "," + f.getSize();	}	/**	 * Lee un GraphColors	 */	static public GraphColors readGraphColors(Node doc) throws ParseException,			GanttException {		doc = getChildByName(doc, "GraphColors");		GraphColors gc = new GraphColors();		gc.background = parseColor(getChildText(doc, "background"));		gc.text = parseColor(getChildText(doc, "text"));		gc.titleFg = parseColor(getChildText(doc, "titleFg"));		gc.titleBg = parseColor(getChildText(doc, "titleBg"));		gc.div = parseColor(getChildText(doc, "div"));		gc.mayorDiv = parseColor(getChildText(doc, "mayorDiv"));		// gc.graph = parseColor( getChildText(doc, "graph") );		gc.weekEnd = parseColor(getChildText(doc, "weekEnd"));		gc.holiday = parseColor(getChildText(doc, "holiday"));		gc.now = parseColor(getChildText(doc, "now"));		gc.horLine = parseColor(getChildText(doc, "horLine"));		gc.snapshot = parseColor(getChildText(doc, "snapshot"));		gc.drawTaskLines = Boolean.valueOf(getChildText(doc, "drawTaskLines"))				.booleanValue();		gc.drawMinorLines = Boolean				.valueOf(getChildText(doc, "drawMinorLines")).booleanValue();		gc.defaultResumeColors = readTaskColors(getChildByName(doc,				"ResumeColors"));		gc.defaultTaskColors = readTaskColors(getChildByName(doc, "TaskColors"));		return gc;	}	/**	 * Generar una representacion de un GraphColors en un arbol DOM de XML	 * Retorna el nodo pero no lo agrega al arbol.	 * 	 * @return Element	 */	static public Node toXML(GraphColors gc) {		Node e = null;		Node root = new Node("GraphColors");		root.appendChild("background", formatColor(gc.background));		root.appendChild("text", formatColor(gc.text));		root.appendChild("titleFg", formatColor(gc.titleFg));		root.appendChild("titleBg", formatColor(gc.titleBg));		root.appendChild("div", formatColor(gc.div));		root.appendChild("mayorDiv", formatColor(gc.mayorDiv));		// root.appendChild("graph", formatColor(gc.graph) );		root.appendChild("weekEnd", formatColor(gc.weekEnd));		root.appendChild("holiday", formatColor(gc.holiday));		root.appendChild("now", formatColor(gc.now));		root.appendChild("horLine", formatColor(gc.horLine));		root.appendChild("snapshot", formatColor(gc.snapshot));		root				.appendChild("drawTaskLines", (gc.drawTaskLines ? "true"						: "false"));		root.appendChild("drawMinorLines", (gc.drawMinorLines ? "true"				: "false"));		root.appendChild(toXML(gc.defaultTaskColors, "TaskColors"));		root.appendChild(toXML(gc.defaultResumeColors, "ResumeColors"));		return root;	}	/**	 * Lee un GraphColors	 */	static public TaskColors readTaskColors(Node doc) throws ParseException,			GanttException {		TaskColors tc = new TaskColors();		tc.barBg = parseColor(getChildText(doc, "barBg"));		tc.barLine = parseColor(getChildText(doc, "barLine"));		tc.barCompleted = parseColor(getChildText(doc, "barCompleted"));		tc.text = parseColor(getChildText(doc, "text"));		tc.constraint = parseColor(getChildText(doc, "constraint"));		return tc;	}	/**	 * Generar una representacion de un TaskColors en un arbol DOM de XML	 * Retorna el nodo pero no lo agrega al arbol.	 * 	 * @return Element	 */	static public Node toXML(TaskColors tc, String elementName) {		Node e = null;		Node root = new Node(elementName);		root.appendChild("barBg", formatColor(tc.barBg));		root.appendChild("barLine", formatColor(tc.barLine));		root.appendChild("barCompleted", formatColor(tc.barCompleted));		root.appendChild("text", formatColor(tc.text));		root.appendChild("constraint", formatColor(tc.constraint));		return root;	}	/**	 * Generar una representacion de un TreeColors en un arbol DOM de XML	 * Retorna el nodo pero no lo agrega al arbol.	 * 	 * @return Element	 */	static public Node toXML(TaskTreeOptions ttc) {		Node e = null;		Node root = new Node("TreeColors");		root.appendChild("cellBg", formatColor(ttc.cellBg));		root.appendChild("cellBorder", formatColor(ttc.cellBorder));		root.appendChild("cellFontColor", formatColor(ttc.cellFontColor));		root.appendChild("focusBg", formatColor(ttc.focusBg));		root.appendChild("focusBorder", formatColor(ttc.focusBorder));		root.appendChild("headerBg", formatColor(ttc.headerBg));		root.appendChild("headerBorder", formatColor(ttc.headerBorder));		root.appendChild("headerFontColor", formatColor(ttc.headerFontColor));		root.appendChild("headerHeight", String.valueOf(ttc.headerHeight));		root.appendChild("rowHeight", String.valueOf(ttc.rowHeight));		// TODO: Soporte a los fonts		root.appendChild("cellFont", formatFont(ttc.cellFont));		root.appendChild("cellResumeFont", formatFont(ttc.cellResumeFont));		root.appendChild("headerFont", formatFont(ttc.headerFont));		if (ttc.columns.size() > 0) {			Node columns = new Node("Columns");			for (Iterator i = ttc.columns.iterator(); i.hasNext();) {				String element = (String) i.next();				columns.appendChild("column", element);			}			root.appendChild(columns);		}		return root;	}	/**	 * Lee datos en un TaskTreeColors	 */	static public void readTaskTreeColors(TaskTreeOptions ttc, Node doc)			throws ParseException, GanttException {		doc = getChildByName(doc, "TreeColors");		ttc.cellBg = parseColor(getChildText(doc, "cellBg"));		ttc.cellBorder = parseColor(getChildText(doc, "cellBorder"));		ttc.cellFontColor = parseColor(getChildText(doc, "cellFontColor"));		ttc.focusBg = parseColor(getChildText(doc, "focusBg"));		ttc.focusBorder = parseColor(getChildText(doc, "focusBorder"));		ttc.headerBg = parseColor(getChildText(doc, "headerBg"));		ttc.headerBorder = parseColor(getChildText(doc, "headerBorder"));		ttc.headerFontColor = parseColor(getChildText(doc, "headerFontColor"));		ttc.headerHeight = Integer.parseInt(getChildText(doc, "headerHeight"));		ttc.rowHeight = Integer.parseInt(getChildText(doc, "rowHeight"));		ttc.cellFont = parseFont(getChildText(doc, "cellFont"));		ttc.cellResumeFont = parseFont(getChildText(doc, "cellResumeFont"));		ttc.headerFont = parseFont(getChildText(doc, "headerFont"));		Node columns = getChildByName(doc, "Columns");		if (columns != null) {			ttc.columns = new Vector();			Node item = getChildByName(columns, "column");			while (item != null) {				if (!item.getNodeName().equals("column"))					break;				ttc.columns.add(item.getValue());				item = item.getNextSibling();			}		}	}	/**	 * Generar una representacion de un GraphColors en un arbol DOM de XML	 * Retorna el nodo pero no lo agrega al arbol.	 * 	 * @return Element	 */	static public Node toXML(ViewOptionsData vo) {		Node e = null;		Node root = new Node("ViewOptions");		root.appendChild("startDate", sdf.format(vo.startDate));		root.appendChild("majDivUnit", String.valueOf(vo.majDivUnit));		root.appendChild("majDivMult", String.valueOf(vo.majDivMult));		root.appendChild("majDivFormat", String.valueOf(vo.majDivFormat));		root.appendChild("minDivUnit", String.valueOf(vo.minDivUnit));		root.appendChild("minDivMult", String.valueOf(vo.minDivMult));		root.appendChild("minDivFormat", String.valueOf(vo.minDivFormat));		root.appendChild("divHeight", String.valueOf(vo.divHeight));		root.appendChild("headerHeight", String.valueOf(vo.headerHeight));		root.appendChild("startOffset", String.valueOf(vo.startOffset));		root.appendChild("stdDivWidth", String.valueOf(vo.stdDivWidth));		root.appendChild("divWidth", String.valueOf(vo.divWidth));		root.appendChild("taskHeight", String.valueOf(vo.taskHeight));		root.appendChild("taskBarHeight", String.valueOf(vo.taskBarHeight));		root.appendChild("barTextFormat", vo.barTextFormat);		root.appendChild("assignTextFormat", vo.assignTextFormat);		return root;	}	/**	 * Lee un GraphColors	 */	static public void readViewOptions(ViewOptionsData vo, Node doc)			throws ParseException, GanttException {		doc = getChildByName(doc, "ViewOptions");		vo.startDate = sdf.parse(getChildText(doc, "startDate"));		vo.majDivUnit = Byte.parseByte(getChildText(doc, "majDivUnit"));		vo.majDivMult = Byte.parseByte(getChildText(doc, "majDivMult"));		vo.majDivFormat = getChildText(doc, "majDivFormat");		vo.minDivUnit = Byte.parseByte(getChildText(doc, "minDivUnit"));		vo.minDivMult = Byte.parseByte(getChildText(doc, "minDivMult"));		vo.minDivFormat = Byte.parseByte(getChildText(doc, "minDivFormat"));		vo.divHeight = Byte.parseByte(getChildText(doc, "divHeight"));		vo.headerHeight = Byte.parseByte(getChildText(doc, "headerHeight"));		vo.startOffset = Byte.parseByte(getChildText(doc, "startOffset"));		vo.stdDivWidth = Byte.parseByte(getChildText(doc, "stdDivWidth"));		vo.divWidth = Byte.parseByte(getChildText(doc, "divWidth"));		vo.taskHeight = Byte.parseByte(getChildText(doc, "taskHeight"));		vo.taskBarHeight = Byte.parseByte(getChildText(doc, "taskBarHeight"));		String s = getChildText(doc, "barTextFormat");		if (s != null)			vo.barTextFormat = s;		s = getChildText(doc, "assignTextFormat");		if (s != null)			vo.assignTextFormat = s;	}	// =============================================================================	// Soporte a las operaciones de lectura	// =============================================================================	/**	 * Retorna la primera aparicion de un nodo hijo con el nombre indicado.	 * 	 * @param n	 *            Nodo desde el cual buscar	 * @param name	 *            nombre del hijo buscado (tag)	 */	static Node getChildByName(Node e, String name) {		for (Iterator i = e.getChildElements(); i.hasNext();) {			Node c = (Node) i.next();			if (name.equals(c.getNodeName())) {				return c;			}		}		return null;	}	/**	 * Retorna la primera aparicion de un nodo con el path indicado.	 * 	 * @param n	 *            Documento desde el cual buscar (raiz)	 * @param name	 *            path del nodo buscado con nodos separados por slash (/)	 */	static Node getElementByPath(Node doc, String path) {		StringTokenizer st = new StringTokenizer(path, "/");		Node n = doc;		while (st.hasMoreTokens()) {			String t = st.nextToken();			n = getChildByName(n, t);			if (n == null)				return null;		}		return n;	}	/**	 * Retorna la primera aparicion de un nodo con el path indicado.	 * 	 * @param n	 *            Documento desde el cual buscar (raiz)	 * @param name	 *            path del nodo buscado con nodos separados por slash (/)	 */	static String getElementText(Node doc, String path) {		Node n = getElementByPath(doc, path);		return n.getValue();	}	/**	 * Retorna la primera aparicion de un nodo con el path indicado.	 * 	 * @param n	 *            Documento desde el cual buscar (raiz)	 * @param name	 *            path del nodo buscado con nodos separados por slash (/)	 */	static Date getElementDate(Node doc, String path) throws ParseException {		return sdf.parse(getElementText(doc, path));	}	static String getChildText(Node doc, String name) {		Node n = getChildByName(doc, name);		if (n == null)			return null;		return n.getValue();	}//	static String getChildTextText(Node node, String name) {//		return node.getChildText(node.name);//	}	/**	 * El stream se cierra luego de leer el archivo.	 * 	 * @param is	 *            inputstream	 * @return	 * @throws ParserConfigurationException	 * @throws SAXException	 * @throws IOException	 */	static public Node readDocument(InputStream is) throws SAXException,			IOException {		DocumentParser dp = new DocumentParser();		dp.parse(is);		Node main = dp.getMainElement();		return dp.getMainElement();	}	static public void addChildText(Node root, String name, String value) {		root.appendChild(name, value);	}}

⌨️ 快捷键说明

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