Changeset 1198

Show
Ignore:
Timestamp:
02/07/10 11:08:58 (7 months ago)
Author:
dreisch
Message:

-fixed #1040

Location:
ide/trunk/src/org/korsakow/domain
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • ide/trunk/src/org/korsakow/domain/command/ExportFlashProjectCommand.java

    r1060 r1198  
    1515import org.korsakow.domain.interf.IMedia; 
    1616import org.korsakow.domain.interf.IProject; 
    17 import org.korsakow.domain.interf.IResource; 
    1817import org.korsakow.domain.interf.ISettings; 
    1918import org.korsakow.domain.interf.ISound; 
    2019import org.korsakow.domain.interf.IText; 
    2120import org.korsakow.domain.interf.IVideo; 
    22 import org.korsakow.domain.mapper.input.MapperHelper; 
     21import org.korsakow.domain.mapper.input.MediaInputMapper; 
    2322import org.korsakow.domain.mapper.input.ProjectInputMapper; 
    2423import org.korsakow.domain.task.ITask; 
    2524import org.korsakow.domain.task.IWorker; 
    26 import org.korsakow.ide.DataRegistry; 
    2725import org.korsakow.ide.lang.LanguageBundle; 
    2826import org.korsakow.ide.task.AbstractTask; 
    2927import org.korsakow.ide.task.UIWorker; 
    30 import org.korsakow.ide.util.DomUtil; 
    3128 
    3229 
     
    7067        private static class SetupExporterTask extends AbstractTask 
    7168        { 
    72                 private IWorker uiWorker; 
    73                 private File exportDir; 
    74                 private Exporter exporter; 
    75                 private long projectId; 
     69                private final IWorker uiWorker; 
     70                private final File exportDir; 
     71                private final Exporter exporter; 
     72                private final long projectId; 
    7673                public SetupExporterTask(IWorker uiWorker, Exporter exporter, File exportDir, long projectId) 
    7774                { 
     
    8279                } 
    8380 
     81                @Override 
    8482                public void runTask() throws Exception { 
    8583                        UoW.newCurrent(); 
     
    8886                        ISettings settings = project.getSettings(); 
    8987 
    90                         Collection<IMedia> media = project.getMedia(); 
     88                        Collection<IMedia> media =  MediaInputMapper.findReferencedMedia(); 
    9189                        Collection<ISound> sounds = new HashSet<ISound>(); 
    9290                        Collection<IVideo> videos = new HashSet<IVideo>(); 
     
    9896                        for (IMedia medium : media) 
    9997                        { 
    100                                 System.gc(); // findResourcesReferencing can be a large task on big projects 
    101                                  
    10298                                fireProgressChanged(0, ++i*100/size); 
    10399                                fireDisplayStringChanged("", medium.getName()); 
    104 //                              Thread.sleep(70); // this is a completely unreliable way of giving the publish a chance to run 
    105 //                              // don't export unused media since it takes long and uses up space, which especially is important for web. 
    106                                 Collection<IResource> referers = MapperHelper.findResourcesReferencing(medium.getId()); 
    107                                 if (referers.isEmpty()) 
    108                                         continue; 
    109100                                 
    110101                                if (medium instanceof ISound) 
     
    123114                        } 
    124115                        long after = System.currentTimeMillis(); 
    125 //                      System.out.println("Determination: " + (after-before)/1000); 
     116                        System.out.println("Determination: " + (after-before)/1000 + "\t" + media.size()); 
    126117                         
    127118                         
     
    139130                        uiWorker.addTasks(exportTasks); 
    140131                } 
     132                @Override 
    141133                public String getTitleString() 
    142134                { 
  • ide/trunk/src/org/korsakow/domain/mapper/input/MapperHelper.java

    r1022 r1198  
    2828public class MapperHelper 
    2929{ 
     30        public static final String[] REFERENCING_ELEMENTS = { 
     31                                                        "backgroundSoundId", 
     32                                                        "backgroundImageId", 
     33                                                        "clickSoundId", 
     34                                                        "splashScreenMediaId", 
     35                                                        "soundId", 
     36                                                        "textId", 
     37                                                        "imageId", 
     38                                                        "mainMediaId", 
     39                                                        "videoId", 
     40                                                        "snuId", 
     41                                                        "mediaId", 
     42                                                        "startingSnuId", 
     43                                                        "interfaceId", 
     44                                                        "previewMediaId" 
     45        }; 
    3046        /** 
    3147         * This is a terrible implementation. 
     
    98114                Set<IResource> references = new HashSet<IResource>(); 
    99115                 
    100                 String[] REFERENCING_ELEMENTS = { 
    101                                                                 "backgroundSoundId", 
    102                                                                 "backgroundImageId", 
    103                                                                 "clickSoundId", 
    104                                                                 "splashScreenMediaId", 
    105                                                                 "soundId", 
    106                                                                 "textId", 
    107                                                                 "imageId", 
    108                                                                 "mainMediaId", 
    109                                                                 "videoId", 
    110                                                                 "snuId", 
    111                                                                 "mediaId", 
    112                                                                 "startingSnuId", 
    113                                                                 "interfaceId", 
    114                                                                 "previewMediaId" 
    115                 }; 
    116 //              // TODO: obviously maintaining this list is not the way to go 
     116                //              // TODO: obviously maintaining this list is not the way to go 
    117117//              // I would like to have it so the structure clearly differentiates between an ID declaration and 
    118118//              // a reference to an object's id 
  • ide/trunk/src/org/korsakow/domain/mapper/input/MediaInputMapper.java

    r1044 r1198  
    44import java.util.ArrayList; 
    55import java.util.Collection; 
     6import java.util.HashSet; 
    67import java.util.List; 
     8import java.util.Set; 
    79 
    810import javax.xml.xpath.XPathExpressionException; 
     
    1315import org.korsakow.domain.interf.IMedia; 
    1416import org.korsakow.domain.interf.IResource; 
     17import org.korsakow.ide.DataRegistry; 
    1518import org.korsakow.services.finder.ResourceFinder; 
    1619import org.w3c.dom.Element; 
     
    5760                } 
    5861        } 
     62        public static Collection<IMedia> findReferencedMedia() throws MapperException, DomainObjectCreationException, XPathExpressionException, SQLException 
     63        { 
     64                Set<IMedia> referenced = new HashSet<IMedia>(); 
     65                 
     66//              // TODO: obviously maintaining this list is not the way to go 
     67//              // I would like to have it so the structure clearly differentiates between an ID declaration and 
     68//              // a reference to an object's id 
     69//              // something along the lines of <Snu><mainMedia><refId>1</refId></mainMedia></Snu> 
     70                for (String ELEMENT : MapperHelper.REFERENCING_ELEMENTS) 
     71                { 
     72                        NodeList elements = DataRegistry.getDocument().getElementsByTagName(ELEMENT); 
     73                        int length = elements.getLength(); 
     74                        for (int i = 0; i < length; ++i) { 
     75                                Element element = (Element)elements.item(i); 
     76                                long refId = Long.parseLong(element.getTextContent()); 
     77                                IResource resource = ResourceInputMapper.map(refId); 
     78                                if (resource instanceof IMedia) 
     79                                        referenced.add((IMedia)resource); 
     80                        } 
     81                } 
     82                return referenced; 
     83        } 
    5984}