|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.nbbuild; import java.io.*; import java.util.*; import org.w3c.dom.*; import org.xml.sax.InputSource; import org.apache.tools.ant.BuildException; /** This class represents module updates tracking * * @author akemr */ class ModuleTracking { private static final String ELEMENT_MODULE_TRACKING = "tracking"; // NOI18N private static final String ELEMENT_MODULE = "module"; // NOI18N private static final String ATTR_MODULE_NAME = "name"; // NOI18N private static final String ELEMENT_FILE = "file"; // NOI18N private static final String ATTR_FILE_NAME = "name"; // NOI18N private static final String ATTR_MODULE_PATH = "path"; // NOI18N /** Platform dependent file name separator */ private static final String FILE_SEPARATOR = System.getProperty ("file.separator"); /** The name of the file */ public static final String TRACKING_FILE = "module_tracking.xml"; // NOI18N private boolean pError = false; private File trackingFile = null; private String nbPath = null; private Tracking tracking = null; // for generating xml in build process public ModuleTracking(String nbPath) { this.nbPath = nbPath; File directory = new File( nbPath ); if (!directory.exists()) { directory.mkdirs(); } trackingFile = new File(directory, TRACKING_FILE); read(); } /* public Module addNewModule( String name ) { = new Tracking(); module.setName( name ); return module; }*/ public void putModule(String name, String path, String[] files) { Module module = tracking.getModule(name); if (module == null) { module = new Module(); module.setName(name); module.setPath(path); tracking.addModule(module); } module.putFiles( files ); } public Iterator getFilesForModule(String name) { Module module = tracking.getModule(name); if (module == null) return null; String[] files = new String[module.getFiles().size()]; return module.getFiles().iterator(); } void write( ) { Document document = XMLUtil.createDocument(ELEMENT_MODULE_TRACKING); Element e_module_tracking = document.getDocumentElement(); Iterator it2 = tracking.getModules().values().iterator(); while ( it2.hasNext() ) { Module mod = (Module)it2.next(); Element e_module = document.createElement(ELEMENT_MODULE); e_module.setAttribute(ATTR_MODULE_NAME, mod.getName()); e_module.setAttribute(ATTR_MODULE_PATH, mod.getPath()); e_module_tracking.appendChild( e_module ); Iterator it3 = mod.getFiles().iterator(); while ( it3.hasNext() ) { String file = (String)it3.next(); Element e_file = document.createElement(ELEMENT_FILE); e_file.setAttribute(ATTR_FILE_NAME, file); e_module.appendChild( e_file ); } } //document.getDocumentElement().normalize(); try { OutputStream os = new FileOutputStream(trackingFile); XMLUtil.write(document, os); os.close(); } catch (Exception e) { e.printStackTrace(); trackingFile.delete(); throw new BuildException("Could not write update tracking file", e); } } /** Scan through org.w3c.dom.Document document. */ private void read() { /** org.w3c.dom.Document document */ org.w3c.dom.Document document; if (trackingFile.exists()) { InputStream is; try { is = new FileInputStream( trackingFile ); InputSource xmlInputSource = new InputSource( is ); document = XMLUtil.parse( xmlInputSource, false, false, new ErrorCatcher(), null ); if (is != null) is.close(); } catch ( org.xml.sax.SAXException e ) { System.out.println("Bad module_tracking" ); // NOI18N e.printStackTrace(); return; } catch ( java.io.IOException e ) { System.out.println("Missing module_tracking" ); // NOI18N e.printStackTrace(); return; } org.w3c.dom.Element element = document.getDocumentElement(); if ((element != null) && element.getTagName().equals(ELEMENT_MODULE_TRACKING)) { scanElement_module_tracking(element); } } if (tracking == null) tracking = new Tracking(); } /** Scan through org.w3c.dom.Element named module. */ void scanElement_module_tracking(org.w3c.dom.Element element) { // |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.