/** * Makes a copy of an EntityView which can be changed independently * @param ev any EntityView * @return the copy * @throws IllegalArgumentException if the input is null OR not completely constructed */ public static EntityView copy(EntityView ev) { if (ev == null) { throw new IllegalArgumentException("input entity view must not be null"); } if (ev.viewKey == null || ev.entityReference == null) { throw new IllegalArgumentException("input entity view must be completely constructed"); } EntityView togo = new EntityView(); EntityReference ref = ev.getEntityReference(); togo.setEntityReference( new EntityReference(ref.getPrefix(), ref.getId() == null ? "" : ref.getId()) ); togo.preloadParseTemplates( ev.getAnazlyzedTemplates() ); togo.setExtension( ev.getExtension() ); togo.setViewKey( ev.getViewKey() ); return togo; }
/** * Get all the path segments for the encoded URL for this view<br/> * Example: /user/aaronz/promote/stuff.xml <br/> * segments = {"user","aaronz","promote","stuff"} * @return an array of path segments */ public String[] getPathSegments() { String url = getOriginalEntityUrl(); if (url == null) { url = getEntityURL(); } String[] segments = new String[0]; if (url != null) { url = TemplateParseUtil.findExtension(url)[1]; if (url.charAt(0) == SEPARATOR) { url = url.substring(1); } segments = url.split(SEPARATOR+""); } return segments; }
/** * @return a copy of this object * @see #copy(EntityView) */ public EntityView copy() { return copy(this); }
/** * @param ev the entity view * @param customAction the custom action * @return a URL for triggering the custom action (without http://server/direct) */ protected String makeActionURL(EntityView ev, CustomAction customAction) { // switched to this since it is more correct String URL = EntityView.SEPARATOR + ev.getEntityReference().getPrefix() + EntityView.SEPARATOR + customAction.action; String viewKey = customAction.viewKey; if (viewKey != null && (EntityView.VIEW_SHOW.equals(viewKey) || EntityView.VIEW_EDIT.equals(viewKey) || EntityView.VIEW_DELETE.equals(viewKey))) { URL = ev.getEntityURL(EntityView.VIEW_SHOW, null) + EntityView.SEPARATOR + customAction.action; } return URL; }
/** * Reduce code duplication and ensure custom templates are used */ public EntityView makeEntityView(EntityReference ref, String viewKey, String extension) { if (ref == null) { throw new IllegalArgumentException("ref cannot be null"); } EntityView view = new EntityView(); EntityViewUrlCustomizable custom = (EntityViewUrlCustomizable) entityProviderManager .getProviderByPrefixAndCapability(ref.getPrefix(), EntityViewUrlCustomizable.class); if (custom != null) { // use the custom parsing templates view.loadParseTemplates( custom.getParseTemplates() ); } view.setEntityReference(ref); if (viewKey != null) { view.setViewKey(viewKey); } if (extension != null) { view.setExtension(extension); } return view; }
} else if ( DESCRIBE.equals(view.getEntityReference().getId()) ) { String output = entityDescriptionManager.makeDescribeEntity(view.getEntityReference().getPrefix(), entityId, format, req.getLocale()); res.setContentLength(output.getBytes().length); try { handledReference = view.getEntityReference().getSpaceReference() + SLASH_DESCRIBE; String prefix = view.getEntityReference().getPrefix(); CustomAction customAction = entityActionsManager.getCustomAction(prefix, view.getPathSegment(1)); if (customAction == null) { customAction = entityActionsManager.getCustomAction(prefix, view.getPathSegment(2)); if (! entityBrokerManager.entityExists(view.getEntityReference()) ) { + view.getEntityReference() + ") that does not exist", view.getEntityReference()+"", HttpServletResponse.SC_NOT_FOUND ); EntityReference cRef = view.getEntityReference(); if (cRef.getId() != null && cRef.getId().equalsIgnoreCase(customAction.action)) { view.setEntityReference( new EntityReference(prefix, "") ); req.setAttribute("entity-format", view.getFormat()); requestStorage.setRequestValue(RequestStorage.ReservedKeys._requestEntityReference.name(), view.getEntityReference().toString()); requestStorage.setRequestValue(RequestStorage.ReservedKeys._requestOrigin.name(), RequestStorage.RequestOrigin.REST.name()); requestStorage.setRequestValue(RequestStorage.ReservedKeys._requestActive.name(), true);
EntityView ev = new EntityView(); ev.setEntityReference( ref ); if (viewKey != null && ! "".equals(viewKey)) { ev.setViewKey(viewKey); ev.setExtension(format); String URL = ev.toString(); if (EntityView.VIEW_DELETE.equals(ev.getViewKey())) { method = Method.DELETE; } else if (EntityView.VIEW_EDIT.equals(ev.getViewKey())) { method = Method.PUT; } else if (EntityView.VIEW_NEW.equals(ev.getViewKey())) { method = Method.POST; } else {
boolean updateable = entityProviderManager.getProviderByPrefixAndCapability(prefix, Updateable.class) != null; boolean deleteable = entityProviderManager.getProviderByPrefixAndCapability(prefix, Deleteable.class) != null; String viewKey = view.getViewKey(); if (EntityView.VIEW_NEW.equals(viewKey) && createable) { handle = true; && entityData.getEntityId() != null) { view = view.copy(); view.setEntityReference( new EntityReference(prefix, entityData.getEntityId()) ); && ! EntityView.VIEW_NEW.equals(viewKey)) { sb.append(" (<a href='" + prefixUrl + view.getEntityURL(EntityView.VIEW_NEW, Formats.FORM) + "'>NEW</a>) "); if (entity == null) { String id = (view.getEntityReference() != null ? view.getEntityReference().getId() : null); if (id == null) { id = (entityData != null ? entityData.getEntityId() : null);
String method = req.getMethod() == null ? EntityView.Method.GET.name() : req.getMethod().toUpperCase().trim(); if (EntityView.Method.GET.name().equals(method)) { view.setMethod(EntityView.Method.GET); output = true; } else if (EntityView.Method.HEAD.name().equals(method)) { view.setMethod(EntityView.Method.HEAD); output = true; } else { view.setViewKey(EntityView.VIEW_DELETE); view.setMethod(EntityView.Method.DELETE); } else if (EntityView.Method.PUT.name().equals(method)) { view.setViewKey(EntityView.VIEW_EDIT); view.setMethod(EntityView.Method.PUT); } else if (EntityView.Method.POST.name().equals(method)) { String _method = req.getParameter(EntityRequestHandler.COMPENSATE_METHOD); if (_method == null) { if (view.getEntityReference().getId() == null) { view.setViewKey(EntityView.VIEW_NEW); } else { view.setViewKey(EntityView.VIEW_EDIT); view.setViewKey(EntityView.VIEW_DELETE); } else if (EntityView.Method.PUT.name().equals(_method)) { if (view.getEntityReference().getId() == null) { view.setViewKey(EntityView.VIEW_NEW);
public ViewParameters getViewParameters() { EntityViewViewParamsInferrer evvpi = null; if (entityViewProxy.getEntityReference() != null) { String prefix = entityViewProxy.getEntityReference().prefix; evvpi = (EntityViewViewParamsInferrer) inferrermap.get(prefix); } return evvpi == null ? null : evvpi.inferDefaultViewParameters(entityViewProxy); } }
String prefix = view.getEntityReference().getPrefix(); EntityProvider provider = entityProviderManager.getProviderByPrefix(prefix); res.setHeader("x-entity-prefix", prefix); res.setHeader("x-entity-reference", view.getEntityReference().toString()); res.setHeader("x-entity-url", view.getEntityURL()); res.setHeader("x-entity-format", view.getFormat()); res.setHeader("x-sdata-url", view.getOriginalEntityUrl());
setEntityReference(ref); this.pathSegments = new HashMap<String, String>(); this.pathSegments.put(PREFIX, ref.getPrefix()); setMethod(Method.DELETE); } else if (VIEW_EDIT.equals(viewKey)) { setMethod(Method.PUT); } else if (VIEW_NEW.equals(viewKey)) { setMethod(Method.POST); setViewKey(viewKey); setExtension(extension);
EntityViewAccessProvider evAccessProvider = entityViewAccessProviderManager.getProvider(view.getEntityReference().getPrefix()); if (evAccessProvider == null) { if (accessProviderManager != null) { HttpServletAccessProvider httpAccessProvider = accessProviderManager.getProvider(view.getEntityReference().getPrefix()); if (httpAccessProvider == null) { return false; httpAccessProvider.handleAccess(req, res, view.getEntityReference()); } finally { Thread.currentThread().setContextClassLoader(currentClassLoader); if (entityViewKeys != null && ! ReflectUtils.contains(entityViewKeys, view.getViewKey()) ) { throw new EntityException("Access provider for " + view.getEntityReference().getPrefix() + " will not handle this view ("+view.getViewKey()+"): " + view, view.getEntityReference()+"", HttpServletResponse.SC_BAD_REQUEST); if (accessFormats != null && ! ReflectUtils.contains(accessFormats, view.getFormat()) ) { throw new FormatUnsupportedException("Access provider for " + view.getEntityReference().getPrefix() + " will not handle this format ("+view.getFormat()+")", view.getEntityReference()+"", view.getFormat());
public void handleAccess(EntityView view, HttpServletRequest req, HttpServletResponse res) { String format = view.getFormat(); if (format.equals(Formats.HTML) || format.equals(Formats.RSS)) { // Okey dokey, do nothing but say all is well try { res.getWriter().print(prefix + ": EntityViewAccessProviderMock"); } catch (IOException e) { log.error(e.getMessage(), e); } ((EntityHttpServletResponse) res).setStatus(HttpServletResponse.SC_OK); } else { throw new FormatUnsupportedException("No support for format: " + format, view.getEntityReference()+"", format); } }
EntityReference ref = entityView.getEntityReference(); OutputStream outputStream = new LazyResponseOutputStream(response); ActionReturn actionReturn = handleCustomActionExecution(actionProvider, ref, action, actionParams, outputStream, entityView, searchParams); actionReturn.format = entityView.getExtension(); if (actionReturn.encoding == null || actionReturn.mimeType == null) {
.getProviderByPrefixAndCapability(prefix, EntityViewUrlCustomizable.class); if (custom == null) { view = new EntityView(entityURL); } else { view = new EntityView(); view.loadParseTemplates( custom.getParseTemplates() ); view.parseEntityURL(entityURL);
setViewKey(viewKey); if (VIEW_DELETE.equals(viewKey)) { setMethod(Method.DELETE); } else if (VIEW_EDIT.equals(viewKey)) { setMethod(Method.PUT); } else if (VIEW_NEW.equals(viewKey)) { setMethod(Method.POST); } else { setMethod(Method.GET);
/** * @return the entity URL of the internal reference based on the * internal viewKey and extension, defaults to {@link TemplateParseUtil#TEMPLATE_SHOW} or * the {@link TemplateParseUtil#TEMPLATE_LIST} one if there is no id, * example: /prefix if there is no id or /prefix/id if there is an id * @throws IllegalArgumentException if there is not enough information to generate a URL */ public String getEntityURL() { String URL = getEntityURL(this.viewKey, this.extension); return URL; }
views.put(ref.getPrefix(), view); view.setEntityReference(ref); String partialURL = view.getEntityURL(); String fullURL = makeFullURL( partialURL ); entityData.setEntityURL( fullURL );
@EntityCustomAction(action="yyyy",viewKey="") public ActionReturn xxxAction(EntityView view) { return new ActionReturn(view.getOriginalEntityUrl()); }