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;
}
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);
}
}
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);
}
}
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));
}
}
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;
}
Aggregations