Changeset 1340
- Timestamp:
- 05/19/11 07:33:10 (13 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/ComponentRegistryImplBase.java
r1339 r1340 2 2 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 import clarin.cmdi.componentregistry.ComponentRegistryUtils;5 4 import clarin.cmdi.componentregistry.DeleteFailedException; 5 import clarin.cmdi.componentregistry.MDMarshaller; 6 6 import clarin.cmdi.componentregistry.UserUnauthorizedException; 7 7 import clarin.cmdi.componentregistry.components.CMDComponentSpec; 8 import clarin.cmdi.componentregistry.components.CMDComponentSpec.Header; 9 import clarin.cmdi.componentregistry.components.CMDComponentType; 8 10 import clarin.cmdi.componentregistry.model.AbstractDescription; 9 11 import clarin.cmdi.componentregistry.model.ComponentDescription; … … 11 13 import java.io.IOException; 12 14 import java.io.OutputStream; 15 import java.io.UnsupportedEncodingException; 13 16 import java.security.Principal; 14 17 import java.util.ArrayList; 15 18 import java.util.List; 19 import javax.xml.bind.JAXBException; 20 import org.apache.commons.lang.StringUtils; 21 import org.slf4j.Logger; 22 import org.slf4j.LoggerFactory; 16 23 17 24 /** … … 20 27 */ 21 28 public abstract class ComponentRegistryImplBase implements ComponentRegistry{ 29 private final static Logger LOG = LoggerFactory.getLogger(ComponentRegistryImplBase.class); 22 30 23 31 @Override … … 27 35 for (ComponentDescription desc : descs) { 28 36 CMDComponentSpec spec = getMDComponent(desc.getId()); 29 if (spec != null && ComponentRegistryUtils.findComponentId(componentId, spec.getCMDComponent())) {37 if (spec != null && findComponentId(componentId, spec.getCMDComponent())) { 30 38 result.add(desc); 31 39 } … … 39 47 for (ProfileDescription profileDescription : getProfileDescriptions()) { 40 48 CMDComponentSpec profile = getMDProfile(profileDescription.getId()); 41 if (profile != null && ComponentRegistryUtils.findComponentId(componentId, profile.getCMDComponent())) {49 if (profile != null && findComponentId(componentId, profile.getCMDComponent())) { 42 50 result.add(profileDescription); 43 51 } … … 45 53 return result; 46 54 } 55 56 /* HELPER METHODS */ 57 58 protected static String stripRegistryId(String id) { 59 return StringUtils.removeStart(id, ComponentRegistry.REGISTRY_ID); 60 } 61 62 protected static void enrichSpecHeader(CMDComponentSpec spec, AbstractDescription description) { 63 Header header = spec.getHeader(); 64 header.setID(description.getId()); 65 if (StringUtils.isEmpty(header.getName())) { 66 header.setName(description.getName()); 67 } 68 if (StringUtils.isEmpty(header.getDescription())) { 69 header.setDescription(description.getDescription()); 70 } 71 } 72 73 protected static boolean findComponentId(String componentId, List<CMDComponentType> componentReferences) { 74 for (CMDComponentType cmdComponent : componentReferences) { 75 if (componentId.equals(cmdComponent.getComponentId())) { 76 return true; 77 } else if (findComponentId(componentId, cmdComponent.getCMDComponent())) { 78 return true; 79 } 80 } 81 return false; 82 } 83 84 protected static void writeXsd(CMDComponentSpec expandedSpec, OutputStream outputStream) { 85 MDMarshaller.generateXsd(expandedSpec, outputStream); 86 } 87 88 protected static void writeXml(CMDComponentSpec spec, OutputStream outputStream) { 89 try { 90 MDMarshaller.marshal(spec, outputStream); 91 } catch (UnsupportedEncodingException e) { 92 LOG.error("Error in encoding: ", e); 93 } catch (JAXBException e) { 94 LOG.error("Cannot marshall spec: " + spec, e); 95 } 96 } 97 98 /* UNIMPLEMENTED INTERFACE METHODS */ 47 99 48 100 @Override -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1339 r1340 2 2 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 import clarin.cmdi.componentregistry.ComponentRegistryUtils;5 4 import clarin.cmdi.componentregistry.Configuration; 6 5 import clarin.cmdi.componentregistry.DeleteFailedException; … … 131 130 @Override 132 131 public int register(AbstractDescription description, CMDComponentSpec spec) { 133 ComponentRegistryUtils.enrichSpecHeader(spec, description);132 enrichSpecHeader(spec, description); 134 133 try { 135 134 String xml = componentSpecToString(spec); … … 194 193 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl. 195 194 expandProfile(profileId, this); 196 ComponentRegistryUtils.writeXml(expandedSpec, output);195 writeXml(expandedSpec, output); 197 196 } 198 197 … … 201 200 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl. 202 201 expandProfile(profileId, this); 203 ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);202 writeXsd(expandedSpec, outputStream); 204 203 } 205 204 … … 208 207 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl. 209 208 expandComponent(componentId, this); 210 ComponentRegistryUtils.writeXml(expandedSpec, output);209 writeXml(expandedSpec, output); 211 210 } 212 211 … … 215 214 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderDbImpl. 216 215 expandComponent(componentId, this); 217 ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);216 writeXsd(expandedSpec, outputStream); 218 217 } 219 218 -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/filesystem/ComponentRegistryImpl.java
r1339 r1340 3 3 import clarin.cmdi.componentregistry.impl.ComponentRegistryImplBase; 4 4 import clarin.cmdi.componentregistry.ComponentRegistry; 5 import clarin.cmdi.componentregistry.ComponentRegistryUtils;6 5 import clarin.cmdi.componentregistry.Configuration; 7 6 import clarin.cmdi.componentregistry.DeleteFailedException; … … 167 166 public void getMDProfileAsXml(String profileId, OutputStream output) { 168 167 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandProfile(profileId, this); 169 ComponentRegistryUtils.writeXml(expandedSpec, output);168 writeXml(expandedSpec, output); 170 169 } 171 170 … … 173 172 public void getMDProfileAsXsd(String profileId, OutputStream outputStream) { 174 173 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandProfile(profileId, this); 175 ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);174 writeXsd(expandedSpec, outputStream); 176 175 } 177 176 178 177 private File getProfileFile(String profileId) { 179 String id = ComponentRegistryUtils.stripRegistryId(profileId);178 String id = stripRegistryId(profileId); 180 179 File file = new File(getProfileDir(), id + File.separator + id + ".xml"); 181 180 return file; … … 195 194 public void getMDComponentAsXml(String componentId, OutputStream output) { 196 195 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandComponent(componentId, this); 197 ComponentRegistryUtils.writeXml(expandedSpec, output);196 writeXml(expandedSpec, output); 198 197 } 199 198 … … 201 200 public void getMDComponentAsXsd(String componentId, OutputStream outputStream) { 202 201 CMDComponentSpec expandedSpec = CMDComponentSpecExpanderImpl.expandComponent(componentId, this); 203 ComponentRegistryUtils.writeXsd(expandedSpec, outputStream);202 writeXsd(expandedSpec, outputStream); 204 203 } 205 204 206 205 private File getComponentFile(String componentId) { 207 String id = ComponentRegistryUtils.stripRegistryId(componentId);206 String id = stripRegistryId(componentId); 208 207 File file = new File(getComponentDir(), id + File.separator + id + ".xml"); 209 208 return file; … … 265 264 266 265 private int register(File storageDir, AbstractDescription description, CMDComponentSpec spec, Closure onFail) { 267 String strippedId = ComponentRegistryUtils.stripRegistryId(description.getId());266 String strippedId = stripRegistryId(description.getId()); 268 267 File dir = new File(storageDir, strippedId); 269 268 boolean success = false; … … 273 272 writeDescription(dir, description); 274 273 if (spec != null) { 275 ComponentRegistryUtils.enrichSpecHeader(spec, description);274 enrichSpecHeader(spec, description); 276 275 writeCMDComponentSpec(dir, strippedId + ".xml", spec); 277 276 } … … 403 402 File file = null; 404 403 if (description.isProfile()) { 405 file = new File(resourceConfig.getProfileDeletionDir(), ComponentRegistryUtils.stripRegistryId(description.getId()));404 file = new File(resourceConfig.getProfileDeletionDir(), stripRegistryId(description.getId())); 406 405 } else { 407 file = new File(resourceConfig.getComponentDeletionDir(), ComponentRegistryUtils.stripRegistryId(description.getId()));406 file = new File(resourceConfig.getComponentDeletionDir(), stripRegistryId(description.getId())); 408 407 } 409 408 if (file.exists()) {
Note: See TracChangeset
for help on using the changeset viewer.