diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 1831cfc67..7fa1270c9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -32,7 +32,6 @@ import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.modes.SoundExportMode; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; -import com.jpexs.decompiler.flash.helpers.ImageHelper; import com.jpexs.decompiler.flash.tags.CSMTextSettingsTag; import com.jpexs.decompiler.flash.tags.DefineButton2Tag; import com.jpexs.decompiler.flash.tags.DefineButtonCxformTag; @@ -112,11 +111,9 @@ import com.jpexs.helpers.SerializableImage; import com.jpexs.helpers.utf8.Utf8Helper; import java.awt.Font; import java.awt.Point; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.io.StringReader; import java.io.StringWriter; import java.util.ArrayList; @@ -134,6 +131,7 @@ import java.util.logging.Logger; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import javax.xml.parsers.SAXParserFactory; +import javax.xml.stream.XMLStreamException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; @@ -2258,7 +2256,7 @@ public class XFLConverter { if (ret2.length() > 0) { ret.append("" + "").append(ret2).append("" - + ""); + + ""); } } @@ -2474,9 +2472,11 @@ public class XFLConverter { } ret.append(antiAlias); if (((CharacterTag) tag).getCharacterId() == 650) { + // todo: remove System.err.println("=========================AAAAAAAAAAA"); } Map attrs = TextTag.getTextRecordsAttributes(textRecords, swf); + // todo: remove System.err.println("///////////============="); ret.append(" width=\"").append(tag.getBounds().getWidth() / 2).append("\" height=\"").append(tag.getBounds().getHeight()).append("\" autoExpand=\"true\" isSelectable=\"false\">"); ret.append(matStr); @@ -2826,237 +2826,259 @@ public class XFLConverter { int flaSwfVersion = swf.version > flaVersion.maxSwfVersion() ? flaVersion.maxSwfVersion() : swf.version; boolean greaterThanCC = flaVersion.ordinal() >= FLAVersion.CC.ordinal(); - StringBuilder publishSettings = new StringBuilder(); - publishSettings.append("\n"); - publishSettings.append("\n"); - publishSettings.append(" \n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(greaterThanCC ? " 0\n" : " 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(greaterThanCC ? " 1\n" : " 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" ").append(baseName).append(".swf\n"); - publishSettings.append(" ").append(baseName).append(".exe\n"); - publishSettings.append(" ").append(baseName).append(".app\n"); - publishSettings.append(" ").append(baseName).append(".html\n"); - publishSettings.append(" ").append(baseName).append(".gif\n"); - publishSettings.append(" ").append(baseName).append(".jpg\n"); - publishSettings.append(" ").append(baseName).append(".png\n"); - publishSettings.append(greaterThanCC ? " 1\n" : " 1\n"); - publishSettings.append(" ").append(baseName).append(".smil\n"); - publishSettings.append(" ").append(baseName).append(".swc\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 12,0,0,0;11,2,0,0;11,1,0,0;10,3,0,0;10,2,153,0;10,1,52,0;9,0,124,0;8,0,24,0;7,0,14,0;6,0,79,0;5,0,58,0;4,0,32,0;3,0,8,0;2,0,1,12;1,0,0,1;\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" ").append(baseName).append("_content.html\n"); - publishSettings.append(" ").append(baseName).append("_alternate.html\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" \n"); - publishSettings.append(" ").append(width).append("\n"); - publishSettings.append(" ").append(height).append("\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 4\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" \n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 80\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 7\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 7\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" ").append(flaSwfVersion).append("\n"); - publishSettings.append(" ").append(FLAVersion.swfVersionToPlayer(flaSwfVersion)).append("\n"); - publishSettings.append(" ").append(useAS3 ? "3" : "2").append("\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" .\n"); - publishSettings.append(" CONFIG::FLASH_AUTHORING="true";\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" \n"); - publishSettings.append(" ").append(swf.compression == SWFCompression.NONE ? "0" : "1").append("\n"); - publishSettings.append(" ").append(swf.compression == SWFCompression.LZMA ? "1" : "0").append("\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" ").append(useNetwork ? 1 : 0).append("\n"); - publishSettings.append(" ").append(Helper.escapeHTML(characterClasses.containsKey(0) ? characterClasses.get(0) : "")).append("\n"); - publishSettings.append(" 2\n"); - publishSettings.append(" 4\n"); - publishSettings.append(" 4096\n"); - publishSettings.append(" AS3\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 15\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 4102\n"); - publishSettings.append(" rsl\n"); - publishSettings.append(" wrap\n"); - publishSettings.append(" $(AppConfig)/ActionScript 3.0/rsls/loader_animation.swf\n"); - if (greaterThanCC) { - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(AppConfig)/ActionScript 3.0/libs\n"); - publishSettings.append(" merge\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(FlexSDK)/frameworks/libs/flex.swc\n"); - publishSettings.append(" merge\n"); - publishSettings.append(" textLayout_2.0.0.232.swz\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(FlexSDK)/frameworks/libs/core.swc\n"); - publishSettings.append(" merge\n"); - publishSettings.append(" textLayout_2.0.0.232.swz\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" "); - } else { - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(AppConfig)/ActionScript 3.0/libs\n"); - publishSettings.append(" merge\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(AppConfig)/ActionScript 3.0/libs/11.0/textLayout.swc\n"); - publishSettings.append(" rsl\n"); - publishSettings.append(" http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swz\n"); - publishSettings.append(" http://fpdownload.adobe.com/pub/swz/crossdomain.xml\n"); - publishSettings.append(" textLayout_2.0.0.232.swz\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" $(AppConfig)/ActionScript 3.0/libs/11.0/textLayout.swc\n"); - publishSettings.append(" \n"); - publishSettings.append(" http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swz\n"); - publishSettings.append(" http://fpdownload.adobe.com/pub/swz/crossdomain.xml\n"); - publishSettings.append(" textLayout_2.0.0.232.swz\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); + XFLXmlWriter psXml = new XFLXmlWriter(); + try { + psXml.writeStartElement("flash_profiles"); + psXml.writeStartElement("flash_profile", new String[]{"version", "1.0", "name", "Default", "current", "true"}); + + psXml.writeStartElement("PublishFormatProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("defaultNames", "1"); + psXml.writeElementValue("flash", "1"); + psXml.writeElementValue("projectorWin", "0"); + psXml.writeElementValue("projectorMac", "0"); + psXml.writeElementValue("html", "1"); + psXml.writeElementValue("gif", "0"); + psXml.writeElementValue("jpeg", "0"); + psXml.writeElementValue("png", "0"); + psXml.writeElementValue(greaterThanCC ? "svg" : "qt", "0"); + psXml.writeElementValue("rnwk", "0"); + psXml.writeElementValue("swc", "0"); + psXml.writeElementValue("flashDefaultName", "1"); + psXml.writeElementValue("projectorWinDefaultName", "1"); + psXml.writeElementValue("projectorMacDefaultName", "1"); + psXml.writeElementValue("htmlDefaultName", "1"); + psXml.writeElementValue("gifDefaultName", "1"); + psXml.writeElementValue("jpegDefaultName", "1"); + psXml.writeElementValue("pngDefaultName", "1"); + psXml.writeElementValue(greaterThanCC ? "svgDefaultName" : "qtDefaultName", "1"); + psXml.writeElementValue("rnwkDefaultName", "1"); + psXml.writeElementValue("swcDefaultName", "1"); + psXml.writeElementValue("flashFileName", baseName + ".swf"); + psXml.writeElementValue("projectorWinFileName", baseName + ".exe"); + psXml.writeElementValue("projectorMacFileName", baseName + ".app"); + psXml.writeElementValue("htmlFileName", baseName + ".html"); + psXml.writeElementValue("gifFileName", baseName + ".gif"); + psXml.writeElementValue("jpegFileName", baseName + ".jpg"); + psXml.writeElementValue("pngFileName", baseName + ".png"); + psXml.writeElementValue(greaterThanCC ? "svgFileName" : "qtFileName", "1"); + psXml.writeElementValue("rnwkFileName", baseName + ".smil"); + psXml.writeElementValue("swcFileName", baseName + ".swc"); + psXml.writeEndElement(); + + psXml.writeStartElement("PublishHtmlProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("VersionDetectionIfAvailable", "0"); + psXml.writeElementValue("VersionInfo", "12,0,0,0;11,2,0,0;11,1,0,0;10,3,0,0;10,2,153,0;10,1,52,0;9,0,124,0;8,0,24,0;7,0,14,0;6,0,79,0;5,0,58,0;4,0,32,0;3,0,8,0;2,0,1,12;1,0,0,1;"); + psXml.writeElementValue("UsingDefaultContentFilename", "1"); + psXml.writeElementValue("UsingDefaultAlternateFilename", "1"); + psXml.writeElementValue("ContentFilename", baseName + "_content.html"); + psXml.writeElementValue("AlternateFilename", baseName + "_alternate.html"); + psXml.writeElementValue("UsingOwnAlternateFile", "0"); + psXml.writeElementValue("OwnAlternateFilename", ""); + psXml.writeElementValue("Width", width); + psXml.writeElementValue("Height", height); + psXml.writeElementValue("Align", "0"); + psXml.writeElementValue("Units", "0"); + psXml.writeElementValue("Loop", "1"); + psXml.writeElementValue("StartPaused", "0"); + psXml.writeElementValue("Scale", "0"); + psXml.writeElementValue("HorizontalAlignment", "1"); + psXml.writeElementValue("VerticalAlignment", "1"); + psXml.writeElementValue("Quality", "4"); + psXml.writeElementValue("DeblockingFilter", "0"); + psXml.writeElementValue("WindowMode", "0"); + psXml.writeElementValue("DisplayMenu", "1"); + psXml.writeElementValue("DeviceFont", "0"); + psXml.writeElementValue("TemplateFileName", ""); + psXml.writeElementValue("showTagWarnMsg", "1"); + psXml.writeEndElement(); + + psXml.writeStartElement("PublishFlashProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("TopDown", ""); + psXml.writeElementValue("FireFox", ""); + psXml.writeElementValue("Report", "0"); + psXml.writeElementValue("Protect", "0"); + psXml.writeElementValue("OmitTraceActions", "0"); + psXml.writeElementValue("Quality", "80"); + psXml.writeElementValue("DeblockingFilter", "0"); + psXml.writeElementValue("StreamFormat", "0"); + psXml.writeElementValue("StreamCompress", "7"); + psXml.writeElementValue("EventFormat", "0"); + psXml.writeElementValue("EventCompress", "7"); + psXml.writeElementValue("OverrideSounds", "0"); + psXml.writeElementValue("Version", flaSwfVersion); + psXml.writeElementValue("ExternalPlayer", FLAVersion.swfVersionToPlayer(flaSwfVersion)); + psXml.writeElementValue("ActionScriptVersion", useAS3 ? "3" : "2"); + psXml.writeElementValue("PackageExportFrame", "1"); + psXml.writeElementValue("PackagePaths", ""); + psXml.writeElementValue("AS3PackagePaths", "."); + psXml.writeElementValue("AS3ConfigConst", "CONFIG::FLASH_AUTHORING=\"true\";"); + psXml.writeElementValue("DebuggingPermitted", "0"); + psXml.writeElementValue("DebuggingPassword", ""); + psXml.writeElementValue("CompressMovie", swf.compression == SWFCompression.NONE ? "0" : "1"); + psXml.writeElementValue("CompressionType", swf.compression == SWFCompression.LZMA ? "1" : "0"); + psXml.writeElementValue("InvisibleLayer", "1"); + psXml.writeElementValue("DeviceSound", "0"); + psXml.writeElementValue("StreamUse8kSampleRate", "0"); + psXml.writeElementValue("EventUse8kSampleRate", "0"); + psXml.writeElementValue("UseNetwork", useNetwork ? 1 : 0); + psXml.writeElementValue("DocumentClass", characterClasses.containsKey(0) ? characterClasses.get(0) : ""); + psXml.writeElementValue("AS3Strict", "2"); + psXml.writeElementValue("AS3Coach", "4"); + psXml.writeElementValue("AS3AutoDeclare", "4096"); + psXml.writeElementValue("AS3Dialect", "AS3"); + psXml.writeElementValue("AS3ExportFrame", "1"); + psXml.writeElementValue("AS3Optimize", "1"); + psXml.writeElementValue("ExportSwc", "0"); + psXml.writeElementValue("ScriptStuckDelay", "15"); + psXml.writeElementValue("IncludeXMP", "1"); + psXml.writeElementValue("HardwareAcceleration", "0"); + psXml.writeElementValue("AS3Flags", "4102"); + psXml.writeElementValue("DefaultLibraryLinkage", "rsl"); + psXml.writeElementValue("RSLPreloaderMethod", "wrap"); + psXml.writeElementValue("RSLPreloaderSWF", "$(AppConfig)/ActionScript 3.0/rsls/loader_animation.swf"); + if (greaterThanCC) { + psXml.writeStartElement("LibraryPath"); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(AppConfig)/ActionScript 3.0/libs"); + psXml.writeElementValue("linkage", "merge"); + psXml.writeEndElement(); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(FlexSDK)/frameworks/libs/flex.swc"); + psXml.writeElementValue("linkage", "merge"); + psXml.writeElementValue("rsl-url", "textLayout_2.0.0.232.swz"); + psXml.writeEndElement(); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(FlexSDK)/frameworks/libs/core.swc"); + psXml.writeElementValue("linkage", "merge"); + psXml.writeElementValue("rsl-url", "textLayout_2.0.0.232.swz"); + psXml.writeEndElement(); + psXml.writeEndElement(); + psXml.writeElementValueRaw("LibraryVersions", Helper.newLine + " "); // todo: is this really needed or an empty tag is ok? + psXml.writeEndElement(); + } else { + psXml.writeStartElement("LibraryPath"); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(AppConfig)/ActionScript 3.0/libs"); + psXml.writeElementValue("linkage", "merge"); + psXml.writeEndElement(); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(AppConfig)/ActionScript 3.0/libs/11.0/textLayout.swc"); + psXml.writeElementValue("linkage", "rsl", new String[]{"usesDefault", "true"}); + psXml.writeElementValue("rsl-url", "http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swz"); + psXml.writeElementValue("policy-file-url", "http://fpdownload.adobe.com/pub/swz/crossdomain.xml"); + psXml.writeElementValue("rsl-url", "textLayout_2.0.0.232.swz"); + psXml.writeEndElement(); + psXml.writeStartElement("library-path-entry"); + psXml.writeElementValue("swc-path", "$(FlexSDK)/frameworks/libs/core.swc"); + psXml.writeElementValue("linkage", "merge"); + psXml.writeElementValue("rsl-url", "textLayout_2.0.0.232.swz"); + psXml.writeEndElement(); + psXml.writeEndElement(); + psXml.writeEndElement(); + + psXml.writeStartElement("LibraryVersions"); + psXml.writeStartElement("library-version"); + psXml.writeElementValue("swc-path", "$(AppConfig)/ActionScript 3.0/libs/11.0/textLayout.swc"); + psXml.writeEmptyElement("feature", new String[]{"name", "tlfText", "majorVersion", "2", "minorVersion", "0", "build", "232"}); + psXml.writeElementValue("rsl-url", "http://fpdownload.adobe.com/pub/swz/tlf/2.0.0.232/textLayout_2.0.0.232.swz"); + psXml.writeElementValue("policy-file-url", "http://fpdownload.adobe.com/pub/swz/crossdomain.xml"); + psXml.writeElementValue("rsl-url", "textLayout_2.0.0.232.swz"); + psXml.writeEndElement(); + psXml.writeEndElement(); + } + + psXml.writeEndElement(); + + psXml.writeStartElement("PublishJpegProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("Width", width); + psXml.writeElementValue("Height", height); + psXml.writeElementValue("Progressive", "0"); + psXml.writeElementValue("DPI", "4718592"); + psXml.writeElementValue("Size", "0"); + psXml.writeElementValue("Quality", "80"); + psXml.writeElementValue("MatchMovieDim", "1"); + psXml.writeEndElement(); + + psXml.writeStartElement("PublishRNWKProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("exportFlash", "1"); + psXml.writeElementValue("flashBitRate", "0"); + psXml.writeElementValue("exportAudio", "1"); + psXml.writeElementValue("audioFormat", "0"); + psXml.writeElementValue("singleRateAudio", "0"); + psXml.writeElementValue("realVideoRate", "100000"); + psXml.writeElementValue("speed28K", "1"); + psXml.writeElementValue("speed56K", "1"); + psXml.writeElementValue("speedSingleISDN", "0"); + psXml.writeElementValue("speedDualISDN", "0"); + psXml.writeElementValue("speedCorporateLAN", "0"); + psXml.writeElementValue("speed256K", "0"); + psXml.writeElementValue("speed384K", "0"); + psXml.writeElementValue("speed512K", "0"); + psXml.writeElementValue("exportSMIL", "1"); + psXml.writeEndElement(); + + psXml.writeStartElement("PublishGifProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("Width", width); + psXml.writeElementValue("Height", height); + psXml.writeElementValue("Animated", "0"); + psXml.writeElementValue("MatchMovieDim", "1"); + psXml.writeElementValue("Loop", "1"); + psXml.writeElementValue("LoopCount", ""); + psXml.writeElementValue("OptimizeColors", "1"); + psXml.writeElementValue("Interlace", "0"); + psXml.writeElementValue("Smooth", "1"); + psXml.writeElementValue("DitherSolids", "0"); + psXml.writeElementValue("RemoveGradients", "0"); + psXml.writeElementValue("TransparentOption", ""); + psXml.writeElementValue("TransparentAlpha", "128"); + psXml.writeElementValue("DitherOption", ""); + psXml.writeElementValue("PaletteOption", ""); + psXml.writeElementValue("MaxColors", "255"); + psXml.writeElementValue("PaletteName", ""); + psXml.writeEndElement(); + + psXml.writeStartElement("PublishPNGProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("Width", width); + psXml.writeElementValue("Height", height); + psXml.writeElementValue("OptimizeColors", "1"); + psXml.writeElementValue("Interlace", "0"); + psXml.writeElementValue("Transparent", "0"); + psXml.writeElementValue("Smooth", "1"); + psXml.writeElementValue("DitherSolids", "0"); + psXml.writeElementValue("RemoveGradients", "0"); + psXml.writeElementValue("MatchMovieDim", "1"); + psXml.writeElementValue("DitherOption", ""); + psXml.writeElementValue("FilterOption", ""); + psXml.writeElementValue("PaletteOption", ""); + psXml.writeElementValue("BitDepth", "24-bit with Alpha"); + psXml.writeElementValue("MaxColors", "255"); + psXml.writeElementValue("PaletteName", ""); + psXml.writeEndElement(); + + if (!greaterThanCC) { + psXml.writeStartElement("PublishQTProperties", new String[]{"enabled", "true"}); + psXml.writeElementValue("Width", width); + psXml.writeElementValue("Height", height); + psXml.writeElementValue("MatchMovieDim", "1"); + psXml.writeElementValue("UseQTSoundCompression", "0"); + psXml.writeElementValue("AlphaOption", ""); + psXml.writeElementValue("LayerOption", ""); + psXml.writeElementValue("QTSndSettings", "00000000"); + psXml.writeElementValue("ControllerOption", "0"); + psXml.writeElementValue("Looping", "0"); + psXml.writeElementValue("PausedAtStart", "0"); + psXml.writeElementValue("PlayEveryFrame", "0"); + psXml.writeElementValue("Flatten", "1"); + psXml.writeEndElement(); + } + + psXml.writeEndElement(); + psXml.writeEndElement(); + } catch (XMLStreamException ex) { + Logger.getLogger(XFLConverter.class.getName()).log(Level.SEVERE, null, ex); } - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" ").append(width).append("\n"); - publishSettings.append(" ").append(height).append("\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 4718592\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 80\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 100000\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" ").append(width).append("\n"); - publishSettings.append(" ").append(height).append("\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" \n"); - publishSettings.append(" 128\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 255\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" ").append(width).append("\n"); - publishSettings.append(" ").append(height).append("\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 24-bit with Alpha\n"); - publishSettings.append(" 255\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - if (!greaterThanCC) { - publishSettings.append(" \n"); - publishSettings.append(" ").append(width).append("\n"); - publishSettings.append(" ").append(height).append("\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" \n"); - publishSettings.append(" \n"); - publishSettings.append(" 00000000\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 0\n"); - publishSettings.append(" 1\n"); - publishSettings.append(" \n"); - } - publishSettings.append("\n"); - publishSettings.append(""); - String publishSettingsStr = publishSettings.toString(); + + String publishSettingsStr = psXml.toString(); if (settings.compressed) { final String domDocumentF = domDocumentStr; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLXmlWriter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLXmlWriter.java new file mode 100644 index 000000000..049cacb59 --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/xfl/XFLXmlWriter.java @@ -0,0 +1,327 @@ +/* + * Copyright (C) 2010-2016 JPEXS, All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.xfl; + +import com.jpexs.helpers.Helper; +import java.util.HashMap; +import java.util.Map; +import java.util.Stack; +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +/** + * + * @author JPEXS + */ +public class XFLXmlWriter implements XMLStreamWriter { + + private boolean newLine = true; + + private boolean newLineNeeded = false; + + private boolean startElementClosed = true; + + private final StringBuilder sb = new StringBuilder(); + + private final Map namespaces = new HashMap<>(); + + private final Stack tagsStack = new Stack<>(); + + @Override + public String toString() { + return sb.toString(); + } + + private XFLXmlWriter append(char character) { + sb.append(character); + newLine = false; + return this; + } + + private XFLXmlWriter append(String text) { + sb.append(text); + newLine = false; + return this; + } + + private void makeNewLine() { + if (!newLine) { + sb.append(Helper.newLine); + newLine = true; + for (int i = 0; i < tagsStack.size(); i++) { + sb.append(" "); + } + } + } + + private void closeStartElement() { + if (!startElementClosed) { + append('>'); + startElementClosed = true; + } + } + + private void ensureStartElementOpen() throws XMLStreamException { + if (startElementClosed) { + throw new XMLStreamException("Attempted to write attribute out of the start element"); + } + } + + private void closeStartElementNewLine() { + closeStartElement(); + makeNewLine(); + } + + @Override + public void writeStartElement(String localName) throws XMLStreamException { + closeStartElementNewLine(); + append('<').append(localName); + tagsStack.add(localName); + startElementClosed = false; + newLineNeeded = false; + } + + public void writeStartElement(String localName, String[] attributes) throws XMLStreamException { + writeStartElement(localName); + if (attributes.length % 2 != 0) { + throw new XMLStreamException("Attribute count should be even"); + } + + for (int i = 0; i < attributes.length / 2; i++) { + writeAttribute(attributes[i * 2], attributes[i * 2 + 1]); + } + } + + @Override + public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException { + writeStartElementInternal(getPrefix(namespaceURI), localName, namespaceURI); + } + + @Override + public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { + setPrefix(prefix, namespaceURI); + writeStartElementInternal(prefix, localName, namespaceURI); + } + + private void writeStartElementInternal(String prefix, String localName, String namespaceURI) throws XMLStreamException { + closeStartElementNewLine(); + append('<').append(prefix).append(':').append(localName); + writeNamespace(prefix, namespaceURI); + tagsStack.add(localName); + startElementClosed = false; + newLineNeeded = false; + } + + @Override + public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException { + writeEmptyElementInternal(getPrefix(namespaceURI), localName, namespaceURI); + } + + @Override + public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException { + setPrefix(prefix, namespaceURI); + writeEmptyElementInternal(prefix, localName, namespaceURI); + } + + private void writeEmptyElementInternal(String prefix, String localName, String namespaceURI) throws XMLStreamException { + writeStartElement(prefix, localName, namespaceURI); + writeEndElement(); + } + + @Override + public void writeEmptyElement(String localName) throws XMLStreamException { + writeStartElement(localName); + writeEndElement(); + } + + public void writeEmptyElement(String localName, String[] attributes) throws XMLStreamException { + writeStartElement(localName, attributes); + writeEndElement(); + } + + @Override + public void writeEndElement() throws XMLStreamException { + String localName = tagsStack.pop(); + if (startElementClosed) { + if (newLineNeeded) { + makeNewLine(); + } + + append("'); + } else { + append(" />"); + startElementClosed = true; + } + + newLineNeeded = true; + } + + public void writeElementValue(String localName, String value) throws XMLStreamException { + writeStartElement(localName); + writeCharacters(value); + writeEndElement(); + } + + public void writeElementValue(String localName, double value) throws XMLStreamException { + writeElementValue(localName, Double.toString(value)); + } + + public void writeElementValue(String localName, int value) throws XMLStreamException { + writeElementValue(localName, Integer.toString(value)); + } + + public void writeElementValueRaw(String localName, String value) throws XMLStreamException { + writeStartElement(localName); + writeCharactersRaw(value); + writeEndElement(); + } + + public void writeElementValue(String localName, String value, String[] attributes) throws XMLStreamException { + writeStartElement(localName, attributes); + writeCharacters(value); + writeEndElement(); + } + + @Override + public void writeEndDocument() throws XMLStreamException { + } + + @Override + public void close() throws XMLStreamException { + } + + @Override + public void flush() throws XMLStreamException { + } + + @Override + public void writeAttribute(String localName, String value) throws XMLStreamException { + ensureStartElementOpen(); + append(' ').append(localName).append("=\"").append(Helper.escapeHTML(value)).append('"'); + } + + @Override + public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException { + setPrefix(prefix, namespaceURI); + writeAttributeInternal(prefix, localName, value); + } + + @Override + public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException { + writeAttributeInternal(getPrefix(namespaceURI), localName, value); + } + + private void writeAttributeInternal(String prefix, String localName, String value) throws XMLStreamException { + ensureStartElementOpen(); + append(' ').append(prefix).append(':').append(localName).append("=\"").append(Helper.escapeHTML(value)).append('"'); + } + + @Override + public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException { + writeAttribute("xmlns", null, prefix, namespaceURI); + } + + @Override + public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException { + } + + @Override + public void writeComment(String data) throws XMLStreamException { + closeStartElement(); + append(""); + } + + @Override + public void writeProcessingInstruction(String target) throws XMLStreamException { + } + + @Override + public void writeProcessingInstruction(String target, String data) throws XMLStreamException { + } + + @Override + public void writeCData(String data) throws XMLStreamException { + // todo: split when data cintains "]]>" + append(""); + } + + @Override + public void writeDTD(String dtd) throws XMLStreamException { + } + + @Override + public void writeEntityRef(String name) throws XMLStreamException { + } + + @Override + public void writeStartDocument() throws XMLStreamException { + } + + @Override + public void writeStartDocument(String version) throws XMLStreamException { + } + + @Override + public void writeStartDocument(String encoding, String version) throws XMLStreamException { + } + + @Override + public void writeCharacters(String text) throws XMLStreamException { + closeStartElement(); + append(Helper.escapeHTML(text)); + } + + public void writeCharactersRaw(String text) throws XMLStreamException { + closeStartElement(); + append(text); + } + + @Override + public void writeCharacters(char[] text, int start, int len) throws XMLStreamException { + writeCharacters(new String(text, start, len)); + } + + @Override + public String getPrefix(String uri) throws XMLStreamException { + String prefix = namespaces.get(uri); + return prefix; + } + + @Override + public void setPrefix(String prefix, String uri) throws XMLStreamException { + namespaces.put(prefix, prefix); + } + + @Override + public void setDefaultNamespace(String uri) throws XMLStreamException { + } + + @Override + public void setNamespaceContext(NamespaceContext context) throws XMLStreamException { + } + + @Override + public NamespaceContext getNamespaceContext() { + return null; + } + + @Override + public Object getProperty(String name) throws IllegalArgumentException { + return null; + } +}