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

📄 append.java

📁 eclipse平台的CDT项目3.0版本的源代码
💻 JAVA
字号:
//Title:        Curriculum Development Tool
//Copyright:    Copyright (c) 2001
//Author:       Brad Schaefer - schaefer@medstat.med.utah.edu
//Company:      Knowledge Weavers - http://medstat.med.utah.edu/kw/
//File:         projects/tree/nodes/Append.java
//Description:  A Node in a project tree that appends a file to its parent

package cdt.projects.tree.nodes;

import cdt.projects.Project;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

/**
 * A {@link cdt.projects.tree.nodes.Node Node} in a project tree that
 * appends the contents of a file into its parent.  This Node type is
 * NOT visible in the project tree, and is actually eliminated once the
 * parent node is selected (as the append contents are then put into
 * the parent node, making this node unnecessary).
 *
 * @version 1.0
 * @author Brad Schaefer (<A HREF="mailto:schaefer@medstat.med.utah.edu">schaefer@medstat.med.utah.edu</A>)
 */
public class Append extends Node {

	/**
	 * Create a hold.
	 *
	 * @param fn The filename of the file to append to the parent node.
	 */
	public Append(String fn) {
		this(fn, null);
	}

	/**
	 * Creates an append node.
	 *
	 * @param fn The filename of the file to append to the parent node.
	 * @param parent parent of this hold.
	 */
	public Append(String fn, Node parent) {
		setName(fn);
		setFile(fn);
		setParent(parent);
	}


	/**
	 * Returns the data in the file being appended, or an empty String if
	 * no file can be found.  The only place that this node will get its
	 * data from is the default project datafiles.
     *
     * @return The String contents of the append file.
	 */
	public String getData() {
		StringBuffer ret = new StringBuffer();
		String dataFile = Project.currentProject.getTemplateFilename();
		try {
			ZipFile zip = new ZipFile(dataFile);
			ZipEntry ze = zip.getEntry(this.getFile());
			if(null == ze) { throw new IOException("Cannot find file: " +this.getFile()); }
			InputStream in = zip.getInputStream(ze);
			byte data[] = new byte[1000];
			int numBytes;
			while( (numBytes = in.read(data)) != -1) {
				ret.append(new String(data, 0, numBytes));
			}
			in.close();
			zip.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ret.toString().trim();
	}

	/**
	 * We never want to modify the file(s) being appended, so this does nothing.
	 *
	 * @param s not used.
	 */
	public void setData(String s) { }

	/**
	 * Adds a node to the children in this node.
	 *
	 * @param into node to add.
	 */
	public void addNodeInto(Node into) { }

	/**
	 * deletes this node.
	 */
	public void removeNode() {
		LinkedList list = getSiblings();
		list.remove(this);
	}

	/**
	 * makes a copy of this node.
	 *
	 * @return copy of this node.
	 */
	public Node copy() {
		Node n = new Append(this.getName());
		n.setFile(this.getFile());
		return n;
	}

	/**
	 * Appends are never visible.
	 *
	 * @return false.
	 */
    public boolean isVisible() {
        return false;
    }

    /**
	 * Writes the project data to an OutputStream.
	 *
	 * @param out OutputStream to send project data to.
	 * @param dir Indicates the directory of the file this {@link cdt.projects.tree.nodes.Node Node} represents.
	 */
	public void writeProject(OutputStream out, String dir) {
/*		try {
			if(getFile().indexOf(" file=") != -1) {
				System.out.println(getName() +" has an incorrect filename '" +getFile()+ "'");
			}
			out.write((new String("<menu name=\"" +getName()+ "\" file=\"" +getFile()+ "\">\n")).getBytes());
			Iterator iter = children.iterator();
			while(iter.hasNext()) {
				Node n = (Node)iter.next();
				n.writeProject(out, dir+getFile()+(File.separatorChar));
			}
			out.write((new String("</menu>\n")).getBytes());
		} catch(Exception e) {
			cdt.ErrorD.ErrorDlg.ErrorMsg("Error writing project -> " +dir+getFile());
		} */
	}

	/**
	 * This node cannot have children.
	 *
	 * @return false.
	 */
	public boolean getAllowsChildren() {
		return false;
	}

	/**
	 * a node has been dropped into this one so add it as a child.
	 *
	 * @param n node to add.
	 */
	public void dropInto(Node n) {
		addNodeInto(n.copy());
	}
}

⌨️ 快捷键说明

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