@Override protected void fix() throws QuickFixException { BuilderService builderService = Aura.getBuilderService(); DefinitionService definitionService = Aura.getDefinitionService(); String descriptors = (String) getAttributes().get("descriptor"); String[] split = CreateComponentDefQuickFix.descriptorPattern.split(descriptors); for (String descriptor : split) { ApplicationDef def = builderService.getApplicationDefBuilder().setDescriptor(descriptor).build(); definitionService.save(def); if (getBooleanAttribute("client.css")) { DefDescriptor<StyleDef> styleDescriptor = definitionService.getDefDescriptor(def.getDescriptor(), "css", StyleDef.class); new CreateStyleDefQuickFix(styleDescriptor).fix(); } resetCache(def.getDescriptor()); } }
/** * Get a security provider for the application. * * <p>This should probably catch the quick fix exception and simply treat it as a null security * provider. This caches the security provider. * * @return the sucurity provider for the application or null if none. * @throws QuickFixException if there was a problem compiling. */ private SecurityProviderDef getSecurityProvider() throws QuickFixException { DefDescriptor<? extends BaseComponentDef> rootDesc = Aura.getContextService().getCurrentContext().getApplicationDescriptor(); if (securityProvider == null || !lastRootDesc.equals(rootDesc)) { SecurityProviderDef securityProviderDef = null; if (rootDesc != null && rootDesc.getDefType().equals(DefType.APPLICATION)) { ApplicationDef root = (ApplicationDef) getDef(rootDesc); if (root != null) { DefDescriptor<SecurityProviderDef> securityDesc = root.getSecurityProviderDefDescriptor(); if (securityDesc != null) { securityProviderDef = getDef(securityDesc); } } } securityProvider = securityProviderDef; lastRootDesc = rootDesc; } return securityProvider; }
/** * Write out the manifest. * * <p>This writes out the full manifest for an application so that we can use the AppCache. * * <p>The manifest contains CSS and JavaScript URLs. These specified resources are copied into the * AppCache with the HTML template. When the page is reloaded, the existing manifest is compared * to the new manifest. If they are identical, the resources are served from the AppCache. * Otherwise, the resources are requested from the server and the AppCache is updated. * * @param request the request * @param response the response * @param context the context * @throws IOException if unable to write out the response */ @Override public void write(HttpServletRequest request, HttpServletResponse response, AuraContext context) throws IOException { servletUtilAdapter.setNoCache(response); try { Map<String, Object> attributes = getComponentAttributes(request); // // First, we make sure that the manifest is enabled. // if (!manifestUtil.isManifestEnabled(request)) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // // Now we validate the cookie, which includes loop detection. // this routine sets the response code. // if (!manifestUtil.checkManifestCookie(request, response)) { return; } boolean appOk = false; DefDescriptor<? extends BaseComponentDef> descr = null; try { descr = context.getApplicationDescriptor(); if (descr != null) { definitionService.updateLoaded(descr); appOk = true; } } catch (QuickFixException qfe) { // // ignore qfe, since we really don't care... the manifest will be 404ed. // This will eventually cause the browser to give up. Note that this case // should almost never occur, as it requires the qfe to be introduced between // the initial request (which will not set a manifest if it gets a qfe) and // the manifest request. // } catch (ClientOutOfSyncException coose) { // // In this case, we want to force a reload... A 404 on the manifest is // supposed to handle this. we hope that the client will do the right // thing, and reload everything. Note that this case really should only // happen if the client already has content, and thus should be refreshing // However, there are very odd edge cases that we probably can't detect // without keeping server side state, such as the case that something // is updated between the initial HTML request and the manifest request. // Not sure what browsers will do in this case. // } if (!appOk) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } // // This writes both the app and framework signatures into // the manifest, so that if either one changes, the // manifest will change. Note that in most cases, we will // write these signatures in multiple places, but we just // need to make sure that they are in at least one place. // Map<String, Object> attribs = Maps.newHashMap(); String appUid = getContextAppUid(context); String nonce = configAdapter.getAuraFrameworkNonce(); // Since we don't get the UID from our URL, we set it here. context.setFrameworkUID(nonce); attribs.put(LAST_MOD, String.format("app=%s, FW=%s", appUid, nonce)); attribs.put(UID, appUid); StringWriter sw = new StringWriter(); String resetCssUrl = configAdapter.getResetCssURL(); if (resetCssUrl != null) { sw.write(resetCssUrl); sw.write('\n'); } for (String s : servletUtilAdapter.getStyles(context)) { sw.write(s); sw.write('\n'); } for (String s : servletUtilAdapter.getScripts(context, true, true, attributes)) { sw.write(s); sw.write('\n'); } // Add locker service safe eval worker url String lockerWorkerURL = configAdapter.getLockerWorkerURL(); if (lockerWorkerURL != null) { sw.write(lockerWorkerURL); sw.write('\n'); } // Add in any application specific resources if (descr != null && descr.getDefType().equals(DefType.APPLICATION)) { ApplicationDef def = (ApplicationDef) descr.getDef(); for (String s : def.getAdditionalAppCacheURLs()) { if (s != null) { sw.write(s); sw.write('\n'); } } } attribs.put(RESOURCE_URLS, sw.toString()); DefDescriptor<ComponentDef> tmplDesc = definitionService.getDefDescriptor("ui:manifest", ComponentDef.class); Component tmpl = instanceService.getInstance(tmplDesc, attribs); renderingService.render(tmpl, response.getWriter()); } catch (Exception e) { Aura.getExceptionAdapter().handleException(e); // Can't throw exception here: to set manifest OBSOLETE response.setStatus(HttpServletResponse.SC_NOT_FOUND); } }