private PathSegments segment() { return PathSegments.of(false, name); }
public PathSegments consume() { return consume(1); }
/** * Returns the device represented by a first segment. * @param path Path to check. * @return The resolved device or {@code null} if no device is found. */ public final Device findDeviceByFirstSegment(PathSegments path) { if (path == null || path.isEmpty()) { return null; } return findDeviceByFirstSegment(path.get(0)); }
public PathSegments add(PathSegments other) { if (other == null || other.isEmpty()) { return this; } if (isEmpty()) { return other; } return new PathSegments(ImmutableList.copyOf(Iterables.concat(segments, other.segments))); }
public PathSegments apply(PathSegments input) { if (input == null || input.isEmpty()) { return input; } String last = input.last(); if (last == null || last.length() == 0) { return input; } last = new StringBuilder(last).append('.').append(extension).toString(); return PathSegments.of(false, Iterables.concat(input.consumeLast(), ImmutableList.of(last))); }
/** * @see com.isotrol.impe3.api.LocaleResolver#resolveLocale(com.isotrol.impe3.api.LocaleResolutionParams) */ public ResolvedLocale resolveLocale(LocaleResolutionParams params) { Locale locale = null; PathSegments p = params.getPath(); if (p.isEmpty()) { // TODO use fallback return new ResolvedLocale(params.getPath(), params.getPortal().getDefaultLocale(), params.getParameters()); } String segment = p.get(0); locale = cache.getUnchecked(params.getPortal()).get(segment); if (locale == null) { // TODO use fallback return new ResolvedLocale(params.getPath(), params.getPortal().getDefaultLocale(), params.getParameters()); } return new ResolvedLocale(p.consume(), locale, params.getParameters()); }
/** * Removes the extension from the last segment. * @return The modified segments. */ public PathSegments removeExtension() { if (isEmpty()) { return this; } final String last = last(); final String removed = removeExtension(last); if (last.equals(removed)) { return this; } return new PathSegments(ImmutableList.copyOf(Iterables.concat(segments.subList(0, segments.size() - 1), ImmutableList.of(removed)))); }
/** * @see com.isotrol.impe3.api.DeviceResolver#resolveDevice(com.isotrol.impe3.api.DeviceResolutionParams) */ public ResolvedDevice resolveDevice(DeviceResolutionParams params) { final DevicesInPortal dips = params.getPortal().getDevices(); final PathSegments path = params.getPath(); Device d = dips.findDeviceByFirstSegment(path); if (d != null) { return params.resolve(d, path.consume()); } d = dips.findDeviceByLastSegment(path); if (d != null) { return params.resolve(d, path.consumeLast()); } d = dips.findDeviceByLastSegmentExtension(path); if (d != null) { return params.resolve(d, path.removeExtension()); } return null; }
/** * Returns the device represented by a last segment. * @param path Path to check. * @return The resolved device or {@code null} if no device is found. */ public final Device findDeviceByLastSegment(PathSegments path) { if (path == null || path.isEmpty()) { return null; } return findDeviceByLastSegment(path.last()); }
/** * Returns a new transformer that inserts segments at the beginning of the provided path. * @param segments Segments to add. * @return The requested transformer. */ public static Function<PathSegments, PathSegments> insert(final PathSegments segments) { if (segments == null || segments.isEmpty()) { return Functions.identity(); } return new Function<PathSegments, PathSegments>() { public PathSegments apply(PathSegments input) { if (input == null || input.isEmpty()) { return segments; } return segments.add(input); } public String toString() { return String.format("Insert transformer: %s", segments); }; }; }
public String head() { return get(0); }
/** * Turns a single segment into a list of decoded segments. * @param segment Segment. * @param encoded If the segment is encoded. * @return The never {@code null} list of segments. */ public static PathSegments segment(String segment, boolean encoded) { if (segment == null || segment.length() == 0) { return EMPTY; } String s = segment; if (encoded) { try { s = URLDecoder.decode(s, "UTF-8"); } catch (UnsupportedEncodingException e) {} } return new PathSegments(ImmutableList.of(s)); }
public PathSegments consumeLast() { return consumeLast(1); }
public PageURI add(PageURI uri) { if (uri == null) { return this; } final PathSegments _path = path.add(uri.path); final ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder(); b.putAll(parameters).putAll(uri.parameters); return new PageURI(_path, b.build()); }
/** * Returns the device represented by a last segment extension. * @param path Path to check. * @return The resolved device or {@code null} if no device is found. */ public final Device findDeviceByLastSegmentExtension(PathSegments path) { if (path == null || path.isEmpty()) { return null; } return findDeviceByLastSegmentExtension(path.last()); }
/** * Returns a new transformer that appends segments to the provided path. * @param segments Segments to append. * @return The requested transformer. */ public static Function<PathSegments, PathSegments> append(final PathSegments segments) { if (segments == null || segments.isEmpty()) { return Functions.identity(); } return new Function<PathSegments, PathSegments>() { public PathSegments apply(PathSegments input) { if (input == null || input.isEmpty()) { return segments; } return input.add(segments); } public String toString() { return String.format("Append transformer: %s", segments); }; }; }
public PathSegments consume(int n) { if (n == 0) { return this; } return new PathSegments(segments.subList(n, segments.size())); }