[Pixelle-commit] SF.net SVN: pixelle: [161] trunk/pixelle/src/com/mebigfatguy/pixelle/ AlgorithmArc
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-07-13 00:50:27
|
Revision: 161
http://pixelle.svn.sourceforge.net/pixelle/?rev=161&view=rev
Author: dbrosius
Date: 2008-07-12 17:50:36 -0700 (Sat, 12 Jul 2008)
Log Message:
-----------
write out the algo file
Modified Paths:
--------------
trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
Modified: trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java
===================================================================
--- trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-07-13 00:39:33 UTC (rev 160)
+++ trunk/pixelle/src/com/mebigfatguy/pixelle/AlgorithmArchiver.java 2008-07-13 00:50:36 UTC (rev 161)
@@ -20,10 +20,15 @@
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
@@ -132,6 +137,18 @@
}
public void save() {
+ OutputStream xmlOut = null;
+ try {
+ File pixelleDir = new File(System.getProperty("user.home"), PIXELLE);
+ pixelleDir.mkdirs();
+ File algoFile = new File(pixelleDir, ALGORITHMS_FILE);
+ xmlOut = new BufferedOutputStream(new FileOutputStream(algoFile));
+ writeAlgorithms(xmlOut, userAlgorithms);
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ Closer.close(xmlOut);
+ }
}
@@ -165,6 +182,37 @@
}
+ private void writeAlgorithms(OutputStream is, Map<String, Map<String, Map<PixelleComponent, String>>> algorithms) throws IOException {
+ PrintWriter pw = null;
+ try {
+ pw = new PrintWriter(new OutputStreamWriter(is));
+ pw.println("<algorithms 'http://pixelle.mebigfatguy.com/0.1.0'");
+ pw.println(" xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'");
+ pw.println(" xsi:schemaLocation='/com/mebigfatguy/pixelle/resources/algorithms.xsd'>");
+
+ for (Map.Entry<String, Map<String, Map<PixelleComponent, String>>> group : algorithms.entrySet()) {
+ pw.println(" <group name='" + group.getKey() + "'>");
+
+ for (Map.Entry<String, Map<PixelleComponent, String>> algorithm : group.getValue().entrySet()) {
+ pw.println(" <algorithm name'" + algorithm.getKey() + "'>");
+
+ for (Map.Entry<PixelleComponent, String> component : algorithm.getValue().entrySet()) {
+ pw.println(" <component name ='" + component.getKey().name().toLowerCase() + "'>");
+ pw.println(" " + component.getValue());
+ pw.println(" </component>");
+ }
+ pw.println(" </algorithm>");
+ }
+ pw.println(" </group>");
+ }
+ pw.println("</algorithms>");
+ pw.flush();
+ }
+ finally {
+ pw.close();
+ }
+ }
+
private void parseAlgorithms(InputStream is, Map<String, Map<String, Map<PixelleComponent, String>>> algorithms) throws IOException, SAXException {
XMLReader r = XMLReaderFactory.createXMLReader();
r.setContentHandler(new DefaultHandler() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|