Skip to content
Snippets Groups Projects
Commit 147fde34 authored by gpawel's avatar gpawel
Browse files

bugfix: exposing method convertStringToElements (needed for YestLab)

SVN: 26444
parent 15c5a44e
No related branches found
No related tags found
No related merge requests found
...@@ -36,6 +36,13 @@ public interface IStructuredPropertyConverter ...@@ -36,6 +36,13 @@ public interface IStructuredPropertyConverter
*/ */
List<IElement> convertToElements(IManagedProperty property); List<IElement> convertToElements(IManagedProperty property);
/**
* Converts the values of specified String object into a list of elements.
*
* @return an empty list if the value is undefined or special.
*/
List<IElement> convertStringToElements(String propertyValue);
/** /**
* @return a {@link String} representation of the specified elements that can be persisted in * @return a {@link String} representation of the specified elements that can be persisted in
* the database. * the database.
......
...@@ -83,8 +83,7 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve ...@@ -83,8 +83,7 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve
private int level = 0; private int level = 0;
@Override @Override
public void writeStartArray(JsonGenerator jg) public void writeStartArray(JsonGenerator jg) throws IOException, JsonGenerationException
throws IOException, JsonGenerationException
{ {
if (level++ == 0) if (level++ == 0)
{ {
...@@ -129,7 +128,12 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve ...@@ -129,7 +128,12 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve
public boolean canHandle(IManagedProperty property) public boolean canHandle(IManagedProperty property)
{ {
return property.getValue().startsWith("["); return canHandle(property.getValue());
}
public boolean canHandle(String string)
{
return string.startsWith("[");
} }
@Override @Override
...@@ -138,7 +142,8 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve ...@@ -138,7 +142,8 @@ public class JsonStructuredPropertyConverter implements IStructuredPropertyConve
return convertStringToElements(property.getValue()); return convertStringToElements(property.getValue());
} }
private List<IElement> convertStringToElements(String propertyValue) @Override
public List<IElement> convertStringToElements(String propertyValue)
{ {
if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue)) if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue))
{ {
......
...@@ -62,6 +62,21 @@ public class XmlOrJsonStructuredPropertyConverter implements IStructuredProperty ...@@ -62,6 +62,21 @@ public class XmlOrJsonStructuredPropertyConverter implements IStructuredProperty
} }
} }
@Override
public List<IElement> convertStringToElements(String string)
{
if (xmlConverter.canHandle(string))
{
return xmlConverter.convertStringToElements(string);
} else if (jsonConverter.canHandle(string))
{
return jsonConverter.convertStringToElements(string);
} else
{
throw new UserFailureException("Illegal managed property value '" + string + "'.");
}
}
@Override @Override
public String convertToString(List<IElement> elements) public String convertToString(List<IElement> elements)
{ {
......
...@@ -62,10 +62,13 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver ...@@ -62,10 +62,13 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver
public boolean canHandle(IManagedProperty property) public boolean canHandle(IManagedProperty property)
{ {
String propertyValue = property.getValue(); return canHandle(property.getValue());
return propertyValue.startsWith("<" + ROOT_NAME) }
|| ManagedProperty.isSpecialValue(propertyValue)
|| StringUtils.isBlank(propertyValue); public boolean canHandle(String string)
{
return string.startsWith("<" + ROOT_NAME) || ManagedProperty.isSpecialValue(string)
|| StringUtils.isBlank(string);
} }
@Override @Override
...@@ -74,7 +77,8 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver ...@@ -74,7 +77,8 @@ public class XmlStructuredPropertyConverter implements IStructuredPropertyConver
return convertStringToElements(property.getValue()); return convertStringToElements(property.getValue());
} }
private List<IElement> convertStringToElements(String propertyValue) @Override
public List<IElement> convertStringToElements(String propertyValue)
{ {
if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue)) if (ManagedProperty.isSpecialValue(propertyValue) || StringUtils.isBlank(propertyValue))
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment