X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FFrameworkWizard%2Fsrc%2Forg%2Ftianocore%2Fframeworkwizard%2Fplatform%2Fui%2FFpdFileContents.java;h=26d3d694c952860db0552209be4884e74d9ad846;hp=08992048085fe0cddb7047b5108162228ba42519;hb=a0783edc77ae576d8032461935362f43293bc467;hpb=607ef9948b4a6be7eb16c1df25c954ed0102a6e6 diff --git a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java index 0899204808..26d3d694c9 100644 --- a/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java +++ b/Tools/Source/FrameworkWizard/src/org/tianocore/frameworkwizard/platform/ui/FpdFileContents.java @@ -70,6 +70,7 @@ import org.tianocore.frameworkwizard.packaging.PackageIdentification; public class FpdFileContents { static final String xmlNs = "http://www.TianoCore.org/2006/Edk2.0"; + static final String regExpNewLineAndSpaces = "((\n)|(\r\n)|(\r)|(\u0085)|(\u2028)|(\u2029))(\\s)*"; private PlatformSurfaceAreaDocument fpdd = null; @@ -91,6 +92,11 @@ public class FpdFileContents { private HashMap defaultPcdValue = new HashMap(); + private String itemType (String pcdInfo) { + + return pcdInfo.substring(pcdInfo.lastIndexOf(" ") + 1); + } + /** * look through all pcd data in all ModuleSA, create pcd -> ModuleSA mappings. */ @@ -184,7 +190,7 @@ public class FpdFileContents { return fpdFrameworkModules; } - public void getFrameworkModuleGuid (String fvName, Vector vGuid) { + public void getFrameworkModuleSAByFvBinding (String fvName, Vector vGuid) { if (getFrameworkModulesCount() == 0){ return; } @@ -202,8 +208,15 @@ public class FpdFileContents { String[] fvNames = fvBinding.split(" "); for (int i = 0; i < fvNames.length; ++i) { + // + // BugBug : underscore "_" should not be replaced!!! + // But Fv name FVMAIN from fdf file not consist with FV_MAIN in fpd file. + // if (fvNames[i].equals(fvName) || fvNames[i].replaceAll("_", "").equals(fvName)) { - vGuid.add(moduleSa.getModuleGuid()); + String[] sa = new String[] {moduleSa.getModuleGuid(), moduleSa.getModuleVersion(), + moduleSa.getPackageGuid(), moduleSa.getPackageVersion(), + listToString(moduleSa.getSupArchList())}; + vGuid.add(sa); break; } } @@ -251,12 +264,22 @@ public class FpdFileContents { } public ModuleSADocument.ModuleSA getModuleSA(String key) { - String[] s = key.split(" "); + if (getfpdFrameworkModules().getModuleSAList() == null || getfpdFrameworkModules().getModuleSAList().size() == 0) { removeElement(getfpdFrameworkModules()); fpdFrameworkModules = null; return null; } + String[] s = key.split(" "); + String archsInKey = ""; + if (s.length > 4) { + for (int i = 4; i < s.length; ++i) { + archsInKey += s[i]; + archsInKey += " "; + } + archsInKey = archsInKey.trim(); + } + ListIterator li = getfpdFrameworkModules().getModuleSAList().listIterator(); while(li.hasNext()) { ModuleSADocument.ModuleSA moduleSa = (ModuleSADocument.ModuleSA)li.next(); @@ -271,13 +294,17 @@ public class FpdFileContents { continue; } } - //ToDo add arch check for s[4] + //ToDo add arch check . if (moduleSa.getSupArchList() != null) { - if (!listToString(moduleSa.getSupArchList()).equals(s[4])) { - continue; + if (listToString(moduleSa.getSupArchList()).equals(archsInKey)) { + return moduleSa; + } + } + else { + if (archsInKey.length() == 0) { + return moduleSa; } } - return moduleSa; } } return null; @@ -326,10 +353,21 @@ public class FpdFileContents { } cursor.push(); - cursor.toPrevToken(); + while (cursor.hasPrevToken()) { + cursor.toPrevToken(); + if (!cursor.isText()) { + break; + } + String s = cursor.getTextValue(); + if (s.matches(regExpNewLineAndSpaces)) { + continue; + } + } + if (cursor.isComment()) { cursor.removeXml(); } + cursor.pop(); cursor.removeXml(); if (getFrameworkModulesCount() == 0) { @@ -370,7 +408,6 @@ public class FpdFileContents { vMi.add(libMi); } - try { nextPcd:for (int i = 0; i < saaModuleSaPcd.length; ++i) { for (int j = 0; j < vMi.size(); ++j) { @@ -382,16 +419,10 @@ public class FpdFileContents { removePcdData(seqModuleSa, saaModuleSaPcd[i][0], saaModuleSaPcd[i][1]); dataModified = true; } - } - catch (Exception e) { - throw e; - } // // add new Pcd from MSA file to ModuleSA. // - try { - - for (int i = 0; i < vMi.size(); ++i) { + for (int i = 0; i < vMi.size(); ++i) { ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea) WorkspaceProfile .getModuleXmlObject(vMi .get(i)); @@ -431,10 +462,6 @@ public class FpdFileContents { } } - } - catch (Exception e){ - throw e; - } return dataModified; } @@ -543,6 +570,9 @@ public class FpdFileContents { do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData)cursor.getObject(); if (pcdData.getCName().equals(cName) && pcdData.getTokenSpaceGuidCName().equals(tsGuid)) { + // + // change item type while not updating dynPcdData???? + // pcdData.setItemType(PcdItemTypes.Enum.forString(itemType)); if(pcdData.getDatumType().equals("VOID*")) { pcdData.setMaxDatumSize(new Integer(maxSize)); @@ -600,6 +630,7 @@ public class FpdFileContents { // sa[0] = spdPcd.getHelpText() + msaPcd.getHelpText(); sa[1] = msaPcd.getPcdItemType()+""; + sa[2] = msa.getModuleDefinitions().getBinaryModule()+""; return true; } @@ -613,12 +644,44 @@ public class FpdFileContents { return false; } + private boolean multiSourcePcd (String cName, String tsGuidCName, String moduleKey) { + int libCount = getLibraryInstancesCount(moduleKey); + String[][] saaLib = new String[libCount][5]; + getLibraryInstances(moduleKey, saaLib); + ModuleIdentification mi = WorkspaceProfile.getModuleId(moduleKey); + Vector vMi = new Vector(); + // + // create vector for module & library instance MIs. + // + vMi.add(mi); + for (int j = 0; j < saaLib.length; ++j) { + String libKey = saaLib[j][1] + " " + saaLib[j][2] + " " + saaLib[j][3] + " " + saaLib[j][4]; + ModuleIdentification libMi = WorkspaceProfile.getModuleId(libKey); + vMi.add(libMi); + } + + int pcdSourceCount = 0; + for (int i = 0; i < vMi.size(); ++i) { + if (WorkspaceProfile.pcdInMsa(cName, tsGuidCName, vMi.get(i))) { + pcdSourceCount++; + } + } + + if (pcdSourceCount < 2) { + return false; + } + else { + return true; + } + + } + /**Remove PCDBuildDefinition entries from ModuleSA * @param moduleKey identifier of ModuleSA. * @param consumer where these entries come from. */ public void removePcdData(String moduleKey, ModuleIdentification consumer) { - try { + ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = (ModuleSurfaceAreaDocument.ModuleSurfaceArea)WorkspaceProfile.getModuleXmlObject(consumer); if (msa.getPcdCoded() == null) { return; @@ -632,12 +695,15 @@ public class FpdFileContents { ModuleSADocument.ModuleSA moduleSA = getModuleSA(moduleKey); if (moduleSA.getPcdBuildDefinition() != null) { XmlCursor cursor = moduleSA.getPcdBuildDefinition().newCursor(); + cursor.push(); if (cursor.toFirstChild()) { do { PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData pcdData = (PcdBuildDefinitionDocument.PcdBuildDefinition.PcdData) cursor .getObject(); - if (msaPcd.getCName().equals(pcdData.getCName()) - && msaPcd.getTokenSpaceGuidCName().equals(pcdData.getTokenSpaceGuidCName())) { + String cName = msaPcd.getCName(); + String tsGuidCName = msaPcd.getTokenSpaceGuidCName(); + if (cName.equals(pcdData.getCName()) + && tsGuidCName.equals(pcdData.getTokenSpaceGuidCName()) && !multiSourcePcd(cName, tsGuidCName, moduleKey)) { maintainDynPcdMap(pcdData.getCName() + " " + pcdData.getTokenSpaceGuidCName(), moduleKey); @@ -646,15 +712,15 @@ public class FpdFileContents { } } while (cursor.toNextSibling()); } + + cursor.pop(); + if (moduleSA.getPcdBuildDefinition().getPcdDataList().size() == 0) { + cursor.removeXml(); + } cursor.dispose(); } } - - } - catch (Exception e){ - e.printStackTrace(); - - } + } // // key for ModuleSA : "ModuleGuid ModuleVer PackageGuid PackageVer Arch" @@ -695,7 +761,17 @@ public class FpdFileContents { cursor.toNextSibling(); } cursor.push(); - cursor.toPrevToken(); + while (cursor.hasPrevToken()) { + cursor.toPrevToken(); + if (!cursor.isText()) { + break; + } + String s = cursor.getTextValue(); + if (s.matches(regExpNewLineAndSpaces)) { + continue; + } + } + if (cursor.isComment()) { cursor.removeXml(); } @@ -895,14 +971,9 @@ public class FpdFileContents { setFvBinding (moduleSa, newFvNameList.trim()); } - public void updateFvBindingInModuleSA (ModuleIdentification mi, String fvName) { - Vector vSupArchs = new Vector(); - getPlatformDefsSupportedArchs(vSupArchs); - String moduleInfo = mi.getGuid() + " " + mi.getVersion() + " " + mi.getPackageId().getGuid() + " " + mi.getPackageId().getVersion(); - for (int i = 0; i < vSupArchs.size(); ++i) { - String moduleKey = moduleInfo + " " + vSupArchs.get(i); - appendFvBinding (moduleKey, fvName); - } + public void updateFvBindingInModuleSA (String moduleKey, String fvName) { + + appendFvBinding (moduleKey, fvName); } public String getFfsFileNameGuid(String moduleKey){ @@ -1176,15 +1247,24 @@ public class FpdFileContents { pcdConsumer = new ArrayList(); } // + // Check whether this PCD has already added to ModuleSA, if so, just return. + // + String moduleInfo = moduleSa.getModuleGuid().toLowerCase() + " " + moduleSa.getModuleVersion() + + " " + moduleSa.getPackageGuid().toLowerCase() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()); + for (int i = 0; i < pcdConsumer.size(); ++i) { + String pcdInfo = pcdConsumer.get(i); + if (moduleInfo.equals(pcdInfo.substring(0, pcdInfo.lastIndexOf(" ")))){ + return; + } + } + // // Using existing Pcd type, if this pcd already exists in other ModuleSA // if (pcdConsumer.size() > 0) { - String[] valPart = pcdConsumer.get(0).split(" "); - itemType = valPart[5]; + + itemType = itemType (pcdConsumer.get(0)); } - String listValue = moduleSa.getModuleGuid() + " " + moduleSa.getModuleVersion() - + " " + moduleSa.getPackageGuid() + " " + moduleSa.getPackageVersion() + " " + listToString(moduleSa.getSupArchList()) - + " " + itemType; + String listValue = moduleInfo + " " + itemType; pcdConsumer.add(listValue); dynPcdMap.put(cName + " " + tsGuid, pcdConsumer); @@ -1681,7 +1761,15 @@ public class FpdFileContents { for (int i = 0; i < includeModules.size(); ++i) { cursor.beginElement(elementModule); cursor.insertAttributeWithValue("ModuleGuid", includeModules.get(i)[0]); - cursor.insertAttributeWithValue("BaseName", includeModules.get(i)[1]); + if (!includeModules.get(i)[1].equals("null") && includeModules.get(i)[1].length() != 0) { + cursor.insertAttributeWithValue("ModuleVersion", includeModules.get(i)[1]); + } + cursor.insertAttributeWithValue("PackageGuid", includeModules.get(i)[2]); + if (!includeModules.get(i)[3].equals("null") && includeModules.get(i)[3].length() != 0) { + cursor.insertAttributeWithValue("PackageVersion", includeModules.get(i)[3]); + } + + cursor.insertAttributeWithValue("Arch", includeModules.get(i)[4]); cursor.toEndToken(); cursor.toNextToken(); } @@ -1729,7 +1817,10 @@ public class FpdFileContents { QName elementFvName = new QName (xmlNs, "FvName"); QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); QName attribModuleGuid = new QName("ModuleGuid"); - QName attribBaseName = new QName("BaseName"); + QName attribModuleVersion = new QName("ModuleVersion"); + QName attribPackageGuid = new QName("PackageGuid"); + QName attribPackageVersion = new QName("PackageVersion"); + QName attribArch = new QName("Arch"); if (cursor.toChild(elementUserExts)) { do { @@ -1743,7 +1834,10 @@ public class FpdFileContents { int i = 0; do { saa[i][0] = cursor.getAttributeText(attribModuleGuid); - saa[i][1] = cursor.getAttributeText(attribBaseName); + saa[i][1] = cursor.getAttributeText(attribModuleVersion); + saa[i][2] = cursor.getAttributeText(attribPackageGuid); + saa[i][3] = cursor.getAttributeText(attribPackageVersion); + saa[i][4] = cursor.getAttributeText(attribArch); ++i; }while (cursor.toNextSibling()); } @@ -1803,6 +1897,138 @@ public class FpdFileContents { } + private boolean versionEqual (String v1, String v2) { + + if ((v1 == null || v1.length() == 0 || v1.equalsIgnoreCase("null")) + && (v2 == null || v2.length() == 0 || v2.equalsIgnoreCase("null"))) { + return true; + } + + if (v1 != null && v1.equals(v2)) { + return true; + } + + return false; + } + + public boolean moduleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { + boolean inList = false; + if (getUserExtsIncModCount(fvName) > 0) { + + XmlCursor cursor = getfpdBuildOpts().newCursor(); + QName elementUserExts = new QName (xmlNs, "UserExtensions"); + QName attribUserId = new QName ("UserID"); + QName elementFvName = new QName (xmlNs, "FvName"); + QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); + QName attribModuleGuid = new QName("ModuleGuid"); + QName attribModuleVersion = new QName("ModuleVersion"); + QName attribPackageGuid = new QName("PackageGuid"); + QName attribPackageVersion = new QName("PackageVersion"); + QName attribArch = new QName("Arch"); + + if (cursor.toChild(elementUserExts)) { + do { + cursor.push(); + if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + cursor.toChild(elementFvName); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toNextSibling(elementIncludeModules); + if (cursor.toFirstChild()) { + + do { + String mg = cursor.getAttributeText(attribModuleGuid); + String mv = cursor.getAttributeText(attribModuleVersion); + String pg = cursor.getAttributeText(attribPackageGuid); + String pv = cursor.getAttributeText(attribPackageVersion); + String ar = cursor.getAttributeText(attribArch); + if (!moduleGuid.equalsIgnoreCase(mg)) { + continue; + } + if (!packageGuid.equalsIgnoreCase(pg)) { + continue; + } + if (!arch.equalsIgnoreCase(ar)) { + continue; + } + if (!versionEqual(moduleVersion, mv)) { + continue; + } + if (!versionEqual(packageVersion, pv)) { + continue; + } + inList = true; + break; + }while (cursor.toNextSibling()); + } + break; + } + } + cursor.pop(); + }while (cursor.toNextSibling(elementUserExts)); + } + cursor.dispose(); + } + return inList; + } + + public void removeModuleInBuildOptionsUserExtensions (String fvName, String moduleGuid, String moduleVersion, String packageGuid, String packageVersion, String arch) { + if (getUserExtsIncModCount(fvName) > 0) { + + XmlCursor cursor = getfpdBuildOpts().newCursor(); + QName elementUserExts = new QName (xmlNs, "UserExtensions"); + QName attribUserId = new QName ("UserID"); + QName elementFvName = new QName (xmlNs, "FvName"); + QName elementIncludeModules = new QName(xmlNs, "IncludeModules"); + QName attribModuleGuid = new QName("ModuleGuid"); + QName attribModuleVersion = new QName("ModuleVersion"); + QName attribPackageGuid = new QName("PackageGuid"); + QName attribPackageVersion = new QName("PackageVersion"); + QName attribArch = new QName("Arch"); + + if (cursor.toChild(elementUserExts)) { + do { + cursor.push(); + if (cursor.getAttributeText(attribUserId).equals("IMAGES")) { + cursor.toChild(elementFvName); + String elementName = cursor.getTextValue(); + if (elementName.equals(fvName)) { + cursor.toNextSibling(elementIncludeModules); + if (cursor.toFirstChild()) { + + do { + String mg = cursor.getAttributeText(attribModuleGuid); + String mv = cursor.getAttributeText(attribModuleVersion); + String pg = cursor.getAttributeText(attribPackageGuid); + String pv = cursor.getAttributeText(attribPackageVersion); + String ar = cursor.getAttributeText(attribArch); + if (!moduleGuid.equalsIgnoreCase(mg)) { + continue; + } + if (!packageGuid.equalsIgnoreCase(pg)) { + continue; + } + if (!arch.equalsIgnoreCase(ar)) { + continue; + } + if (!versionEqual(moduleVersion, mv)) { + continue; + } + if (!versionEqual(packageVersion, pv)) { + continue; + } + cursor.removeXml(); + }while (cursor.toNextSibling()); + } + break; + } + } + cursor.pop(); + }while (cursor.toNextSibling(elementUserExts)); + } + cursor.dispose(); + } + } public void genBuildOptionsUserDefAntTask (String id, String fileName, String execOrder) { UserDefinedAntTasksDocument.UserDefinedAntTasks udats = getfpdBuildOpts().getUserDefinedAntTasks(); @@ -2608,7 +2834,7 @@ public class FpdFileContents { } } - public void AddFvImageFvImageNames (String[] fvNames) { + public void addFvImageFvImageNames (String[] fvNames) { FvImagesDocument.FvImages fis = getfpdFlash().getFvImages(); if (fis == null || fis.getFvImageList() == null) { genFvImagesFvImage (fvNames, "ImageName", null); @@ -2619,14 +2845,35 @@ public class FpdFileContents { while (li.hasNext()) { FvImagesDocument.FvImages.FvImage fi = li.next(); if (fi.getType().toString().equals("ImageName")) { - for (int i = 0; i < fvNames.length; ++i) { - fi.addFvImageNames(fvNames[i]); - } + addFvImageNamesInFvImage (fi, fvNames); return; } } - genFvImagesFvImage (fvNames, "ImageName", null); + genFvImagesFvImage (fvNames, "ImageName", null); + } + + public void addFvImageNamesInFvImage (FvImagesDocument.FvImages.FvImage fi, String[] fvNames) { + for (int i = 0; i < fvNames.length; ++i) { + fi.addFvImageNames(fvNames[i]); + } + } + + public void addFvImageNamesInFvImage (int i, String[] fvNames) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + addFvImageNamesInFvImage(fi, fvNames); + } + cursor.dispose(); } public void genFvImagesFvImage(String[] names, String types, Map options) { @@ -2706,6 +2953,22 @@ public class FpdFileContents { } } + public void updateFvImageNamesInFvImage (int i, String oldFvName, String newFvName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + updateFvImageNamesInFvImage (fi, oldFvName, newFvName); + } + cursor.dispose(); + } /** * @param fi * @param oldFvName The FV Name to be replaced. @@ -2723,7 +2986,7 @@ public class FpdFileContents { cursor.setTextValue(newFvName); } else { - cursor.removeXml(); + cursor.removeXml(); } } }while (cursor.toNextSibling(qFvImageNames)); @@ -2732,6 +2995,27 @@ public class FpdFileContents { cursor.dispose(); } + /**update the Type attribute of ith FvImage with new type. + * @param i + * @param type + */ + public void updateFvImagesFvImageType (int i, String type) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + fi.setType(FvImageTypes.Enum.forString(type)); + } + cursor.dispose(); + } + public void updateFvImagesFvImage(int i, String[] names, String types, Map options){ XmlObject o = getfpdFlash().getFvImages(); @@ -2849,19 +3133,43 @@ public class FpdFileContents { } } + public void removeFvImageNameValue (int i, String attributeName) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + removeFvImageNameValue (fi, attributeName); + } + cursor.dispose(); + } + /**Remove from fi the attribute pair with attributeName in FvImageOptions. + * @param fi + * @param attributeName + */ + public void removeFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String attributeName) { + if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) { + ListIterator li = fi.getFvImageOptions().getNameValueList().listIterator(); + while (li.hasNext()) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next(); + if (nv.getName().equals(attributeName)) { + li.remove(); + } + } + } + } + public void removeTypedNamedFvImageNameValue (String fvName, String type, String optName) { Vector vFvImage = getFvImagesFvImageWithName(fvName, type); for (int i = 0; i < vFvImage.size(); ++i) { FvImagesDocument.FvImages.FvImage fi = vFvImage.get(i); - if (fi.getFvImageOptions() != null && fi.getFvImageOptions().getNameValueList() != null) { - ListIterator li = fi.getFvImageOptions().getNameValueList().listIterator(); - while (li.hasNext()) { - FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = li.next(); - if (nv.getName().equals(optName)) { - li.remove(); - } - } - } + removeFvImageNameValue (fi, optName); } } @@ -2924,6 +3232,23 @@ public class FpdFileContents { } + public void setFvImagesFvImageNameValue (int i, String name, String value) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return; + } + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + for (int j = 0; j < i; ++j) { + cursor.toNextSibling(qFvImage); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + setFvImagesFvImageNameValue (fi, name, value, null); + } + cursor.dispose(); + } + /**Add to FvImage the name-value pair, or replace old name with newName, or generate new name-value pair if not exists before. * @param fi * @param name @@ -2932,6 +3257,12 @@ public class FpdFileContents { */ public void setFvImagesFvImageNameValue (FvImagesDocument.FvImages.FvImage fi, String name, String value, String newName) { if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null) { + FvImagesDocument.FvImages.FvImage.FvImageOptions.NameValue nv = fi.addNewFvImageOptions().addNewNameValue(); + nv.setName(name); + nv.setValue(value); + if (newName != null) { + nv.setName(newName); + } return; } @@ -2976,6 +3307,50 @@ public class FpdFileContents { } } } + + public int getFvImagePosInFvImages (String fvNameList, String type) { + XmlObject o = getfpdFlash().getFvImages(); + if (o == null) { + return -1; + } + + int pos = -1; + String[] fvNameArray = fvNameList.trim().split(" "); + Vector vFvNames = new Vector(); + + + XmlCursor cursor = o.newCursor(); + QName qFvImage = new QName(xmlNs, "FvImage"); + if (cursor.toChild(qFvImage)) { + do { + pos++; + vFvNames.removeAllElements(); + for (int i = 0; i < fvNameArray.length; ++i) { + vFvNames.add(fvNameArray[i]); + } + FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); + if (!fi.getType().toString().equals(type)) { + continue; + } + if (fi.getFvImageNamesList() == null || fi.getFvImageNamesList().size() != vFvNames.size()) { + continue; + } + ListIterator li = fi.getFvImageNamesList().listIterator(); + while (li.hasNext()) { + String name = li.next(); + vFvNames.remove(name); + } + if (vFvNames.size() == 0) { + cursor.dispose(); + return pos; + } + + }while (cursor.toNextSibling(qFvImage)); + + } + cursor.dispose(); + return -1; + } /**Get FvImage Options for FvImage i * @param i the ith FvImage */ @@ -2992,6 +3367,7 @@ public class FpdFileContents { } FvImagesDocument.FvImages.FvImage fi = (FvImagesDocument.FvImages.FvImage)cursor.getObject(); if (fi.getFvImageOptions() == null || fi.getFvImageOptions().getNameValueList() == null){ + cursor.dispose(); return; } ListIterator li = fi.getFvImageOptions().getNameValueList().listIterator(); @@ -3000,6 +3376,7 @@ public class FpdFileContents { m.put(nv.getName(), nv.getValue()); } } + cursor.dispose(); } /**