if (value == null)
{
continue;
}
final AttributeMetaData attrMeta = metaData.getAttributeDescription(namespace, name);
if (attrMeta == null)
{
continue;
}
if (attrMeta.isTransient())
{
continue;
}
if (isFiltered(attrMeta))
{
continue;
}
if (attrMeta.isBulk() == false)
{
continue;
}
if ("Resource".equals(attrMeta.getValueRole()))
{
final AttributeList attList = new AttributeList();
if (attList.isNamespaceUriDefined(namespace) == false &&
writer.isNamespaceDefined(namespace) == false)
{
attList.addNamespaceDeclaration("autoGenNS", namespace);
}
if (value instanceof URL)
{
attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "url");
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(String.valueOf(value), true);
writer.writeCloseTag();
}
else if (value instanceof ResourceKey)
{
try
{
final ResourceKey key = (ResourceKey) value;
final ResourceManager resourceManager = bundle.getResourceManager();
final ResourceKey bundleKey = bundle.getBundleKey().getParent();
final String serializedKey = resourceManager.serialize(bundleKey, key);
attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "resource-key");
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(serializedKey, true);
writer.writeCloseTag();
}
catch (ResourceException re)
{
logger.error("Could not serialize the ResourceKey: " + re.getMessage(), re);
throw new IOException("Could not serialize the ResourceKey: ", re);
}
}
else if (value instanceof File)
{
attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "file");
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(String.valueOf(value), true);
writer.writeCloseTag();
}
else if (value instanceof String)
{
attList.setAttribute(AttributeNames.Core.NAMESPACE, "resource-type", "local-ref");
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(String.valueOf(value), true);
writer.writeCloseTag();
}
else
{
logger.warn("Unknown value-type in resource-attribute " + namespace + ":" + name);
}
continue;
}
if ("Expression".equals(attrMeta.getValueRole()) && value instanceof Expression)
{
// write attribute-expressions.
final AttributeList attList = new AttributeList();
attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-namespace", namespace);
attList.setAttribute(BundleNamespaces.LAYOUT, "attribute-name", name);
ExpressionWriterUtility.writeExpressionCore
(bundle, state, (Expression) value, writer, BundleNamespaces.LAYOUT, "expression", attList);
continue;
}
try
{
final PropertyEditor propertyEditor = attrMeta.getEditor();
if (propertyEditor != null)
{
propertyEditor.setValue(value);
final String text = propertyEditor.getAsText();
final AttributeList attList = new AttributeList();
if (attList.isNamespaceUriDefined(namespace) == false &&
writer.isNamespaceDefined(namespace) == false)
{
attList.addNamespaceDeclaration("autoGenNS", namespace);
}
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(text, true);
writer.writeCloseTag();
}
else
{
final String attrValue = ConverterRegistry.toAttributeValue(value);
final AttributeList attList = new AttributeList();
if (attList.isNamespaceUriDefined(namespace) == false &&
writer.isNamespaceDefined(namespace) == false)
{
attList.addNamespaceDeclaration("autoGenNS", namespace);
}
writer.writeTag(namespace, attrMeta.getName(), attList, XmlWriter.OPEN);
writer.writeTextNormalized(attrValue, true);
writer.writeCloseTag();
}
}