/** * Load schema. * * @param schema the schema * @param schemaElement the schema element * @return the map * @throws Exception the exception */ @SuppressWarnings("unchecked") private static Map<String, Object> loadSchema( Schema schema, org.dom4j.Element schemaElement, ServiceContext ctx) throws Exception { String schemaName1 = schemaElement.attributeValue( ExportConstants.NAME_ATTR); // FIXME: Do we need this local var? String schemaName = schema.getName(); Map<String, Object> data = new HashMap<String, Object>(); Iterator<org.dom4j.Element> it = schemaElement.elementIterator(); while (it.hasNext()) { org.dom4j.Element element = it.next(); String name = element.getName(); Field field = schema.getField(name); if (field != null) { Object value = getElementData(element, field.getType(), ctx); data.put(name, value); } else { // FIXME: substitute an appropriate constant for "csid" below. // One potential class to which to add that constant, if it is not already // declared, might be AbstractCollectionSpaceResourceImpl - ADR 2012-09-24 if (!name.equals("csid")) { // 'csid' elements in input payloads can be safely ignored. logger.warn( "Invalid input document. No such property was found [" + name + "] in schema " + schemaName); } } } return data; }
// called from XSDLoader protected void registerSchema(Schema schema) { schemas.put(schema.getName(), schema); Namespace ns = schema.getNamespace(); uriToSchema.put(ns.uri, schema); if (!StringUtils.isBlank(ns.prefix)) { prefixToSchema.put(ns.prefix, schema); } }
/** * @return The message if it's found in message bundles, a generic message otherwise. * @since 7.1 */ public String getMessage(Locale locale) { // test whether there's a specific translation for for this field and this constraint // the expected key is // label.schema.constraint.violation.[constraintName].[schemaName].[field].[subField] List<String> pathTokens = new ArrayList<String>(); pathTokens.add(Constraint.MESSAGES_KEY); pathTokens.add(constraint.getDescription().getName()); pathTokens.add(schema.getName()); for (PathNode node : path) { String name = node.getField().getName().getLocalName(); pathTokens.add(name); } String key = StringUtils.join(pathTokens, '.'); String computedInvalidValue = "null"; if (invalidValue != null) { String invalidValueString = invalidValue.toString(); if (invalidValueString.length() > 20) { computedInvalidValue = invalidValueString.substring(0, 15) + "..."; } else { computedInvalidValue = invalidValueString; } } Object[] params = new Object[] {computedInvalidValue}; Locale computedLocale = locale != null ? locale : Constraint.MESSAGES_DEFAULT_LANG; String message = null; try { message = I18NUtils.getMessageString(Constraint.MESSAGES_BUNDLE, key, params, computedLocale); } catch (MissingResourceException e) { log.trace("No bundle found", e); message = null; } if (message != null && !message.trim().isEmpty() && !key.equals(message)) { // use the message if there's one return message; } else { if (locale != null && Locale.ENGLISH.getLanguage().equals(locale.getLanguage())) { // use the constraint message return constraint.getErrorMessage(invalidValue, locale); } else { return getMessage(Locale.ENGLISH); } } }