Exemplo n.º 1
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   json.writeMapEntry("label", this.label);
   json.writeMapEntry("value", this.value);
   json.writeMapEnd();
 }
Exemplo n.º 2
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   json.writeMapEntry("fieldName", this.fieldName);
   json.writeMapEntry("ascending", this.ascending);
   json.writeMapEnd();
 }
Exemplo n.º 3
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   json.writeMapEntry("label", this.label);
   json.writeMapEntry("fieldName", this.fieldName);
   json.writeMapEntry("isSortable", this.isSortable);
   json.writeMapEnd();
 }
Exemplo n.º 4
0
 @Override
 public void assertDiff(String test, StringBuilder sb)
     throws SAXException, IOException, ParserConfigurationException {
   Object controlObj = new JsonReader().read(readGoldFile());
   Object testObj = new JsonReader().read(test);
   // for stuff that has ref support, the serIds may be different because
   // of ordering, so resolve them
   controlObj = Json.resolveRefs(controlObj);
   testObj = Json.resolveRefs(testObj);
   Assert.assertEquals(sb == null ? "Diff from " + getUrl() : sb.toString(), controlObj, testObj);
 }
Exemplo n.º 5
0
  @Override
  public void serialize(Json json) throws IOException {
    json.writeMapBegin();
    json.writeMapEntry("descriptor", descriptor);

    AuraContext context = Aura.getContextService().getCurrentContext();
    if (!context.isPreloading() && !context.isPreloaded(getDescriptor())) {
      // TODONM: revisit this after removing theme from aura context
      if (context.getThemeList().isEmpty()) {
        context.addAppThemeDescriptors();
      }
      json.writeMapEntry("code", getCode());
    }
    json.writeMapEnd();
  }
Exemplo n.º 6
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   json.writeMapEntry("name", name);
   json.writeMapEntry("description", description);
   json.writeMapEntry("type", type);
   json.writeMapEntry("required", required);
   json.writeMapEntry("defaultValue", defaultValue);
   json.writeMapEntry("parentName", parentName);
   json.writeMapEntry("parentDefType", parentDefType);
   json.writeMapEnd();
 }
Exemplo n.º 7
0
    public HttpPost getPostMethod() throws Exception {
      if (post == null) {
        Map<String, Object> message = Maps.newHashMap();
        ArrayList<Map<String, Object>> actionInstanceArray = new ArrayList<>();
        for (int i = 0; i < qualifiedName.size(); i++) {
          Map<String, Object> actionInstance = Maps.newHashMap();
          actionInstance.put("descriptor", qualifiedName.get(i));
          if (actionParams.get(i) != null) {
            actionInstance.put("params", actionParams.get(i));
          }
          actionInstanceArray.add(actionInstance);
        }
        if (app == null) {
          app =
              Aura.getDefinitionService()
                  .getDefDescriptor("auratest:test_SimpleServerRenderedPage", ApplicationDef.class);
        }
        message.put("actions", actionInstanceArray.toArray());
        String jsonMessage = Json.serialize(message);
        Map<String, String> params = Maps.newHashMap();
        params.put("message", jsonMessage);
        params.put("aura.token", getTestServletConfig().getCsrfToken());

        params.put("aura.context", getAuraTestingUtil().buildContextForPost(mode, app, null, dn));
        post = obtainPostMethod("/aura", params);
      }
      return post;
    }
Exemplo n.º 8
0
  /**
   * Convenience method for executing an Action
   *
   * @param descriptor fully qualified descriptor string for the action - e.g.
   *     java://org.auraframework.components.test.java.controller.JavaTestController/ACTION$getString
   * @param params a set of name value string pairs to use as parameters to the post call.
   * @return a {@link HttpPost}
   * @throws Exception
   */
  protected HttpPost executeAuraAction(
      Class<?> serverControllerClass,
      String methodName,
      Map<String, String> actionParams,
      Map<String, String> postParams)
      throws Exception {
    Map<String, Object> message = new HashMap<>();
    Map<String, Object> actionInstance = new HashMap<>();
    String descriptor =
        "java://" + serverControllerClass.getCanonicalName() + "/ACTION$" + methodName;
    actionInstance.put("descriptor", descriptor);
    if (actionParams != null) {
      actionInstance.put("params", actionParams);
    }
    Map<?, ?>[] actions = {actionInstance};
    message.put("actions", actions);
    String jsonMessage = Json.serialize(message);

    if (postParams == null) {
      postParams = Maps.newHashMap();
    }
    postParams.put("message", jsonMessage);
    if (!postParams.containsKey("aura.token")) {
      postParams.put("aura.token", getCsrfToken());
    }
    if (!postParams.containsKey("aura.context")) {
      postParams.put(
          "aura.context",
          Aura.getContextService().getCurrentContext().serialize(EncodingStyle.Normal));
    }
    HttpPost post = obtainPostMethod("/aura", postParams);
    perform(post);
    post.releaseConnection();
    return post;
  }
Exemplo n.º 9
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   for (Entry<String, Object> entry : properties.entrySet()) {
     Object value = entry.getValue();
     if (value instanceof Answer) {
       try {
         value = ((Answer<?>) value).answer();
       } catch (Throwable e) {
         if (e instanceof IOException) {
           throw (IOException) e;
         } else {
           throw new AuraRuntimeException(e);
         }
       }
     }
     json.writeMapEntry(entry.getKey(), value);
   }
   json.writeMapEnd();
 }
Exemplo n.º 10
0
 @Override
 public void serialize(Json json) throws IOException {
   json.writeMapBegin();
   json.writeMapKey("fullName");
   json.writeValue(this.getFullName());
   json.writeMapKey("shortName");
   json.writeValue(this.getShortName());
   json.writeMapEnd();
 }
Exemplo n.º 11
0
 @SuppressWarnings("unchecked")
 private void verifyStyleDefSerialization(DefDescriptor<StyleDef> styleDesc, Boolean expectCode)
     throws Exception {
   String serialized = Json.serialize(styleDesc.getDef());
   Object o = new JsonReader().read(serialized);
   assertTrue(o instanceof Map);
   Map<String, Object> outerMap = (Map<String, Object>) o;
   assertEquals(styleDesc.toString(), outerMap.get("descriptor"));
   assertEquals(
       styleDesc.getNamespace() + AuraTextUtil.initCap(styleDesc.getName()),
       outerMap.get("className"));
   if (expectCode) {
     assertEquals(
         "StyleDef content not included.", styleDesc.getDef().getCode(), outerMap.get("code"));
   } else {
     assertNull("StyleDef content should not be included.", outerMap.get("code"));
   }
 }
  @Override
  public void write(T value, Map<String, Object> componentAttributes, Appendable out)
      throws IOException {
    try {

      AuraContext context = Aura.getContextService().getCurrentContext();
      InstanceService instanceService = Aura.getInstanceService();
      RenderingService renderingService = Aura.getRenderingService();
      BaseComponentDef def = value.getDescriptor().getDef();

      ComponentDef templateDef = def.getTemplateDef();
      Map<String, Object> attributes = Maps.newHashMap();

      StringBuilder sb = new StringBuilder();
      writeHtmlStyles(new ArrayList<>(Arrays.asList(Aura.getConfigAdapter().getResetCssURL())), sb);
      attributes.put("auraResetCss", sb.toString());
      sb.setLength(0);
      writeHtmlStyles(AuraServlet.getStyles(), sb);
      attributes.put("auraStyleTags", sb.toString());
      sb.setLength(0);
      writeHtmlScripts(AuraServlet.getScripts(), sb);
      DefDescriptor<StyleDef> styleDefDesc = templateDef.getStyleDescriptor();
      if (styleDefDesc != null) {
        attributes.put("auraInlineStyle", styleDefDesc.getDef().getCode());
      }

      String contextPath = context.getContextPath();
      Mode mode = context.getMode();

      if (mode.allowLocalRendering() && def.isLocallyRenderable()) {
        BaseComponent<?, ?> cmp =
            (BaseComponent<?, ?>) instanceService.getInstance(def, componentAttributes);

        attributes.put("body", Lists.<BaseComponent<?, ?>>newArrayList(cmp));
        attributes.put("bodyClass", "");
        attributes.put("autoInitialize", "false");

        Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);

        renderingService.render(template, out);
      } else {

        attributes.put("auraScriptTags", sb.toString());
        Map<String, Object> auraInit = Maps.newHashMap();
        if (componentAttributes != null && !componentAttributes.isEmpty()) {
          auraInit.put("attributes", componentAttributes);
        }
        auraInit.put("descriptor", def.getDescriptor());
        auraInit.put("deftype", def.getDescriptor().getDefType());
        auraInit.put("host", contextPath);

        attributes.put("autoInitialize", "false");
        attributes.put("autoInitializeSync", "true");

        auraInit.put("instance", value);
        auraInit.put("token", AuraBaseServlet.getToken());

        StringBuilder contextWriter = new StringBuilder();
        Aura.getSerializationService()
            .write(context, null, AuraContext.class, contextWriter, "JSON");
        auraInit.put("context", new Literal(contextWriter.toString()));

        attributes.put("auraInitSync", Json.serialize(auraInit));

        Component template = instanceService.getInstance(templateDef.getDescriptor(), attributes);
        renderingService.render(template, out);
      }
    } catch (QuickFixException e) {
      throw new AuraRuntimeException(e);
    }
  }
Exemplo n.º 13
0
    @Override
    public void serialize(Json json, AuraContext ctx) throws IOException {
      json.writeMapBegin();
      json.writeMapEntry("mode", ctx.getMode());

      DefDescriptor<? extends BaseComponentDef> appDesc = ctx.getApplicationDescriptor();
      if (appDesc != null) {
        if (appDesc.getDefType().equals(DefType.APPLICATION)) {
          json.writeMapEntry(
              "app", String.format("%s:%s", appDesc.getNamespace(), appDesc.getName()));
        } else {
          json.writeMapEntry(
              "cmp", String.format("%s:%s", appDesc.getNamespace(), appDesc.getName()));
        }
      }

      if (ctx.getSerializeThemes()) {
        ThemeList themes = ctx.getThemeList();
        if (!themes.isEmpty()) {
          List<String> stringed = Lists.newArrayList();
          for (DefDescriptor<ThemeDef> theme : themes) {
            stringed.add(theme.getQualifiedName());
          }
          json.writeMapEntry("themes", stringed);
        }

        Optional<String> dynamicVarsUid = themes.getActiveDynamicVarsUid();
        if (dynamicVarsUid.isPresent()) {
          json.writeMapEntry("dynamicVarsUid", dynamicVarsUid.get());
        }
      }

      if (ctx.getRequestedLocales() != null) {
        List<String> locales = new ArrayList<>();
        for (Locale locale : ctx.getRequestedLocales()) {
          locales.add(locale.toString());
        }
        json.writeMapEntry("requestedLocales", locales);
      }
      Map<String, String> loadedStrings = Maps.newHashMap();
      Map<DefDescriptor<?>, String> clientLoaded = Maps.newHashMap();
      clientLoaded.putAll(ctx.getClientLoaded());
      for (Map.Entry<DefDescriptor<?>, String> entry : ctx.getLoaded().entrySet()) {
        loadedStrings.put(
            String.format(
                "%s@%s", entry.getKey().getDefType().toString(), entry.getKey().getQualifiedName()),
            entry.getValue());
        clientLoaded.remove(entry.getKey());
      }
      if (forClient) {
        for (DefDescriptor<?> deleted : clientLoaded.keySet()) {
          loadedStrings.put(
              String.format("%s@%s", deleted.getDefType().toString(), deleted.getQualifiedName()),
              DELETED);
        }
      }
      if (loadedStrings.size() > 0) {
        json.writeMapKey("loaded");
        json.writeMap(loadedStrings);
      }
      if (ctx.getSerializeLastMod()) {
        json.writeMapEntry("lastmod", Long.toString(AuraBaseServlet.getLastMod()));
      }

      TestContextAdapter testContextAdapter = Aura.get(TestContextAdapter.class);
      if (testContextAdapter != null) {
        TestContext testContext = testContextAdapter.getTestContext();
        if (testContext != null) {
          json.writeMapEntry("test", testContext.getName());
        }
      }

      if (ctx.getFrameworkUID() != null) {
        json.writeMapEntry("fwuid", ctx.getFrameworkUID());
      }

      if (forClient) {
        // client needs value providers, urls don't
        boolean started = false;

        for (GlobalValueProvider valueProvider : ctx.getGlobalProviders().values()) {
          if (!valueProvider.isEmpty()) {
            if (!started) {
              json.writeMapKey("globalValueProviders");
              json.writeArrayBegin();
              started = true;
            }
            json.writeComma();
            json.writeIndent();
            json.writeMapBegin();
            json.writeMapEntry("type", valueProvider.getValueProviderKey().getPrefix());
            json.writeMapEntry("values", valueProvider.getData());
            json.writeMapEnd();
          }
        }

        if (started) {
          json.writeArrayEnd();
        }

        //
        // Now comes the tricky part, we have to serialize all of the definitions that are
        // required on the client side, and, of all types. This way, we won't have to handle
        // ugly cases of actual definitions nested inside our configs, and, we ensure that
        // all dependencies actually get sent to the client. Note that the 'loaded' set needs
        // to be updated as well, but that needs to happen prior to this.
        //
        Map<DefDescriptor<? extends Definition>, Definition> defMap;

        defMap = ctx.getDefRegistry().filterRegistry(ctx.getPreloadedDefinitions());

        if (defMap.size() > 0) {
          List<Definition> componentDefs = Lists.newArrayList();
          List<Definition> eventDefs = Lists.newArrayList();
          List<Definition> libraryDefs = Lists.newArrayList();

          for (Map.Entry<DefDescriptor<? extends Definition>, Definition> entry :
              defMap.entrySet()) {
            DefDescriptor<? extends Definition> desc = entry.getKey();
            DefType dt = desc.getDefType();
            Definition d = entry.getValue();
            //
            // Ignore defs that ended up not being valid. This is arguably something
            // that the MDR should have done when filtering.
            //
            if (d != null) {
              if (DefType.COMPONENT.equals(dt) || DefType.APPLICATION.equals(dt)) {
                componentDefs.add(d);
              } else if (DefType.EVENT.equals(dt)) {
                eventDefs.add(d);
              } else if (DefType.LIBRARY.equals(dt)) {
                libraryDefs.add(d);
              }
            }
          }
          writeDefs(json, "componentDefs", componentDefs);
          writeDefs(json, "eventDefs", eventDefs);
          writeDefs(json, "libraryDefs", libraryDefs);
        }
        ctx.serializeAsPart(json);
      }
      json.writeMapEnd();
    }
Exemplo n.º 14
0
 private void writeDefs(Json json, String name, List<Definition> writable) throws IOException {
   if (writable.size() > 0) {
     Collections.sort(writable, DEFSORTER);
     json.writeMapEntry(name, writable);
   }
 }