Changeset 875


Ignore:
Timestamp:
11/10/10 13:57:18 (14 years ago)
Author:
patdui
Message:
  • download expandable xml implemented
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/ComponentRegistryImpl.java

    r836 r875  
    22
    33import java.io.File;
    4 import java.io.FileInputStream;
    5 import java.io.FileNotFoundException;
    64import java.io.FileOutputStream;
    75import java.io.IOException;
    86import java.io.OutputStream;
     7import java.io.UnsupportedEncodingException;
    98import java.security.Principal;
    109import java.text.ParseException;
     
    2423import org.apache.commons.collections.map.LRUMap;
    2524import org.apache.commons.io.FileUtils;
    26 import org.apache.commons.io.IOUtils;
    2725import org.apache.commons.io.filefilter.IOFileFilter;
    2826import org.apache.commons.io.filefilter.NameFileFilter;
     
    201199
    202200    public void getMDProfileAsXml(String profileId, OutputStream output) {
    203         File file = getProfileFile(profileId);
    204         copyStream(file, output);
     201        CMDComponentSpec expandedSpec = CMDComponentSpecExpander.expandProfile(profileId, this);
     202        writeXml(expandedSpec, output);
    205203    }
    206204
     
    214212    }
    215213
    216     public File getProfileFile(String profileId) {
     214    private void writeXml(CMDComponentSpec spec, OutputStream outputStream) {
     215        try {
     216            MDMarshaller.marshal(spec, outputStream);
     217        } catch (UnsupportedEncodingException e) {
     218            LOG.error("Error in encoding: ", e);
     219        } catch (JAXBException e) {
     220            LOG.error("Cannot marshall spec: " + spec, e);
     221        }
     222    }
     223
     224    private File getProfileFile(String profileId) {
    217225        String id = stripRegistryId(profileId);
    218226        File file = new File(getProfileDir(), id + File.separator + id + ".xml");
     
    230238
    231239    public void getMDComponentAsXml(String componentId, OutputStream output) {
    232         File file = getComponentFile(componentId);
    233         copyStream(file, output);
    234     }
    235 
    236     private void copyStream(File file, OutputStream output) {
    237         try {
    238             IOUtils.copy(new FileInputStream(file), output);
    239         } catch (FileNotFoundException e) {
    240             LOG.error("Cannot retrieve file: " + file, e);
    241         } catch (IOException e) {
    242             LOG.error("Cannot retrieve content from file: " + file, e);
    243         }
     240        CMDComponentSpec expandedSpec = CMDComponentSpecExpander.expandComponent(componentId, this);
     241        writeXml(expandedSpec, output);
    244242    }
    245243
     
    249247    }
    250248
    251     public File getComponentFile(String componentId) {
     249    private File getComponentFile(String componentId) {
    252250        String id = stripRegistryId(componentId);
    253251        File file = new File(getComponentDir(), id + File.separator + id + ".xml");
Note: See TracChangeset for help on using the changeset viewer.