Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / src / net / sf / openrocket / file / openrocket / savers / RocketComponentSaver.java
index 3cd29acb14de07113c8d0fb859b4dc47432e2d9f..a4892902afa73822e9eca0d46e8112ab131feea5 100644 (file)
@@ -3,21 +3,26 @@ package net.sf.openrocket.file.openrocket.savers;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Locale;
 
 import net.sf.openrocket.file.RocketSaver;
+import net.sf.openrocket.l10n.Translator;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Motor;
 import net.sf.openrocket.motor.ThrustCurveMotor;
+import net.sf.openrocket.preset.ComponentPreset;
 import net.sf.openrocket.rocketcomponent.ComponentAssembly;
 import net.sf.openrocket.rocketcomponent.MotorMount;
 import net.sf.openrocket.rocketcomponent.Rocket;
 import net.sf.openrocket.rocketcomponent.RocketComponent;
+import net.sf.openrocket.startup.Application;
 import net.sf.openrocket.util.BugException;
 import net.sf.openrocket.util.Color;
 import net.sf.openrocket.util.LineStyle;
 
 
 public class RocketComponentSaver {
+       private static final Translator trans = Application.getTranslator();
        
        protected RocketComponentSaver() {
                // Prevent instantiation from outside the package
@@ -26,7 +31,14 @@ public class RocketComponentSaver {
        protected void addParams(net.sf.openrocket.rocketcomponent.RocketComponent c, List<String> elements) {
                elements.add("<name>" + RocketSaver.escapeXML(c.getName()) + "</name>");
                
-
+               ComponentPreset preset = c.getPresetComponent();
+               if (preset != null) {
+                       elements.add("<preset type=\"" + preset.getType() +
+                                       "\" manufacturer=\"" + preset.getManufacturer().getSimpleName() +
+                                       "\" partno=\"" + preset.getPartNo() + "\" digest=\"" + preset.getDigest() + "\"/>");
+               }
+               
+               
                // Save color and line style if significant
                if (!(c instanceof Rocket || c instanceof ComponentAssembly)) {
                        Color color = c.getColor();
@@ -38,19 +50,19 @@ public class RocketComponentSaver {
                        LineStyle style = c.getLineStyle();
                        if (style != null) {
                                // Type names currently equivalent to the enum names except for case.
-                               elements.add("<linestyle>" + style.name().toLowerCase() + "</linestyle>");
+                               elements.add("<linestyle>" + style.name().toLowerCase(Locale.ENGLISH) + "</linestyle>");
                        }
                }
                
-
+               
                // Save position unless "AFTER"
                if (c.getRelativePosition() != RocketComponent.Position.AFTER) {
                        // The type names are currently equivalent to the enum names except for case.
-                       String type = c.getRelativePosition().name().toLowerCase();
+                       String type = c.getRelativePosition().name().toLowerCase(Locale.ENGLISH);
                        elements.add("<position type=\"" + type + "\">" + c.getPositionValue() + "</position>");
                }
                
-
+               
                // Overrides
                boolean overridden = false;
                if (c.isMassOverridden()) {
@@ -66,7 +78,7 @@ public class RocketComponentSaver {
                                        + "</overridesubcomponents>");
                }
                
-
+               
                // Comment
                if (c.getComment().length() > 0) {
                        elements.add("<comment>" + RocketSaver.escapeXML(c.getComment()) + "</comment>");
@@ -75,8 +87,8 @@ public class RocketComponentSaver {
        }
        
        
-
-
+       
+       
        protected final String materialParam(Material mat) {
                return materialParam("material", mat);
        }
@@ -99,7 +111,9 @@ public class RocketComponentSaver {
                        throw new BugException("Unknown material type: " + mat.getType());
                }
                
-               return str + " density=\"" + mat.getDensity() + "\">" + RocketSaver.escapeXML(mat.getName()) + "</" + tag + ">";
+               String baseName = trans.getBaseText("material", mat.getName());
+               
+               return str + " density=\"" + mat.getDensity() + "\">" + RocketSaver.escapeXML(baseName) + "</" + tag + ">";
        }
        
        
@@ -121,7 +135,7 @@ public class RocketComponentSaver {
                        
                        elements.add("  <motor configid=\"" + id + "\">");
                        if (motor.getMotorType() != Motor.Type.UNKNOWN) {
-                               elements.add("    <type>" + motor.getMotorType().name().toLowerCase() + "</type>");
+                               elements.add("    <type>" + motor.getMotorType().name().toLowerCase(Locale.ENGLISH) + "</type>");
                        }
                        if (motor instanceof ThrustCurveMotor) {
                                ThrustCurveMotor m = (ThrustCurveMotor) motor;
@@ -144,7 +158,7 @@ public class RocketComponentSaver {
                }
                
                elements.add("  <ignitionevent>"
-                               + mount.getIgnitionEvent().name().toLowerCase().replace("_", "")
+                               + mount.getIgnitionEvent().name().toLowerCase(Locale.ENGLISH).replace("_", "")
                                + "</ignitionevent>");
                
                elements.add("  <ignitiondelay>" + mount.getIgnitionDelay() + "</ignitiondelay>");