diff --git a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementFromJsonVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementFromJsonVisitor.java index 81bebb72e..e6059b4dc 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementFromJsonVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementFromJsonVisitor.java @@ -1,12 +1,12 @@ /* * Copyright 2015 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,20 +23,9 @@ import java.util.Set; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; - import li.strolch.exception.StrolchException; -import li.strolch.model.AbstractStrolchElement; -import li.strolch.model.GroupedParameterizedElement; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.ParameterizedElement; -import li.strolch.model.Resource; -import li.strolch.model.State; -import li.strolch.model.StrolchRootElement; -import li.strolch.model.StrolchValueType; -import li.strolch.model.Tags; +import li.strolch.model.*; import li.strolch.model.Tags.Json; -import li.strolch.model.Version; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.TimeOrdering; @@ -71,15 +60,15 @@ public class StrolchElementFromJsonVisitor { order.setPolicyDefs(defs); // attributes - if (jsonObject.has(Tags.Json.DATE)) { - String date = jsonObject.get(Tags.Json.DATE).getAsString(); + if (jsonObject.has(Json.DATE)) { + String date = jsonObject.get(Json.DATE).getAsString(); order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(date)); } else { order.setDate(ISO8601FormatFactory.getInstance().getDateFormat().parse(StringHelper.DASH)); //$NON-NLS-1$ } - if (jsonObject.has(Tags.Json.STATE)) { - order.setState(State.parse(jsonObject.get(Tags.Json.STATE).getAsString())); + if (jsonObject.has(Json.STATE)) { + order.setState(State.parse(jsonObject.get(Json.STATE).getAsString())); } else { order.setState(State.CREATED); } @@ -101,10 +90,10 @@ public class StrolchElementFromJsonVisitor { resource.setPolicyDefs(defs); // time states - if (!jsonObject.has(Tags.Json.TIMED_STATES)) + if (!jsonObject.has(Json.TIMED_STATES)) return; - JsonObject timedStatesJ = jsonObject.getAsJsonObject(Tags.Json.TIMED_STATES); + JsonObject timedStatesJ = jsonObject.getAsJsonObject(Json.TIMED_STATES); Set> entrySet = timedStatesJ.entrySet(); for (Entry entry : entrySet) { @@ -112,7 +101,7 @@ public class StrolchElementFromJsonVisitor { JsonObject timeStateJ = entry.getValue().getAsJsonObject(); // evaluate type of TimedState - String typeS = timeStateJ.get(Tags.Json.TYPE).getAsString(); + String typeS = timeStateJ.get(Json.TYPE).getAsString(); DBC.PRE.assertNotEmpty("Type must be set on TimedState for resource with id " + resource.getId(), typeS); StrolchValueType valueType = StrolchValueType.parse(typeS); StrolchTimedState> timedState = valueType.timedStateInstance(); @@ -128,29 +117,29 @@ public class StrolchElementFromJsonVisitor { } // further attributes - if (timeStateJ.has(Tags.Json.INTERPRETATION)) - timedState.setInterpretation(timeStateJ.get(Tags.Json.INTERPRETATION).getAsString()); - if (timeStateJ.has(Tags.Json.UOM)) - timedState.setUom(timeStateJ.get(Tags.Json.UOM).getAsString()); - if (timeStateJ.has(Tags.Json.INDEX)) - timedState.setIndex(timeStateJ.get(Tags.Json.INDEX).getAsInt()); - if (timeStateJ.has(Tags.Json.HIDDEN)) - timedState.setHidden(timeStateJ.get(Tags.Json.HIDDEN).getAsBoolean()); + if (timeStateJ.has(Json.INTERPRETATION)) + timedState.setInterpretation(timeStateJ.get(Json.INTERPRETATION).getAsString()); + if (timeStateJ.has(Json.UOM)) + timedState.setUom(timeStateJ.get(Json.UOM).getAsString()); + if (timeStateJ.has(Json.INDEX)) + timedState.setIndex(timeStateJ.get(Json.INDEX).getAsInt()); + if (timeStateJ.has(Json.HIDDEN)) + timedState.setHidden(timeStateJ.get(Json.HIDDEN).getAsBoolean()); resource.addTimedState(timedState); - if (!timeStateJ.has(Tags.Json.VALUES)) + if (!timeStateJ.has(Json.VALUES)) continue; - JsonArray valuesJ = timeStateJ.getAsJsonArray(Tags.Json.VALUES); + JsonArray valuesJ = timeStateJ.getAsJsonArray(Json.VALUES); valuesJ.forEach(e -> { JsonObject timeValueJ = e.getAsJsonObject(); - String timeS = timeValueJ.get(Tags.Json.TIME).getAsString(); + String timeS = timeValueJ.get(Json.TIME).getAsString(); long time = ISO8601FormatFactory.getInstance().parseDate(timeS).getTime(); - String valueS = timeValueJ.get(Tags.Json.VALUE).getAsString(); + String valueS = timeValueJ.get(Json.VALUE).getAsString(); timedState.setStateFromStringAt(time, valueS); }); } @@ -164,9 +153,9 @@ public class StrolchElementFromJsonVisitor { fillElement(jsonObject, (GroupedParameterizedElement) activity); - if (!jsonObject.has(Tags.Json.TIME_ORDERING)) + if (!jsonObject.has(Json.TIME_ORDERING)) throw new StrolchException("TimeOrdering not set on " + activity.getLocator()); - String timeOrderingS = jsonObject.get(Tags.Json.TIME_ORDERING).getAsString(); + String timeOrderingS = jsonObject.get(Json.TIME_ORDERING).getAsString(); TimeOrdering timeOrdering = TimeOrdering.parse(timeOrderingS); activity.setTimeOrdering(timeOrdering); @@ -177,23 +166,23 @@ public class StrolchElementFromJsonVisitor { if (defs.hasPolicyDefs()) activity.setPolicyDefs(defs); - if (!jsonObject.has(Tags.Json.ELEMENTS)) + if (!jsonObject.has(Json.ELEMENTS)) return; - JsonArray elementsJsonArray = jsonObject.getAsJsonArray(Tags.Json.ELEMENTS); + JsonArray elementsJsonArray = jsonObject.getAsJsonArray(Json.ELEMENTS); elementsJsonArray.forEach(e -> { JsonObject elementJsonObject = e.getAsJsonObject(); - String objectType = elementJsonObject.get(Tags.Json.OBJECT_TYPE).getAsString(); + String objectType = elementJsonObject.get(Json.OBJECT_TYPE).getAsString(); switch (objectType) { - case Tags.Json.ACTIVITY: + case Json.ACTIVITY: Activity childActivity = new Activity(); fillElement(elementJsonObject, childActivity); activity.addElement(childActivity); break; - case Tags.Json.ACTION: + case Json.ACTION: Action childAction = new Action(); fillElement(elementJsonObject, childAction); activity.addElement(childAction); @@ -208,9 +197,9 @@ public class StrolchElementFromJsonVisitor { } protected void fillElement(JsonObject jsonObject, AbstractStrolchElement strolchElement) { - if (jsonObject.has(Tags.Json.ID) && jsonObject.has(Tags.Json.NAME)) { - strolchElement.setId(jsonObject.get(Tags.Json.ID).getAsString()); - strolchElement.setName(jsonObject.get(Tags.Json.NAME).getAsString()); + if (jsonObject.has(Json.ID) && jsonObject.has(Json.NAME)) { + strolchElement.setId(jsonObject.get(Json.ID).getAsString()); + strolchElement.setName(jsonObject.get(Json.NAME).getAsString()); } else { String msg = "Check the values of the jsonObject: {0} either id or name attribute is null!"; //$NON-NLS-1$ msg = MessageFormat.format(msg, jsonObject); @@ -221,8 +210,8 @@ public class StrolchElementFromJsonVisitor { protected void fillElement(JsonObject jsonObject, GroupedParameterizedElement groupedParameterizedElement) { fillElement(jsonObject, (AbstractStrolchElement) groupedParameterizedElement); - if (jsonObject.has(Tags.Json.TYPE)) { - groupedParameterizedElement.setType(jsonObject.get(Tags.Json.TYPE).getAsString()); + if (jsonObject.has(Json.TYPE)) { + groupedParameterizedElement.setType(jsonObject.get(Json.TYPE).getAsString()); } else { String msg = "Check the values of the jsonObject: {0} type attribute is null!"; //$NON-NLS-1$ msg = MessageFormat.format(msg, jsonObject); @@ -230,10 +219,10 @@ public class StrolchElementFromJsonVisitor { } // add all the parameter bags - if (!jsonObject.has(Tags.Json.PARAMETER_BAGS)) + if (!jsonObject.has(Json.PARAMETER_BAGS)) return; - JsonObject bagsJsonObject = jsonObject.getAsJsonObject(Tags.Json.PARAMETER_BAGS); + JsonObject bagsJsonObject = jsonObject.getAsJsonObject(Json.PARAMETER_BAGS); Set> bags = bagsJsonObject.entrySet(); for (Entry entry : bags) { @@ -261,8 +250,8 @@ public class StrolchElementFromJsonVisitor { protected void fillElement(JsonObject jsonObject, ParameterizedElement parameterizedElement) { fillElement(jsonObject, (AbstractStrolchElement) parameterizedElement); - if (jsonObject.has(Tags.Json.TYPE)) { - parameterizedElement.setType(jsonObject.get(Tags.Json.TYPE).getAsString()); + if (jsonObject.has(Json.TYPE)) { + parameterizedElement.setType(jsonObject.get(Json.TYPE).getAsString()); } else { String msg = "Check the values of the jsonObject: {0} type attribute is null!"; //$NON-NLS-1$ msg = MessageFormat.format(msg, jsonObject); @@ -270,10 +259,10 @@ public class StrolchElementFromJsonVisitor { } // add all the parameters - if (!jsonObject.has(Tags.Json.PARAMETERS)) + if (!jsonObject.has(Json.PARAMETERS)) return; - JsonObject parametersJsonObject = jsonObject.getAsJsonObject(Tags.Json.PARAMETERS); + JsonObject parametersJsonObject = jsonObject.getAsJsonObject(Json.PARAMETERS); Set> parameters = parametersJsonObject.entrySet(); for (Entry entry : parameters) { String paramId = entry.getKey(); @@ -285,7 +274,7 @@ public class StrolchElementFromJsonVisitor { } JsonObject paramJsonObject = jsonElement.getAsJsonObject(); - String paramtype = paramJsonObject.get(Tags.Json.TYPE).getAsString(); + String paramtype = paramJsonObject.get(Json.TYPE).getAsString(); StrolchValueType paramValueType = StrolchValueType.parse(paramtype); Parameter parameter = paramValueType.parameterInstance(); @@ -303,16 +292,16 @@ public class StrolchElementFromJsonVisitor { protected void fillElement(JsonObject jsonObject, Parameter param) { fillElement(jsonObject, (AbstractStrolchElement) param); - if (jsonObject.has(Tags.Json.INTERPRETATION)) - param.setInterpretation(jsonObject.get(Tags.Json.INTERPRETATION).getAsString()); - if (jsonObject.has(Tags.Json.UOM)) - param.setUom(jsonObject.get(Tags.Json.UOM).getAsString()); - if (jsonObject.has(Tags.Json.INDEX)) - param.setIndex(jsonObject.get(Tags.Json.INDEX).getAsInt()); - if (jsonObject.has(Tags.Json.HIDDEN)) - param.setHidden(jsonObject.get(Tags.Json.HIDDEN).getAsBoolean()); + if (jsonObject.has(Json.INTERPRETATION)) + param.setInterpretation(jsonObject.get(Json.INTERPRETATION).getAsString()); + if (jsonObject.has(Json.UOM)) + param.setUom(jsonObject.get(Json.UOM).getAsString()); + if (jsonObject.has(Json.INDEX)) + param.setIndex(jsonObject.get(Json.INDEX).getAsInt()); + if (jsonObject.has(Json.HIDDEN)) + param.setHidden(jsonObject.get(Json.HIDDEN).getAsBoolean()); - String value = jsonObject.get(Tags.Json.VALUE).getAsString(); + String value = jsonObject.get(Json.VALUE).getAsString(); param.setValueFromString(value); } @@ -320,12 +309,12 @@ public class StrolchElementFromJsonVisitor { fillElement(jsonObject, (GroupedParameterizedElement) action); // attributes - if (jsonObject.has(Tags.Json.RESOURCE_ID)) - action.setResourceId(jsonObject.get(Tags.Json.RESOURCE_ID).getAsString()); - if (jsonObject.has(Tags.Json.RESOURCE_TYPE)) - action.setResourceType(jsonObject.get(Tags.Json.RESOURCE_TYPE).getAsString()); - if (jsonObject.has(Tags.Json.STATE)) - action.setState(State.parse(jsonObject.get(Tags.Json.STATE).getAsString())); + if (jsonObject.has(Json.RESOURCE_ID)) + action.setResourceId(jsonObject.get(Json.RESOURCE_ID).getAsString()); + if (jsonObject.has(Json.RESOURCE_TYPE)) + action.setResourceType(jsonObject.get(Json.RESOURCE_TYPE).getAsString()); + if (jsonObject.has(Json.STATE)) + action.setState(State.parse(jsonObject.get(Json.STATE).getAsString())); // policies PolicyDefs defs = parsePolicies(jsonObject); @@ -333,18 +322,18 @@ public class StrolchElementFromJsonVisitor { action.setPolicyDefs(defs); // value changes - if (!jsonObject.has(Tags.Json.VALUE_CHANGES)) + if (!jsonObject.has(Json.VALUE_CHANGES)) return; - JsonArray valueChangesJ = jsonObject.getAsJsonArray(Tags.Json.VALUE_CHANGES); + JsonArray valueChangesJ = jsonObject.getAsJsonArray(Json.VALUE_CHANGES); valueChangesJ.forEach(e -> { try { JsonObject valueChangeJ = e.getAsJsonObject(); - String stateId = valueChangeJ.get(Tags.Json.STATE_ID).getAsString(); - String timeS = valueChangeJ.get(Tags.Json.TIME).getAsString(); - String valueS = valueChangeJ.get(Tags.Json.VALUE).getAsString(); - String typeS = valueChangeJ.get(Tags.Json.TYPE).getAsString(); + String stateId = valueChangeJ.has(Json.STATE_ID) ? valueChangeJ.get(Json.STATE_ID).getAsString() : ""; + String timeS = valueChangeJ.get(Json.TIME).getAsString(); + String valueS = valueChangeJ.get(Json.VALUE).getAsString(); + String typeS = valueChangeJ.get(Json.TYPE).getAsString(); StrolchValueType type = StrolchValueType.parse(typeS); IValue value = type.valueInstance(valueS); @@ -366,10 +355,10 @@ public class StrolchElementFromJsonVisitor { PolicyDefs policyDefs = new PolicyDefs(); - if (!jsonObject.has(Tags.Json.POLICIES)) + if (!jsonObject.has(Json.POLICIES)) return policyDefs; - JsonObject policiesJsonObject = jsonObject.getAsJsonObject(Tags.Json.POLICIES); + JsonObject policiesJsonObject = jsonObject.getAsJsonObject(Json.POLICIES); Set> entrySet = policiesJsonObject.entrySet(); for (Entry entry : entrySet) { @@ -385,16 +374,16 @@ public class StrolchElementFromJsonVisitor { protected void parseVersion(StrolchRootElement rootElement, JsonObject jsonObject) { - if (!jsonObject.has(Tags.Json.VERSION)) + if (!jsonObject.has(Json.VERSION)) return; - JsonObject versionJ = jsonObject.getAsJsonObject(Tags.Json.VERSION); + JsonObject versionJ = jsonObject.getAsJsonObject(Json.VERSION); - int v = versionJ.get(Tags.Json.VERSION).getAsInt(); - String createdBy = versionJ.get(Tags.Json.CREATED_BY).getAsString(); - String createdAtS = versionJ.get(Tags.Json.CREATED_AT).getAsString(); + int v = versionJ.get(Json.VERSION).getAsInt(); + String createdBy = versionJ.get(Json.CREATED_BY).getAsString(); + String createdAtS = versionJ.get(Json.CREATED_AT).getAsString(); Date createdAt = ISO8601FormatFactory.getInstance().parseDate(createdAtS); - boolean deleted = versionJ.get(Tags.Json.DELETED).getAsBoolean(); + boolean deleted = versionJ.get(Json.DELETED).getAsBoolean(); Version version = new Version(rootElement.getLocator(), v, createdBy, createdAt, deleted); rootElement.setVersion(version); diff --git a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java index 25f94c724..fbd2f2ac2 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/json/StrolchElementToJsonVisitor.java @@ -1,5 +1,7 @@ package li.strolch.model.json; +import static li.strolch.utils.helper.StringHelper.isNotEmpty; + import java.util.*; import java.util.Map.Entry; import java.util.function.BiConsumer; @@ -10,6 +12,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import li.strolch.exception.StrolchModelException; import li.strolch.model.*; +import li.strolch.model.Tags.Json; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; @@ -268,7 +271,7 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor> valueChange = iter.next(); JsonObject changeJ = new JsonObject(); - changeJ.addProperty(Tags.Json.STATE_ID, valueChange.getStateId()); - changeJ.addProperty(Tags.Json.TIME, formatDate(valueChange.getTime())); - changeJ.addProperty(Tags.Json.VALUE, valueChange.getValue().getValueAsString()); - changeJ.addProperty(Tags.Json.TYPE, valueChange.getValue().getType()); + if (isNotEmpty(valueChange.getStateId())) + changeJ.addProperty(Json.STATE_ID, valueChange.getStateId()); + changeJ.addProperty(Json.TIME, formatDate(valueChange.getTime())); + changeJ.addProperty(Json.VALUE, valueChange.getValue().getValueAsString()); + changeJ.addProperty(Json.TYPE, valueChange.getValue().getType()); changesJ.add(changeJ); } @@ -409,7 +413,7 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor param = bag.getParameter(paramKey); @@ -521,18 +525,18 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor>> values = state.getTimeEvolution().getValues(); for (ITimeValue> value : values) { @@ -602,8 +606,8 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor> v : timeEvolution.getValues()) { JsonObject obj = new JsonObject(); - obj.addProperty(Tags.Json.DATE, ISO8601FormatFactory.getInstance().formatDate(v.getTime())); - obj.addProperty(Tags.Json.VALUE, v.getValue().getValueAsString()); + obj.addProperty(Json.DATE, ISO8601FormatFactory.getInstance().formatDate(v.getTime())); + obj.addProperty(Json.VALUE, v.getValue().getValueAsString()); arrayJ.add(obj); } @@ -632,11 +636,11 @@ public class StrolchElementToJsonVisitor implements StrolchElementVisitor implements IValueChange, Serializa public ValueChange(final Long time, final T value, final String stateId) { this.time = time; this.value = value; - this.stateId = stateId; + this.stateId = trimOrEmpty(stateId); } @Override diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java index 153e111ee..c6b711dcd 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToDomVisitor.java @@ -1,12 +1,12 @@ /* * Copyright 2015 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,25 +15,14 @@ */ package li.strolch.model.xml; +import static li.strolch.utils.helper.StringHelper.isNotEmpty; + +import javax.xml.parsers.DocumentBuilder; import java.util.Iterator; import java.util.Map.Entry; import java.util.SortedSet; -import javax.xml.parsers.DocumentBuilder; - -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import li.strolch.model.AbstractStrolchElement; -import li.strolch.model.GroupedParameterizedElement; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.ParameterizedElement; -import li.strolch.model.Resource; -import li.strolch.model.StrolchModelConstants; -import li.strolch.model.StrolchRootElement; -import li.strolch.model.Tags; -import li.strolch.model.Version; +import li.strolch.model.*; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; @@ -46,8 +35,9 @@ import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.visitor.StrolchRootElementVisitor; import li.strolch.utils.helper.DomUtil; -import li.strolch.utils.helper.StringHelper; import li.strolch.utils.iso8601.ISO8601FormatFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; /** * @author Robert von Burg @@ -144,9 +134,9 @@ public class StrolchElementToDomVisitor implements StrolchRootElementVisitor> value) { Element element = document.createElement(Tags.VALUE_CHANGE); - element.setAttribute(Tags.STATE_ID, value.getStateId()); + if (isNotEmpty(value.getStateId())) + element.setAttribute(Tags.STATE_ID, value.getStateId()); element.setAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(value.getTime())); element.setAttribute(Tags.VALUE, value.getValue().getValueAsString()); element.setAttribute(Tags.TYPE, value.getValue().getType()); diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java index 9aacb13f9..c46ada973 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxVisitor.java @@ -17,6 +17,7 @@ package li.strolch.model.xml; import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; import static li.strolch.model.StrolchModelConstants.UOM_NONE; +import static li.strolch.utils.helper.StringHelper.isNotEmpty; import java.text.MessageFormat; import java.util.Iterator; @@ -24,19 +25,7 @@ import java.util.Map.Entry; import java.util.Set; import java.util.SortedSet; -import org.xml.sax.Attributes; -import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.AttributesImpl; - -import li.strolch.model.GroupedParameterizedElement; -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.StrolchElement; -import li.strolch.model.StrolchRootElement; -import li.strolch.model.Tags; -import li.strolch.model.Version; +import li.strolch.model.*; import li.strolch.model.activity.Action; import li.strolch.model.activity.Activity; import li.strolch.model.activity.IActivityElement; @@ -48,8 +37,11 @@ import li.strolch.model.timevalue.ITimeValue; import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.visitor.StrolchRootElementVisitor; -import li.strolch.utils.helper.StringHelper; import li.strolch.utils.iso8601.ISO8601FormatFactory; +import org.xml.sax.Attributes; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.AttributesImpl; /** * @author Robert von Burg @@ -328,10 +320,10 @@ public class StrolchElementToSaxVisitor implements StrolchRootElementVisitor> valueChange) { AttributesImpl attributes = new AttributesImpl(); - if (StringHelper.isNotEmpty(valueChange.getStateId())) + if (isNotEmpty(valueChange.getStateId())) attributes.addAttribute(null, null, Tags.STATE_ID, Tags.CDATA, valueChange.getStateId()); attributes.addAttribute(null, null, Tags.TIME, Tags.CDATA, diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxWriterVisitor.java b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxWriterVisitor.java index fefc07dd4..872e14ed3 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxWriterVisitor.java +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/StrolchElementToSaxWriterVisitor.java @@ -17,6 +17,7 @@ package li.strolch.model.xml; import static li.strolch.model.StrolchModelConstants.INTERPRETATION_NONE; import static li.strolch.model.StrolchModelConstants.UOM_NONE; +import static li.strolch.utils.helper.StringHelper.isNotEmpty; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; @@ -38,7 +39,6 @@ import li.strolch.model.timevalue.ITimeVariable; import li.strolch.model.timevalue.IValue; import li.strolch.model.timevalue.IValueChange; import li.strolch.model.visitor.StrolchRootElementVisitor; -import li.strolch.utils.helper.StringHelper; import li.strolch.utils.iso8601.ISO8601FormatFactory; /** @@ -186,9 +186,9 @@ public class StrolchElementToSaxWriterVisitor implements StrolchRootElementVisit writeStartStrolchElement(Tags.ACTION, empty, action); this.writer.writeAttribute(Tags.STATE, action.getState().getName()); - if (StringHelper.isNotEmpty(action.getResourceId())) + if (isNotEmpty(action.getResourceId())) this.writer.writeAttribute(Tags.RESOURCE_ID, action.getResourceId()); - if (StringHelper.isNotEmpty(action.getResourceType())) + if (isNotEmpty(action.getResourceType())) this.writer.writeAttribute(Tags.RESOURCE_TYPE, action.getResourceType()); if (action.hasParameterBags()) @@ -197,7 +197,8 @@ public class StrolchElementToSaxWriterVisitor implements StrolchRootElementVisit if (action.hasChanges()) { for (IValueChange> change : action.getChanges()) { this.writer.writeEmptyElement(Tags.VALUE_CHANGE); - this.writer.writeAttribute(Tags.STATE_ID, change.getStateId()); + if (isNotEmpty(change.getStateId())) + this.writer.writeAttribute(Tags.STATE_ID, change.getStateId()); this.writer.writeAttribute(Tags.TIME, ISO8601FormatFactory.getInstance().formatDate(change.getTime())); this.writer.writeAttribute(Tags.VALUE, change.getValue().getValueAsString()); this.writer.writeAttribute(Tags.TYPE, change.getValue().getType()); diff --git a/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java b/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java index 97777238b..5c614e729 100644 --- a/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java +++ b/li.strolch.model/src/main/java/li/strolch/model/xml/XmlModelSaxReader.java @@ -1,12 +1,12 @@ /* * Copyright 2013 Robert von Burg - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.