Search in sources :

Example 1 with TextPropertyType

use of ietf.params.xml.ns.icalendar_2.TextPropertyType in project bw-calendar-engine by Bedework.

the class LocationPropUpdater method applyUpdate.

@Override
public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final BwEvent ev = ui.getEvent();
        final ChangeTableEntry cte = ui.getCte();
        BwString val = new BwString(UpdaterUtil.getLang(ui.getProp()), ((TextPropertyType) ui.getProp()).getText());
        final BwLocation evLoc = ev.getLocation();
        BwString evVal = null;
        if (evLoc != null) {
            evVal = evLoc.getAddress();
        }
        if (ui.isRemove()) {
            if (evVal == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot remove");
            }
            val = null;
        } else if (ui.isAdd()) {
            if (evVal != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
        } else if (!ui.isChange()) {
            final ParameterUpdater.UpdateInfo langUpd = UpdaterUtil.findLangUpdate(ui.getParamUpdates());
            if (langUpd == null) {
                return new UpdateResult("No update specified for " + ui.getPropName());
            }
            String lang = val.getLang();
            if (langUpd.isRemove()) {
                lang = null;
            } else if (langUpd.isAdd()) {
                lang = ((TextParameterType) langUpd.getParam()).getText();
            } else if (langUpd.getUpdparam() != null) {
                lang = ((TextParameterType) langUpd.getUpdparam()).getText();
            }
            if (!Util.equalsString(lang, val.getLang())) {
                val = new BwString(lang, val.getValue());
            }
        } else {
            if (!val.equals(evVal)) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            val = new BwString(UpdaterUtil.getLang(ui.getUpdprop()), ((TextPropertyType) ui.getUpdprop()).getText());
        }
        if (val == null) {
            cte.setDeleted(ev.getLocation());
            ev.setLocation(null);
        } else if (Util.cmpObjval(val, evVal) != 0) {
            BwLocation loc = ui.getIcalCallback().findLocation(val);
            if (loc == null) {
                loc = BwLocation.makeLocation();
                loc.setAddress(val);
                ui.getIcalCallback().addLocation(loc);
            }
            if (cte.setChanged(evLoc, loc)) {
                ev.setLocation(loc);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) TextParameterType(ietf.params.xml.ns.icalendar_2.TextParameterType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) ParameterUpdater(org.bedework.caldav.bwserver.ParameterUpdater) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 2 with TextPropertyType

use of ietf.params.xml.ns.icalendar_2.TextPropertyType in project arctic-sea by 52North.

the class SweCommonDecoderV20 method decode.

@Override
public Object decode(Object element) throws DecodingException {
    if (element instanceof DataArrayPropertyType) {
        final DataArrayPropertyType dataArrayPropertyType = (DataArrayPropertyType) element;
        return parseAbstractDataComponent(dataArrayPropertyType.getDataArray1());
    } else if (element instanceof DataRecordPropertyType) {
        final DataRecordPropertyType dataRecordPropertyType = (DataRecordPropertyType) element;
        return parseAbstractDataComponent(dataRecordPropertyType.getDataRecord());
    } else if (element instanceof AbstractDataComponentDocument) {
        return parseAbstractDataComponentDocument((AbstractDataComponentDocument) element);
    } else if (element instanceof AbstractDataComponentType) {
        return parseAbstractDataComponent((AbstractDataComponentType) element);
    } else if (element instanceof Coordinate[]) {
        return parseCoordinates((Coordinate[]) element);
    } else if (element instanceof AnyScalarPropertyType[]) {
        return parseAnyScalarPropertyTypeArray((AnyScalarPropertyType[]) element);
    } else if (element instanceof TextEncodingDocument) {
        final TextEncodingDocument textEncodingDoc = (TextEncodingDocument) element;
        final SweTextEncoding sosTextEncoding = parseTextEncoding(textEncodingDoc.getTextEncoding());
        sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
        return sosTextEncoding;
    } else if (element instanceof TextEncodingType) {
        TextEncodingDocument textEncodingDoc = TextEncodingDocument.Factory.newInstance(getXmlOptions());
        TextEncodingType textEncoding = (TextEncodingType) element;
        textEncodingDoc.setTextEncoding(textEncoding);
        SweTextEncoding sosTextEncoding = parseTextEncoding(textEncoding);
        sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
        return sosTextEncoding;
    } else if (element instanceof TextPropertyType) {
        return parseAbstractDataComponent(((TextPropertyType) element).getText());
    } else if (element instanceof CountPropertyType) {
        return parseAbstractDataComponent(((CountPropertyType) element).getCount());
    } else if (element instanceof BooleanPropertyType) {
        return parseAbstractDataComponent(((BooleanPropertyType) element).getBoolean());
    } else if (element instanceof CategoryPropertyType) {
        return parseAbstractDataComponent(((CategoryPropertyType) element).getCategory());
    } else if (element instanceof QuantityPropertyType) {
        return parseAbstractDataComponent(((QuantityPropertyType) element).getQuantity());
    } else if (element instanceof DataStreamPropertyType) {
        return parseDataStream(((DataStreamPropertyType) element).getDataStream());
    } else if (element instanceof DataStreamType) {
        return parseDataStream((DataStreamType) element);
    } else if (element instanceof DataStreamDocument) {
        return parseDataStream(((DataStreamDocument) element).getDataStream());
    } else if (element instanceof XmlObject) {
        throw new UnsupportedDecoderXmlInputException(this, (XmlObject) element);
    } else {
        throw new UnsupportedDecoderInputException(this, element);
    }
}
Also used : TextEncodingDocument(net.opengis.swe.x20.TextEncodingDocument) DataStreamDocument(net.opengis.swe.x20.DataStreamDocument) AnyScalarPropertyType(net.opengis.swe.x20.AnyScalarPropertyType) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) AbstractDataComponentType(net.opengis.swe.x20.AbstractDataComponentType) TextEncodingType(net.opengis.swe.x20.TextEncodingType) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) Coordinate(net.opengis.swe.x20.VectorType.Coordinate) CountPropertyType(net.opengis.swe.x20.CountPropertyType) DataStreamType(net.opengis.swe.x20.DataStreamType) DataStreamPropertyType(net.opengis.swe.x20.DataStreamPropertyType) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) TextPropertyType(net.opengis.swe.x20.TextPropertyType) AbstractDataComponentDocument(net.opengis.swe.x20.AbstractDataComponentDocument) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType)

Example 3 with TextPropertyType

use of ietf.params.xml.ns.icalendar_2.TextPropertyType in project arctic-sea by 52North.

the class SweCommonEncoderv20 method asPropertyType.

private XmlObject asPropertyType(AbstractDataComponentType type) throws NotYetSupportedEncodingException {
    if (type instanceof BooleanType) {
        BooleanPropertyType propertyType = BooleanPropertyType.Factory.newInstance();
        propertyType.setBoolean((BooleanType) type);
        return propertyType;
    } else if (type instanceof CountType) {
        CountPropertyType propertyType = CountPropertyType.Factory.newInstance();
        propertyType.setCount((CountType) type);
        return propertyType;
    } else if (type instanceof CountRangeType) {
        CountRangePropertyType propertyType = CountRangePropertyType.Factory.newInstance();
        propertyType.setCountRange((CountRangeType) type);
        return propertyType;
    } else if (type instanceof QuantityType) {
        QuantityPropertyType propertyType = QuantityPropertyType.Factory.newInstance();
        propertyType.setQuantity((QuantityType) type);
        return propertyType;
    } else if (type instanceof QuantityRangeType) {
        QuantityRangePropertyType propertyType = QuantityRangePropertyType.Factory.newInstance();
        propertyType.setQuantityRange((QuantityRangeType) type);
        return propertyType;
    } else if (type instanceof TimeType) {
        TimePropertyType propertyType = TimePropertyType.Factory.newInstance();
        propertyType.setTime((TimeType) type);
        return propertyType;
    } else if (type instanceof TimeRangeType) {
        TimeRangePropertyType propertyType = TimeRangePropertyType.Factory.newInstance();
        propertyType.setTimeRange((TimeRangeType) type);
        return propertyType;
    } else if (type instanceof CategoryType) {
        CategoryPropertyType propertyType = CategoryPropertyType.Factory.newInstance();
        propertyType.setCategory((CategoryType) type);
        return propertyType;
    } else if (type instanceof CategoryRangeType) {
        CategoryRangePropertyType propertyType = CategoryRangePropertyType.Factory.newInstance();
        propertyType.setCategoryRange((CategoryRangeType) type);
        return propertyType;
    } else if (type instanceof MatrixType) {
        MatrixPropertyType propertyType = MatrixPropertyType.Factory.newInstance();
        propertyType.setMatrix((MatrixType) type);
        return propertyType;
    } else if (type instanceof DataArrayType) {
        DataArrayPropertyType propertyType = DataArrayPropertyType.Factory.newInstance();
        propertyType.setDataArray1((DataArrayType) type);
        return propertyType;
    } else if (type instanceof DataChoiceType) {
        DataChoicePropertyType propertyType = DataChoicePropertyType.Factory.newInstance();
        propertyType.setDataChoice((DataChoiceType) type);
        return propertyType;
    } else if (type instanceof DataRecordType) {
        DataRecordPropertyType propertyType = DataRecordPropertyType.Factory.newInstance();
        propertyType.setDataRecord((DataRecordType) type);
        return propertyType;
    } else if (type instanceof TextType) {
        TextPropertyType propertyType = TextPropertyType.Factory.newInstance();
        propertyType.setText((TextType) type);
        return propertyType;
    } else if (type instanceof VectorType) {
        VectorPropertyType propertyType = VectorPropertyType.Factory.newInstance();
        propertyType.setVector((VectorType) type);
        return propertyType;
    } else {
        throw new NotYetSupportedEncodingException(type.getClass().getName(), type);
    }
}
Also used : DataRecordType(net.opengis.swe.x20.DataRecordType) CategoryRangeType(net.opengis.swe.x20.CategoryRangeType) MatrixPropertyType(net.opengis.swe.x20.MatrixPropertyType) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) CategoryType(net.opengis.swe.x20.CategoryType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) TimeRangePropertyType(net.opengis.swe.x20.TimeRangePropertyType) CountType(net.opengis.swe.x20.CountType) TimeType(net.opengis.swe.x20.TimeType) VectorPropertyType(net.opengis.swe.x20.VectorPropertyType) CountPropertyType(net.opengis.swe.x20.CountPropertyType) CountRangeType(net.opengis.swe.x20.CountRangeType) DataChoiceType(net.opengis.swe.x20.DataChoiceType) VectorType(net.opengis.swe.x20.VectorType) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) TextPropertyType(net.opengis.swe.x20.TextPropertyType) CountRangePropertyType(net.opengis.swe.x20.CountRangePropertyType) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) DataChoicePropertyType(net.opengis.swe.x20.DataChoicePropertyType) DataArrayType(net.opengis.swe.x20.DataArrayType) QuantityRangePropertyType(net.opengis.swe.x20.QuantityRangePropertyType) CategoryRangePropertyType(net.opengis.swe.x20.CategoryRangePropertyType) BooleanType(net.opengis.swe.x20.BooleanType) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) TextType(net.opengis.swe.x20.TextType) TimeRangeType(net.opengis.swe.x20.TimeRangeType) QuantityType(net.opengis.swe.x20.QuantityType) MatrixType(net.opengis.swe.x20.MatrixType) TimePropertyType(net.opengis.swe.x20.TimePropertyType) QuantityRangeType(net.opengis.swe.x20.QuantityRangeType) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType)

Example 4 with TextPropertyType

use of ietf.params.xml.ns.icalendar_2.TextPropertyType in project bw-calendar-engine by Bedework.

the class XbwContactPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xcontacts = ev.getXproperties(BwXproperty.xBedeworkContact);
        final Set<BwContact> contacts = ev.getContacts();
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BwString cstr = new BwString(lang, xval);
        if (ui.isRemove()) {
            if (Util.isEmpty(xcontacts)) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            for (final BwXproperty xp : xcontacts) {
                if (!xp.getValue().equals(xval)) {
                    continue;
                }
                // Found
                ev.removeXproperty(xp);
                cte.addRemovedValue(xp);
                /* Do we have a corresponding contact */
                for (final BwContact c : contacts) {
                    if (c.getCn().equals(cstr)) {
                        ev.removeContact(c);
                        cte.addRemovedValue(c);
                        break;
                    }
                }
                return UpdateResult.getOkResult();
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    return new UpdateResult("Entity already has " + ui.getPropName() + " property with that value - cannot add");
                }
            }
            /* Add the xprop or a contact */
            if (!checkContact(ui, ev, contacts, lang, xval)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            for (final BwXproperty xp : xcontacts) {
                if (xp.getValue().equals(xval)) {
                    // Found
                    ev.removeXproperty(xp);
                    cte.addRemovedValue(xp);
                    final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
                    final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
                    if (!checkContact(ui, ev, contacts, nlang, nxval)) {
                        final BwXproperty nxp = makeXprop(nlang, nxval);
                        ev.addXproperty(nxp);
                        cte.addAddedValue(nxp);
                    }
                    return UpdateResult.getOkResult();
                }
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : BwXproperty(org.bedework.calfacade.BwXproperty) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwContact(org.bedework.calfacade.BwContact) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) BwString(org.bedework.calfacade.BwString) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 5 with TextPropertyType

use of ietf.params.xml.ns.icalendar_2.TextPropertyType in project bw-calendar-engine by Bedework.

the class XbwLocPropUpdater method applyUpdate.

public UpdateResult applyUpdate(final UpdateInfo ui) throws WebdavException {
    try {
        final ChangeTableEntry cte = ui.getCte();
        final BwEvent ev = ui.getEvent();
        final List<BwXproperty> xlocs = ev.getXproperties(xBedeworkLocation);
        // Should only be one or zero
        final BwXproperty xloc;
        if (Util.isEmpty(xlocs)) {
            xloc = null;
        } else {
            xloc = xlocs.get(0);
        }
        final String lang = UpdaterUtil.getLang(ui.getProp());
        final String xval = ((TextPropertyType) ui.getProp()).getText();
        final BaseParameterType keyParam = XcalUtil.findParam(ui.getProp(), XcalTags.xBedeworkLocationKey);
        final String keyName;
        if (keyParam != null) {
            keyName = ((TextParameterType) keyParam).getText();
        } else {
            keyName = null;
        }
        final BwLocation evLoc = ev.getLocation();
        if (ui.isRemove()) {
            if (xlocs == null) {
                // Nothing to remove
                return UpdateResult.getOkResult();
            }
            // TODO - match values?
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            if (evLoc != null) {
                ev.setLocation(null);
                cte.addRemovedValue(evLoc);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isAdd()) {
            if (xloc != null) {
                return new UpdateResult("Entity already has " + ui.getPropName() + " property - cannot add");
            }
            if (!checkLocation(ui, ev, lang, xval, null)) {
                final BwXproperty xp = makeXprop(lang, xval);
                ev.addXproperty(xp);
                cte.addAddedValue(xp);
            }
            return UpdateResult.getOkResult();
        }
        if (ui.isChange()) {
            if (xloc == null) {
                return new UpdateResult("Entity has no " + ui.getPropName() + " property - cannot change");
            }
            if (CalFacadeUtil.cmpObjval(xval, xloc.getValue()) != 0) {
                return new UpdateResult("Values don't match for update to " + ui.getPropName());
            }
            ev.removeXproperty(xloc);
            cte.addRemovedValue(xloc);
            final String nlang = UpdaterUtil.getLang(ui.getUpdprop());
            final String nxval = ((TextPropertyType) ui.getUpdprop()).getText();
            if (!checkLocation(ui, ev, nlang, nxval, keyName)) {
                final BwXproperty nxp = makeXprop(nlang, nxval);
                if (keyName != null) {
                    nxp.getParameters().add(new Xpar(XcalTags.xBedeworkLocationKey.getLocalPart(), keyName));
                }
                ev.addXproperty(nxp);
                cte.addAddedValue(nxp);
            }
        }
        return UpdateResult.getOkResult();
    } catch (final CalFacadeException cfe) {
        throw new WebdavException(cfe);
    }
}
Also used : Xpar(org.bedework.calfacade.BwXproperty.Xpar) BaseParameterType(ietf.params.xml.ns.icalendar_2.BaseParameterType) BwLocation(org.bedework.calfacade.BwLocation) BwXproperty(org.bedework.calfacade.BwXproperty) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) BwEvent(org.bedework.calfacade.BwEvent) ChangeTableEntry(org.bedework.calfacade.util.ChangeTableEntry) BwString(org.bedework.calfacade.BwString) TextPropertyType(ietf.params.xml.ns.icalendar_2.TextPropertyType) UpdateResult(org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

TextPropertyType (ietf.params.xml.ns.icalendar_2.TextPropertyType)5 BwEvent (org.bedework.calfacade.BwEvent)4 UpdateResult (org.bedework.caldav.server.sysinterface.SysIntf.UpdateResult)3 BooleanPropertyType (net.opengis.swe.x20.BooleanPropertyType)2 CategoryPropertyType (net.opengis.swe.x20.CategoryPropertyType)2 CountPropertyType (net.opengis.swe.x20.CountPropertyType)2 DataArrayPropertyType (net.opengis.swe.x20.DataArrayPropertyType)2 DataRecordPropertyType (net.opengis.swe.x20.DataRecordPropertyType)2 QuantityPropertyType (net.opengis.swe.x20.QuantityPropertyType)2 TextPropertyType (net.opengis.swe.x20.TextPropertyType)2 BwString (org.bedework.calfacade.BwString)2 BwXproperty (org.bedework.calfacade.BwXproperty)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 ChangeTableEntry (org.bedework.calfacade.util.ChangeTableEntry)2 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)2 BaseParameterType (ietf.params.xml.ns.icalendar_2.BaseParameterType)1 TextParameterType (ietf.params.xml.ns.icalendar_2.TextParameterType)1 AbstractDataComponentDocument (net.opengis.swe.x20.AbstractDataComponentDocument)1 AbstractDataComponentType (net.opengis.swe.x20.AbstractDataComponentType)1 AnyScalarPropertyType (net.opengis.swe.x20.AnyScalarPropertyType)1