// Nothing to fill - eg. gco:CharacterString
if (isSimpleElement) {
return;
}
MetadataType type = schema.getTypeInfo(schema.getElementType(elemName, parentName));
boolean hasSuggestion = sugg.hasSuggestion(elemName, type.getElementList());
// List<String> elementSuggestion = sugg.getSuggestedElements(elemName);
// boolean hasSuggestion = elementSuggestion.size() != 0;
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - Type:");
Log.debug(Geonet.EDITORFILLELEMENT,"#### - name = " + type.getName());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - # attributes = " + type.getAttributeCount());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - # elements = " + type.getElementCount());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - # isOrType = " + type.isOrType());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - type = " + type);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - Has suggestion = " + hasSuggestion);
}
//-----------------------------------------------------------------------
//--- handle attributes if mandatory or suggested
//
for(int i=0; i<type.getAttributeCount(); i++) {
MetadataAttribute attr = type.getAttributeAt(i);
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - " + i + " attribute = " + attr.name);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - required = " + attr.required);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - suggested = "+sugg.isSuggested(elemName, attr.name));
}
if (attr.required || sugg.isSuggested(elemName, attr.name)) {
String value = "";
if (attr.defValue != null) {
value = attr.defValue;
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - value = " + attr.defValue);
}
}
String uname = getUnqualifiedName(attr.name);
String ns = getNamespace(attr.name, element, schema);
String prefix = getPrefix(attr.name);
if (!prefix.equals(""))
element.setAttribute(new Attribute(uname, value, Namespace.getNamespace(prefix,ns)));
else
element.setAttribute(new Attribute(uname, value));
}
}
//-----------------------------------------------------------------------
//--- add mandatory children
//
// isOrType if element has substitutes and one of them should be chosen
if (!type.isOrType()) {
for(int i=0; i<type.getElementCount(); i++) {
String childName = type.getElementAt(i);
boolean childIsMandatory = type.getMinCardinAt(i) > 0;
boolean childIsSuggested = sugg.isSuggested(elemName, childName);
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - " + i + " element = " + childName);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - suggested = " + childIsSuggested);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - is mandatory = " + childIsMandatory);
}
if (childIsMandatory || childIsSuggested) {
MetadataType elemType = schema.getTypeInfo(schema.getElementType(childName, elemName));
List<String> childSuggestion = sugg.getSuggestedElements(childName);
boolean childHasOneSuggestion = sugg.hasSuggestion(childName, elemType.getElementList()) && (CollectionUtils.intersection(elemType.getElementList(),childSuggestion).size()==1);
boolean childHasOnlyCharacterStringSuggestion = childSuggestion.size() == 1 && childSuggestion.contains("gco:CharacterString");
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - is or type = "+ elemType.isOrType());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - has suggestion = "+ childHasOneSuggestion);
Log.debug(Geonet.EDITORFILLELEMENT,"#### - elem type list = " + elemType.getElementList());
Log.debug(Geonet.EDITORFILLELEMENT,"#### - suggested types list = " + sugg.getSuggestedElements(childName));
}
//--- There can be 'or' elements with other 'or' elements inside them.
//--- In this case we cannot expand the inner 'or' elements so the
//--- only way to solve the problem is to avoid the creation of them
if (
schema.isSimpleElement(elemName, childName) || // eg. gco:Decimal
!elemType.isOrType() || // eg. gmd:EX_Extent
(elemType.isOrType() && ( // eg. depends on schema-suggestions.xml
childHasOneSuggestion || // expand the only one suggestion - TODO - this needs improvements
(childSuggestion.size() == 0 && elemType.getElementList().contains("gco:CharacterString")))
// expand element which have no suggestion
// and have a gco:CharacterString substitute.
// gco:CharacterString is the default.
)
) {
// Create the element
String name = getUnqualifiedName(childName);
String ns = getNamespace(childName, element, schema);
String prefix = getPrefix(childName);
Element child = new Element(name, prefix, ns);
// Add it to the element
element.addContent(child);
if (childHasOnlyCharacterStringSuggestion) {
child.addContent(new Element("CharacterString", Namespaces.GCO));
}
// Continue ....
fillElement(schema, sugg, element, child);
} else {
// Logging some cases to avoid
if(Log.isDebugEnabled(Geonet.EDITORFILLELEMENT)) {
if (elemType.isOrType()) {
if (elemType.getElementList().contains("gco:CharacterString")
&& !childHasOneSuggestion) {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - (INNER) Requested expansion of an OR element having gco:CharacterString substitute and no suggestion: " + element.getName());
} else {
Log.debug(Geonet.EDITORFILLELEMENT,"#### - WARNING (INNER): requested expansion of an OR element : " +childName);
}