Example usage for org.apache.commons.digester Digester push

List of usage examples for org.apache.commons.digester Digester push

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester push.

Prototype

public void push(String stackName, Object value) 

Source Link

Document

Pushes the given object onto the stack with the given name.

Usage

From source file:org.freecine.filmscan.Project.java

/**
 Get project object for given directory.
 <p>/*from  w  w  w .j ava2  s  .c  o m*/
 If dir is an existing directory with valid project.xml file in it, laod the 
 project and return it. If there is no project in the directory, return a 
 new empty project.
         
 @param dir Project directory
 @return The project in directory or new project if no project exists there
 */
static public Project getProject(File dir) {
    File projectFile = new File(dir, "project.xml");
    Project ret = null;
    if (projectFile.exists()) {
        Digester d = new Digester();
        d.push("prj_dir_stack", dir);
        d.addRuleSet(new ProjectRuleSet(""));
        try {
            ret = (Project) d.parse(projectFile);
        } catch (IOException e) {
            log.severe("IO error reading " + projectFile.getPath() + ": " + e.getMessage());
        } catch (SAXException e) {
            log.severe("Parse error reading " + projectFile.getPath() + ": " + e.getMessage());
        }
    } else {
        try {
            if (!dir.exists() && !dir.mkdirs()) {
                log.warning("Cannot crete project directory");
                return null;
            }
            ret = new Project(dir);
            ret.save();
        } catch (IOException ex) {
            return null;
        }
    }
    return ret;
}

From source file:org.freecine.filmscan.TestProject.java

@Test
public void testProjectSaveLoad() throws IOException, SAXException {
    File prjdir = File.createTempFile("projectest", "");
    prjdir.delete();/*from w  w  w .jav a2 s  .  co m*/
    prjdir.mkdir();
    Project prj = new Project(prjdir);
    ScanStrip sc1 = new ScanStrip();
    ScanStrip sc2 = new ScanStrip();
    for (int n = 0; n < 30; n++) {
        sc1.addPerforation(100, n * 800);
        sc2.addPerforation(100, n * 800);
    }
    prj.addScanStrip(sc1);
    prj.addScanStrip(sc2);

    prj.save();

    // try to load the project

    Digester d = new Digester();
    d.addRuleSet(new ProjectRuleSet(""));
    d.push("prj_dir_stack", prjdir);
    Project prj2 = (Project) d.parse(new File(prjdir, "project.xml"));
    assertEquals(prjdir, prj2.getProjectDir());

}