Package org.apache.shindig.gadgets.uri.JsUriManager

Examples of org.apache.shindig.gadgets.uri.JsUriManager.JsUri


  }

  private void checkWrapCode(JsCompileMode mode, boolean wraps) throws Exception {
    IMocksControl control = createControl();
    JsRequest request = control.createMock(JsRequest.class);
    JsUri jsUri = control.createMock(JsUri.class);
    expect(jsUri.getCompileMode()).andReturn(mode);
    expect(request.getJsUri()).andReturn(jsUri);
    JsResponseBuilder builder = new JsResponseBuilder().appendJs("JS_CODE", "source");
    AnonFuncWrappingProcessor processor = new AnonFuncWrappingProcessor();
    control.replay();
    assertTrue(processor.process(request, builder));
View Full Code Here


  private JsUri mockJsUri(JsCompileMode mode) {
    return mockJsUri(mode, false);
  }

  private JsUri mockJsUri(JsCompileMode mode, boolean isJsload) {
    JsUri result = createMock(JsUri.class);
    expect(result.getCompileMode()).andStubReturn(mode);
    expect(result.getRepository()).andStubReturn(null);
    expect(result.isJsload()).andReturn(isJsload).anyTimes();
    replay(result);
    return result;
  }
View Full Code Here

    return result;
  }

  @Test
  public void processEmpty() throws Exception {
    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL);
    JsRequest jsRequest = new JsRequest(jsUri, null, false, null);
    JsResponseBuilder jsBuilder = new JsResponseBuilder();
    boolean actualReturnCode = processor.process(jsRequest, jsBuilder);
    assertTrue(actualReturnCode);
    assertEquals("", jsBuilder.build().toJsString());
View Full Code Here

    assertEquals("", jsBuilder.build().toJsString());
  }

  @Test
  public void processWithOneText() throws Exception {
    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL);
    JsRequest jsRequest = new JsRequest(jsUri, null, false, null);
    JsResponseBuilder jsBuilder = new JsResponseBuilder();
    jsBuilder.appendJs(textJsContent1);
    boolean actualReturnCode = processor.process(jsRequest, jsBuilder);
    assertTrue(actualReturnCode);
View Full Code Here

        jsBuilder.build().toJsString());
  }

  @Test
  public void processWithOneNonEmptyFeature() throws Exception {
    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL);
    JsRequest jsRequest = new JsRequest(jsUri, null, false, null);
    JsResponseBuilder jsBuilder = new JsResponseBuilder();
    jsBuilder.appendJs(featureJsContent1);
    boolean actualReturnCode = processor.process(jsRequest, jsBuilder);
    assertTrue(actualReturnCode);
View Full Code Here

        jsBuilder.build().toJsString());
  }

  @Test
  public void processWithOneEmptyFeature() throws Exception {
    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL);
    JsRequest jsRequest = new JsRequest(jsUri, null, false, null);
    JsResponseBuilder jsBuilder = new JsResponseBuilder();
    jsBuilder.appendJs(featureJsContent3);
    boolean actualReturnCode = processor.process(jsRequest, jsBuilder);
    assertTrue(actualReturnCode);
View Full Code Here

        jsBuilder.build().toJsString());
  }

  @Test
  public void processWithFeaturesAndTexts() throws Exception {
    JsUri jsUri = mockJsUri(JsCompileMode.CONCAT_COMPILE_EXPORT_ALL);
    JsRequest jsRequest = new JsRequest(jsUri, null, false, null);
    JsResponseBuilder jsBuilder = new JsResponseBuilder();
    jsBuilder.appendJs(textJsContent1);
    jsBuilder.appendJs(featureJsContent1);
    jsBuilder.appendJs(featureJsContent2);
View Full Code Here

    }
    return source.substring(0, colIx);
  }

  public Iterable<JsContent> getJsContent(JsUri jsUri, FeatureBundle bundle) {
    jsUri = new JsUri(jsUri) {
      @Override
      public boolean isDebug() {
        // Force debug JS in the raw JS content retrieved.
        return true;
      }
View Full Code Here

    this.compiler = compiler;
  }

  public boolean process(JsRequest request, JsResponseBuilder builder) throws JsException {
    // Get JavaScript content from features aliases request.
    JsUri jsUri = request.getJsUri();
    GadgetContext ctx = new JsGadgetContext(jsUri);

    FeatureRegistry registry;
    try {
      registry = registryProvider.get(jsUri.getRepository());
    } catch (GadgetException e) {
      throw new JsException(e.getHttpStatusCode(), e.getMessage());
    }

    // TODO: possibly warn on unknown/unrecognized libs.
    List<FeatureBundle> requestedBundles = registry.getFeatureResources(
        ctx, jsUri.getLibs(), null).getBundles();
    List<FeatureBundle> loadedBundles = registry.getFeatureResources(
        ctx, jsUri.getLoadedLibs(), null).getBundles();

    Set<String> loadedFeatures = Sets.newHashSet();
    for (FeatureBundle bundle : loadedBundles) {
      loadedFeatures.add(bundle.getName());
      builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, true));
      builder.appendExterns(bundle.getApis(ApiDirective.Type.JS, false));
    }

    // Collate all JS desired for the current request.
    boolean isProxyCacheable = true;

    for (FeatureBundle bundle : requestedBundles) {
      // Exclude all transitively-dependent loaded features.
      if (loadedFeatures.contains(bundle.getName())) {
        continue;
      }
      builder.appendAllJs(compiler.getJsContent(jsUri, bundle));
      for (FeatureResource featureResource : bundle.getResources()) {
        isProxyCacheable = isProxyCacheable && featureResource.isProxyCacheable();
      }
    }

    builder.setProxyCacheable(isProxyCacheable);
    UriStatus uriStatus = jsUri.getStatus();
    setResponseCacheTtl(builder, uriStatus != null ? uriStatus : UriStatus.VALID_UNVERSIONED);
    return true;
  }
View Full Code Here

  private static final Pattern ONLOAD_FN_PATTERN = Pattern.compile("[a-zA-Z0-9_]+");

  public boolean process(JsRequest request, JsResponseBuilder builder)
      throws JsException {
    JsUri jsUri = request.getJsUri();

    // Add onload handler to add callback function.
    String onloadStr = jsUri.getOnload();
    if (onloadStr != null) {
      if (!ONLOAD_FN_PATTERN.matcher(onloadStr).matches()) {
        throw new JsException(HttpServletResponse.SC_BAD_REQUEST, ONLOAD_FUNCTION_NAME_ERROR);
      }
      builder.appendJs(createOnloadScript(onloadStr), ONLOAD_CODE_ID);
    } else if (jsUri.isNohint()) {
      // "Second-stage" JS, which may have had a callback set by loader.
      // This type of JS doesn't create a hint, but does attempt to use one.
      builder.appendJs(JSL_CALLBACK_JS, JSL_CODE_ID);
    }
    return true;
View Full Code Here

TOP

Related Classes of org.apache.shindig.gadgets.uri.JsUriManager.JsUri

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.