private static final Logger logger =
LoggerFactory.getLogger(DocumentUtils.class);
- /** The NAM e_ valu e_ separator. */
+ /** The name value separator. */
private static String NAME_VALUE_SEPARATOR = "|";
+
+ // The delimiter in a schema-qualified field name,
+ // between its schema name and field name components.
+ private static String SCHEMA_FIELD_DELIMITER = ":";
/** The XML elements with this suffix will indicate. */
private static String STRUCTURED_TYPE_SUFFIX = "List";
root.setAttribute("xmlns:" + ns, xc.getNamespaceURI());
document.appendChild(root);
- Schema schema = getSchema(partMeta.getLabel());
+ Schema schema = getSchemaFromName(partMeta.getLabel());
buildDocument(document, root, objectProps, schema);
}
}
- public static Schema getSchema(String label) {
+ /*
+ * Returns a schema, given the name of a schema.
+ *
+ * @param schemaName a schema name.
+ * @return a schema.
+ */
+ public static Schema getSchemaFromName(String schemaName) {
SchemaManager schemaManager = Framework.getLocalService(SchemaManager.class);
- return schemaManager.getSchema(label);
+ return schemaManager.getSchema(schemaName);
+ }
+
+ /*
+ * Returns the schema part of a presumably schema-qualified field name.
+ *
+ * If the schema part is null or empty, returns the supplied field name.
+ *
+ * @param schemaQualifiedFieldName a schema-qualified field name.
+ * @return the schema part of the field name.
+ */
+ public static String getSchemaNamePart(String schemaQualifiedFieldName) {
+ if (schemaQualifiedFieldName == null || schemaQualifiedFieldName.trim().isEmpty()) {
+ return schemaQualifiedFieldName;
+ }
+ if (schemaQualifiedFieldName.indexOf(SCHEMA_FIELD_DELIMITER) > 0) {
+ String[] schemaQualifiedFieldNameParts =
+ schemaQualifiedFieldName.split(SCHEMA_FIELD_DELIMITER);
+ String schemaName = schemaQualifiedFieldNameParts[0];
+ return schemaName;
+ } else {
+ return schemaQualifiedFieldName;
+ }
+ }
+
+ /*
+ * Returns a schema-qualified field name, given a schema name and field name.
+ *
+ * If the schema name is null or empty, returns the supplied field name.
+ *
+ * @param schemaName a schema name.
+ * @param fieldName a field name.
+ * @return a schema-qualified field name.
+ */
+ public static String appendSchemaName(String schemaName, String fieldName) {
+ if (schemaName == null || schemaName.trim().isEmpty()) {
+ return fieldName;
+ }
+ return schemaName + SCHEMA_FIELD_DELIMITER + fieldName;
}
DocumentWrapper<DocumentModel> docWrapper,
List<String> authRefFieldNames) throws PropertyException {
- final String SCHEMA_FIELD_DELIMITER = ":";
AuthorityRefList authRefList = new AuthorityRefList();
List<AuthorityRefList.AuthorityRefItem> list = authRefList.getAuthorityRefItem();
String refName = "";
for (String authRefFieldName : authRefFieldNames) {
- String schemaName = "";
- // FIXME: Replacing the following by an existing utility
- // method or, if not already present, create a new utility
- // method for this task in the common package.
- if (authRefFieldName.indexOf(SCHEMA_FIELD_DELIMITER) > 0) {
- String[] authRefFieldNameParts =
- authRefFieldName.split(SCHEMA_FIELD_DELIMITER);
- schemaName = authRefFieldNameParts[0];
- authRefFieldName = authRefFieldNameParts[1];
- }
-
- Schema schema = DocumentUtils.getSchema(schemaName);
+ String schemaName = DocumentUtils.getSchemaNamePart(authRefFieldName);
+ Schema schema = DocumentUtils.getSchemaFromName(schemaName);
Field field = schema.getField(authRefFieldName);
Type type = field.getType();
}
// FIXME: The following assumes a very simple structure
// for repeatable single scalar fields: a parent (continer)
- // element, containing 0-n child elements, each of the same
- // name and type, with values capable of being meaningfully
- // cast to String.
+ // element, containing 0-n child elements, each of them
+ // of identical name and type, with values capable of being
+ // meaningfully cast to String.
//
// Past release 1.0a, repeatability may consist
// of arbitrary nesting and complexity, rather than
if (obj != null) {
refName = (String) obj;
if (refName != null || ! refName.trim().isEmpty()) {
- list.add(authorityRefListItem(childAuthRefFieldName, refName));
+ String schemaQualifiedChildFieldName =
+ DocumentUtils.appendSchemaName(schemaName, childAuthRefFieldName);
+ list.add(authorityRefListItem(schemaQualifiedChildFieldName, refName));
}
}
}