Search in sources :

Example 6 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class FilterBuilder method buildFilter.

/**
 * Build a filter from the given path. The applyFilter flag only
 * applies to the root of the tree. The filter may already have been
 * processed by the caller.
 *
 * @param path
 * @param applyFilter applies only to root of tree
 * @return FilterBase or null
 */
public FilterBase buildFilter(final String path, final boolean applyFilter, final boolean explicitSelection) {
    if (path == null) {
        return BooleanFilter.falseFilter;
    }
    BwCalendar col = colCache.get(path);
    if (col == null) {
        try {
            col = parser.getCollection(path);
        } catch (CalFacadeException cfe) {
            error(cfe);
            return BooleanFilter.falseFilter;
        }
        colCache.put(path, col);
    }
    final ArrayList<String> pathElements = new ArrayList<>();
    pathElements.add(path);
    final CalFilter calFilter;
    try {
        calFilter = makeColFilter(col, applyFilter, explicitSelection, pathElements);
    } catch (CalFacadeException cfe) {
        error(cfe);
        return BooleanFilter.falseFilter;
    }
    if (calFilter == null) {
        // No valid matches
        return BooleanFilter.falseFilter;
    }
    /* if we have any OrCalFilters it's because they refer to different
     * calendar collections.
     *
     * Re-express this as BwFilters
     */
    final FilterBase f = makeBwFilter(calFilter);
    if (debug) {
        debug(" ---------  FilterBuilder result ---------------");
        dump(f, "");
        debug(" ---------  end of FilterBuilder result ---------------");
    }
    return f;
}
Also used : ArrayList(java.util.ArrayList) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) FilterBase(org.bedework.caldav.util.filter.FilterBase)

Example 7 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class BwPrincipal method makePrincipal.

public static BwPrincipal makePrincipal(final String href) throws CalFacadeException {
    try {
        final String uri = URLDecoder.decode(new URI(URLEncoder.encode(href, "UTF-8")).getPath(), "UTF-8");
        if (!isPrincipal(uri)) {
            return null;
        }
        int start = -1;
        int end = uri.length();
        if (uri.endsWith("/")) {
            end--;
        }
        for (String prefix : toWho.keySet()) {
            if (!uri.startsWith(prefix)) {
                continue;
            }
            if (uri.equals(prefix)) {
                // Trying to browse user principals?
                return null;
            }
            int whoType = toWho.get(prefix);
            String who;
            if ((whoType == WhoDefs.whoTypeUser) || (whoType == WhoDefs.whoTypeGroup)) {
                /* Strip off the principal prefix for real users.
           */
                who = uri.substring(prefix.length(), end);
            } else {
                who = uri;
            }
            final BwPrincipal p;
            if ((whoType == WhoDefs.whoTypeGroup) && prefix.equals(bwadmingroupPrincipalRoot)) {
                p = new BwAdminGroup();
            } else {
                p = BwPrincipal.makePrincipal(whoType);
            }
            if (p != null) {
                p.setAccount(who);
                p.setPrincipalRef(uri);
                return p;
            }
        }
        throw new CalFacadeException(CalFacadeException.principalNotFound);
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : ToString(org.bedework.util.misc.ToString) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) URI(java.net.URI) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 8 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class BwPrincipalInfo method setPropertiesFromVCard.

/**
 * @param cardStr
 * @throws CalFacadeException
 */
public void setPropertiesFromVCard(final String cardStr, final String addrDataCtype) throws CalFacadeException {
    if (cardStr == null) {
        return;
    }
    this.cardStr = cardStr;
    addProperty(new PrincipalProperty<String>("vcard", cardStr));
    try {
        if ("application/vcard+json".equals(addrDataCtype)) {
            card = new JsonCardBuilder(null).build(new StringReader(cardStr));
        } else {
            card = new VCardBuilder(new StringReader(cardStr)).build();
        }
        Property piprop = card.getExtendedProperty("X-BW-PRINCIPALHREF");
        if (piprop != null) {
            setPrincipalHref(piprop.getValue());
        }
        piprop = card.getExtendedProperty("X-ICAL4J-TOV3-KIND");
        if (piprop != null) {
            setKind(piprop.getValue());
        }
        if (getKind() == null) {
            // Check for member attributes
            piprop = card.getProperty(Id.MEMBER);
            if (piprop != null) {
                setKind(Kind.GROUP.getValue());
            }
        }
        for (PrincipalPropertyInfo ppi : BwPrincipalInfo.getPrincipalPropertyInfoSet()) {
            Property.Id pname = ppi.getVcardPname();
            if (pname == null) {
                // Not a vcard property
                continue;
            }
            if (!ppi.getMulti()) {
                // Single valued
                Property prop = card.getProperty(pname);
                if (prop == null) {
                    continue;
                }
                addProperty(ppi, prop);
            } else {
                List<Property> ps = card.getProperties(pname);
                if (Util.isEmpty(ps)) {
                    continue;
                }
                for (Property prop : ps) {
                    addProperty(ppi, prop);
                }
            }
        }
    } catch (final Throwable t) {
        if (debug) {
            debug("CardStr was " + cardStr);
        }
        throw new CalFacadeException(t);
    }
}
Also used : Id(net.fortuna.ical4j.vcard.Property.Id) VCardBuilder(net.fortuna.ical4j.vcard.VCardBuilder) StringReader(java.io.StringReader) ToString(org.bedework.util.misc.ToString) Property(net.fortuna.ical4j.vcard.Property) JsonCardBuilder(org.bedework.util.vcard.JsonCardBuilder) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 9 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class SimpleFilterParser method makeTimeRange.

private TimeRange makeTimeRange(final String startStr, final String endStr) throws ParseFailed {
    try {
        DateTime start = null;
        DateTime end = null;
        if (startStr != null) {
            start = new DateTime(startStr);
        }
        if (endStr != null) {
            end = new DateTime(endStr);
        }
        return new TimeRange(start, end);
    } catch (final Throwable t) {
        throw parseResult.setCfe(new CalFacadeException(t));
    }
}
Also used : TimeRange(org.bedework.caldav.util.TimeRange) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 10 with CalFacadeException

use of org.bedework.calfacade.exc.CalFacadeException in project bw-calendar-engine by Bedework.

the class BwXproperty method parseParameters.

/**
 * @param val
 * @return List<Xpar>
 * @throws CalFacadeException
 */
public static List<Xpar> parseParameters(String val) throws CalFacadeException {
    /* Code copied shamelessly from ical4j.
     * Better approach would be to make these parsing methods available to
     * applications.
     */
    int WORD_CHAR_START = 32;
    int WORD_CHAR_END = 255;
    int WHITESPACE_CHAR_START = 0;
    int WHITESPACE_CHAR_END = 20;
    if ((val == null) || (val.length() == 0)) {
        return null;
    }
    if (!val.startsWith(";")) {
        val = ";" + val;
    }
    StreamTokenizer tokeniser = new StreamTokenizer(new StringReader(val));
    List<Xpar> pars = new ArrayList<Xpar>();
    try {
        tokeniser.resetSyntax();
        tokeniser.wordChars(WORD_CHAR_START, WORD_CHAR_END);
        tokeniser.whitespaceChars(WHITESPACE_CHAR_START, WHITESPACE_CHAR_END);
        tokeniser.ordinaryChar(':');
        tokeniser.ordinaryChar(';');
        tokeniser.ordinaryChar('=');
        tokeniser.ordinaryChar('\t');
        tokeniser.eolIsSignificant(true);
        tokeniser.whitespaceChars(0, 0);
        tokeniser.quoteChar('"');
        while (tokeniser.nextToken() == ';') {
            parseParameter(tokeniser, pars);
        }
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
    return pars;
}
Also used : StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) StreamTokenizer(java.io.StreamTokenizer) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)298 BwCalendar (org.bedework.calfacade.BwCalendar)55 BwEvent (org.bedework.calfacade.BwEvent)55 EventInfo (org.bedework.calfacade.svc.EventInfo)37 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)32 ArrayList (java.util.ArrayList)28 BwString (org.bedework.calfacade.BwString)26 BwDateTime (org.bedework.calfacade.BwDateTime)24 IndexException (org.bedework.util.indexing.IndexException)23 BwPrincipal (org.bedework.calfacade.BwPrincipal)22 TreeSet (java.util.TreeSet)19 BwAttendee (org.bedework.calfacade.BwAttendee)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)16 Calendar (net.fortuna.ical4j.model.Calendar)15 DateTime (net.fortuna.ical4j.model.DateTime)15 Period (net.fortuna.ical4j.model.Period)13 BwCategory (org.bedework.calfacade.BwCategory)13 StringReader (java.io.StringReader)12 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)12 BwEventProxy (org.bedework.calfacade.BwEventProxy)12