Changeset 1864 for ComponentRegistry/tags/ComponentRegistry-1.11.1/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java
- Timestamp:
- 04/05/12 15:38:51 (12 years ago)
- Location:
- ComponentRegistry/tags/ComponentRegistry-1.11.1
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/tags/ComponentRegistry-1.11.1
- Property svn:mergeinfo changed
/ComponentRegistry/trunk (added) merged: 1859-1863
- Property svn:mergeinfo changed
-
ComponentRegistry/tags/ComponentRegistry-1.11.1/ComponentRegistry
- Property svn:mergeinfo changed
/ComponentRegistry/trunk/ComponentRegistry (added) merged: 1860-1863
- Property svn:mergeinfo changed
-
ComponentRegistry/tags/ComponentRegistry-1.11.1/ComponentRegistry/src/main/java
- Property svn:mergeinfo changed
/ComponentRegistry/trunk/ComponentRegistry/src/main/java (added) merged: 1860,1862-1863
- Property svn:mergeinfo changed
-
ComponentRegistry/tags/ComponentRegistry-1.11.1/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rest/MDValidator.java
r1816 r1864 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 4 import clarin.cmdi.componentregistry.ComponentRegistryException; 5 import clarin.cmdi.componentregistry.ComponentRegistryResourceResolver; 5 6 import clarin.cmdi.componentregistry.Configuration; 6 7 import clarin.cmdi.componentregistry.MDMarshaller; … … 28 29 29 30 public class MDValidator implements Validator { 30 31 31 32 private final static Logger LOG = LoggerFactory.getLogger(MDValidator.class); 32 33 static final String MISMATCH_ERROR = "Cannot register component as a profile or vica versa."; … … 49 50 50 51 /** 51 * 52 * @param input In order to validate the input is consumed. So use @see getCMDComponentSpec to get the parsed CMDComponentSpec. 52 * 53 * @param input In order to validate the input is consumed. So use 54 * @see getCMDComponentSpec to get the parsed CMDComponentSpec. 53 55 * @param desc 54 * @param registry (registry you currently used) 55 * @param userRegistry can be null, We get user registry as well so we can give nice error messages if needed. Can be the same as @param registry 56 * @param registry (registry you currently used) 57 * @param userRegistry can be null, We get user registry as well so we can give nice error messages if needed. Can be the same as 58 * @param registry 56 59 */ 57 60 public MDValidator(InputStream input, AbstractDescription description, ComponentRegistry registry, ComponentRegistry userRegistry, ComponentRegistry publicRegistry) { … … 62 65 this.publicRegistry = publicRegistry; 63 66 } 64 67 65 68 @Override 66 69 public List<String> getErrorMessages() { 67 70 return errorMessages; 68 71 } 69 72 70 73 @Override 71 74 public boolean validate() { 72 75 try { 73 76 clarin.cmdi.schema.cmd.Validator validator = new clarin.cmdi.schema.cmd.Validator(new URL(Configuration.getInstance().getGeneralComponentSchema())); 77 validator.setResourceResolver(new ComponentRegistryResourceResolver()); 74 78 // We may need to reuse the input stream, so save it to a byte array first 75 79 byte[] inputBytes = getBytesFromInputStream(); … … 109 113 return errorMessages.isEmpty(); 110 114 } 111 115 112 116 private byte[] getBytesFromInputStream() throws IOException { 113 117 int len; 114 118 byte[] b = new byte[4096]; 115 119 final ByteArrayOutputStream bOS = new ByteArrayOutputStream(); 116 120 117 121 while ((len = input.read(b)) > 0) { 118 122 bOS.write(b, 0, len); 119 123 } 120 124 121 125 return bOS.toByteArray(); 122 126 } 123 127 124 128 private void validateComponents(List<CMDComponentType> cmdComponents) throws ComponentRegistryException { 125 129 for (CMDComponentType cmdComponentType : cmdComponents) { … … 128 132 } 129 133 } 130 134 131 135 private void validateDescribedComponents(CMDComponentType cmdComponentType) throws ComponentRegistryException { 132 136 checkPublicComponents(cmdComponentType); 133 137 } 134 138 135 139 private void checkPublicComponents(CMDComponentType cmdComponentType) throws ComponentRegistryException { 136 140 if (isDefinedInSeparateFile(cmdComponentType)) { … … 157 161 } 158 162 } 159 163 160 164 } 161 165 } 162 166 } 163 167 164 168 private boolean isDefinedInSeparateFile(CMDComponentType cmdComponentType) { 165 169 return cmdComponentType.getName() == null; 166 170 } 167 171 168 172 public CMDComponentSpec getCMDComponentSpec() { 169 173 return spec;
Note: See TracChangeset
for help on using the changeset viewer.