Revision 44161

View differences:

trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.mapcontext/org.gvsig.fmap.mapcontext.api/src/main/java/org/gvsig/fmap/mapcontext/impl/DefaultMapContextManager.java
29 29
import java.io.FileInputStream;
30 30
import java.io.FileNotFoundException;
31 31
import java.io.IOException;
32
import java.io.InputStream;
32 33
import java.lang.reflect.InvocationTargetException;
33 34
import java.lang.reflect.Method;
34 35
import java.util.ArrayList;
......
38 39
import java.util.LinkedHashMap;
39 40
import java.util.List;
40 41
import java.util.Map;
42
import org.apache.commons.io.IOUtils;
41 43
import org.apache.commons.lang3.StringUtils;
42 44

  
43 45
import org.cresques.cts.IProjection;
44 46
import org.gvsig.fmap.crs.CRSFactory;
45 47
import org.gvsig.fmap.dal.DataServerExplorer;
48
import org.gvsig.fmap.dal.DataServerExplorer.DataResource;
46 49
import org.gvsig.fmap.dal.DataStore;
47 50
import org.gvsig.fmap.dal.DataStoreParameters;
48 51
import org.gvsig.fmap.dal.exception.DataException;
......
582 585
    public ILegend getLegend(DataStore dataStore) {
583 586
        ILegend legend = null;
584 587

  
585
        File file = getResourcePath(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1));
588
        DataResource resource = getResource(dataStore, SymbolManager.LEGEND_FILE_EXTENSION.substring(1));
586 589
        try {
587
            if ((file != null) && (file.exists())) {
590
            if ((resource != null) && (resource.exists())) {
588 591
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
589
                FileInputStream is = new FileInputStream(file);
592
                InputStream is = resource.asInputStream();
590 593
                legend = (ILegend) persistenceManager.getObject(is);
591 594
                is.close();
592 595
            }
593
        } catch (FileNotFoundException e) {
594
            logger.error("Legend not found", e);
595
        } catch (IOException e) {
596
            logger.error("Error reading the legend", e);
596
        } catch (Exception e) {
597
            logger.warn("Can't loasd legend", e);
598
        } finally {
599
            IOUtils.closeQuietly(resource);
597 600
        }
598 601

  
599 602
        //If the legend is null, next option is to check if the store has the getLegend method
......
632 635
    public ILabelingStrategy getLabelingStrategy(DataStore dataStore) {
633 636
        ILabelingStrategy labelingStrategy = null;
634 637

  
635
        File file = getResourcePath(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1));
638
        DataResource resource = getResource(dataStore, SymbolManager.LABELINGSTRATEGY_FILE_EXTENSION.substring(1));
636 639
        try {
637
            if ((file != null) && (file.exists())) {
640
            if ((resource != null) && (resource.exists())) {
638 641
                PersistenceManager persistenceManager = ToolsLocator.getPersistenceManager();
639
                FileInputStream is = new FileInputStream(file);
642
                InputStream is = resource.asInputStream();
640 643
                labelingStrategy = (ILabelingStrategy) persistenceManager.getObject(is);
641 644
                is.close();
642 645
            }
643
        } catch (FileNotFoundException e) {
644
            logger.error("Label strategy not found", e);
645
        } catch (IOException e) {
646
            logger.error("Error reading the labeling strategy", e);
646
        } catch (Exception e) {
647
            logger.warn("Can't load Label strategy", e);
648
        } finally {
649
            IOUtils.closeQuietly(resource);
647 650
        }
648 651

  
649 652
        //If the legend is null, next option is to check if the store has the getLegend method
......
685 688
        }
686 689
    }
687 690

  
688
    private File getResourcePath(DataStore dataStore, String resource) {
689
        //Loading the file from a store based on file
691
    
692
    private DataResource getResource(DataStore dataStore, String resource) {
690 693
        DataServerExplorer explorer = null;
691 694
        try {
692 695
            explorer = dataStore.getExplorer();
693 696
            if (explorer == null) {
694 697
                return null;
695 698
            }
696
            return explorer.getResourcePath(dataStore, resource);
699
            return explorer.getResource(dataStore, resource);
697 700
        } catch (Exception e) {
698
            logger.warn(
699
                    "Can't locate a specific legend provided by the explorer "
700
                    + explorer, e);
701
            logger.warn("Can't locate resource '"+resource+"' for '"+dataStore.getName()+"'.",e);
701 702
            return null;
702 703
        } finally {
703 704
            DisposeUtils.disposeQuietly(explorer);

Also available in: Unified diff