use of net.fortuna.ical4j.model.parameter.XParameter in project bw-calendar-engine by Bedework.
the class VEventUtil method mergeXparams.
/* ====================================================================
Private methods
==================================================================== */
private static void mergeXparams(final Property p, final Component c) {
if (c == null) {
return;
}
PropertyList pl = c.getProperties(p.getName());
if (Util.isEmpty(pl)) {
return;
}
String pval = p.getValue();
if (p instanceof Attach) {
// We just saved the hash for binary content
Value v = (Value) p.getParameter(Parameter.VALUE);
if (v != null) {
pval = String.valueOf(pval.hashCode());
}
}
Property from = null;
if (pl.size() == 1) {
from = (Property) pl.get(0);
} else {
// Look for value?
Iterator pit = pl.iterator();
while (pit.hasNext()) {
from = (Property) pit.next();
if (from.getValue().equals(pval)) {
break;
}
}
}
if (from == null) {
return;
}
ParameterList params = from.getParameters();
Iterator parit = params.iterator();
while (parit.hasNext()) {
Parameter param = (Parameter) parit.next();
if (!(param instanceof XParameter)) {
continue;
}
XParameter xpar = (XParameter) param;
if (xpar.getName().toUpperCase().equals(BwXproperty.xparUid)) {
continue;
}
p.getParameters().add(xpar);
}
}
use of net.fortuna.ical4j.model.parameter.XParameter in project bw-calendar-engine by Bedework.
the class BwEventUtil method testXparams.
/* ====================================================================
Private methods
==================================================================== */
private static void testXparams(final Property p, final Holder<Boolean> hasXparams) {
if (hasXparams.value) {
// No need to check
return;
}
ParameterList params = p.getParameters();
Iterator parit = params.iterator();
while (parit.hasNext()) {
Parameter param = (Parameter) parit.next();
if (!(param instanceof XParameter)) {
continue;
}
XParameter xpar = (XParameter) param;
if (xpar.getName().toUpperCase().equals(BwXproperty.xparUid)) {
continue;
}
hasXparams.value = true;
}
}
use of net.fortuna.ical4j.model.parameter.XParameter in project ofbiz-framework by apache.
the class ICalConverter method loadRelatedParties.
protected static void loadRelatedParties(List<GenericValue> relatedParties, PropertyList componentProps, Map<String, Object> context) {
PropertyList attendees = componentProps.getProperties("ATTENDEE");
for (GenericValue partyValue : relatedParties) {
if ("CAL_ORGANIZER~CAL_OWNER".contains(partyValue.getString("roleTypeId"))) {
// RFC 2445 4.6.1, 4.6.2, and 4.6.3 ORGANIZER can appear only once
replaceProperty(componentProps, createOrganizer(partyValue, context));
} else {
String partyId = partyValue.getString("partyId");
boolean newAttendee = true;
Attendee attendee = null;
Iterator<Attendee> i = UtilGenerics.cast(attendees.iterator());
while (i.hasNext()) {
attendee = i.next();
Parameter xParameter = attendee.getParameter(partyIdXParamName);
if (xParameter != null && partyId.equals(xParameter.getValue())) {
loadPartyAssignment(attendee, partyValue, context);
newAttendee = false;
break;
}
}
if (newAttendee) {
attendee = createAttendee(partyValue, context);
componentProps.add(attendee);
}
}
}
}
use of net.fortuna.ical4j.model.parameter.XParameter in project opencast by opencast.
the class CalendarGenerator method addEvent.
/**
* Adds an SchedulerEvent as a new entry to this iCalendar
*
* @param mp
* {@link MediaPackage} of event
* @param agentId
* the agent identifier
* @param start
* the start date
* @param end
* the end date
* @param captureAgentMetadata
* properties for capture agent metadata
*
* @return true if the event could be added.
*/
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
String eventId = mp.getIdentifier().compact();
logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
DateTime startDate = new DateTime(start);
DateTime endDate = new DateTime(end);
Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
if (marginEndDate.before(new Date())) {
logger.debug("Event has already passed more than an hour, skipping!");
return false;
}
startDate.setUtc(true);
endDate.setUtc(true);
String seriesID = null;
VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
try {
ParameterList pl = new ParameterList();
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
}
event.getProperties().add(new Uid(eventId));
DateTime lastModifiedDate = new DateTime(lastModified);
lastModifiedDate.setUtc(true);
event.getProperties().add(new LastModified(lastModifiedDate));
// TODO Organizer should be URI (email-address?) created fake address
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
event.getProperties().add(new Organizer(pl, organizer));
}
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
}
event.getProperties().add(new Location(agentId));
if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
event.getProperties().add(new RelatedTo(seriesID));
}
ParameterList dcParameters = new ParameterList();
dcParameters.add(new FmtType("application/xml"));
dcParameters.add(Value.BINARY);
dcParameters.add(Encoding.BASE64);
dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
event.getProperties().add(metadataAttachment);
String seriesDC = getSeriesDublinCoreAsString(seriesID);
if (seriesDC != null) {
logger.debug("Attaching series {} information to event {}", seriesID, eventId);
ParameterList sDcParameters = new ParameterList();
sDcParameters.add(new FmtType("application/xml"));
sDcParameters.add(Value.BINARY);
sDcParameters.add(Encoding.BASE64);
sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
event.getProperties().add(seriesAttachment);
} else {
logger.debug("No series provided for event {}.", eventId);
}
ParameterList caParameters = new ParameterList();
caParameters.add(new FmtType("application/text"));
caParameters.add(Value.BINARY);
caParameters.add(Encoding.BASE64);
caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
event.getProperties().add(agentsAttachment);
} catch (Exception e) {
logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
return false;
}
cal.getComponents().add(event);
logger.debug("new VEvent = {} ", event.toString());
return true;
}
use of net.fortuna.ical4j.model.parameter.XParameter in project zm-mailbox by Zimbra.
the class TestUserServlet method testIcsImportExport.
/**
* Test that can import into a new calendar from ICALENDAR containing an inline ATTACHment.
* Test that it is possible to export calendar entry with an attachment with the attachment
* inlined if icalAttach=inline or ignoring the attachment if icalAttach=none
* @throws Exception
*/
@Test
public void testIcsImportExport() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String calName = NAME_PREFIX + "2ndCalendar";
String calUri = String.format("/%s?fmt=ics", calName);
TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
calendar.getProperties().add(new ProdId("-//ZimbraTest 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
java.util.Calendar start = java.util.Calendar.getInstance();
start.set(java.util.Calendar.MONTH, java.util.Calendar.SEPTEMBER);
start.set(java.util.Calendar.DAY_OF_MONTH, 03);
VEvent wwII = new VEvent(new Date(start.getTime()), NAME_PREFIX + " Declarations of war");
wwII.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
wwII.getProperties().add(new Uid("3-14159"));
Attach attach = new Attach("Attachment.\nIsn't it short.".getBytes(MimeConstants.P_CHARSET_ASCII));
attach.getParameters().add(new XParameter("X-APPLE-FILENAME", "short.txt"));
attach.getParameters().add(new FmtType(MimeConstants.CT_TEXT_PLAIN));
wwII.getProperties().add(attach);
calendar.getComponents().add(wwII);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, buf);
URI uri = mbox.getRestURI(calUri);
HttpClient client = mbox.getHttpClient(uri);
HttpPost post = new HttpPost(uri.toString());
post.setEntity(new InputStreamEntity(new ByteArrayInputStream(buf.toByteArray()), ContentType.create(MimeConstants.CT_TEXT_CALENDAR)));
ZimbraLog.test.info("testIcsImportExport:ICS to be imported:%s", new String(buf.toByteArray()));
TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
uri = mbox.getRestURI(calUri + "&icalAttach=inline");
HttpGet get = new HttpGet(uri.toString());
TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.info("testIcsImportExport:ICS exported (with icalAttach=inline):%s", respIcal);
int attachNdx = respIcal.indexOf("ATTACH;");
Assert.assertTrue("ATTACH should be present", -1 != attachNdx);
String fromAttach = respIcal.substring(attachNdx);
Assert.assertTrue("BINARY should be present", -1 != fromAttach.indexOf("VALUE=BINARY"));
uri = mbox.getRestURI(calUri + "&icalAttach=none");
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (with icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
uri = mbox.getRestURI(calUri);
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (default - same as icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
}
Aggregations