@Override
  public void onReceive(Context context, Intent intent) {
    ExtensionManager extensionManager = ExtensionManager.getInstance(context);
    if (extensionManager.cleanupExtensions()) {
      LOGD(TAG, "Extension cleanup performed and action taken.");

      Intent widgetUpdateIntent = new Intent(context, DashClockService.class);
      widgetUpdateIntent.setAction(DashClockService.ACTION_UPDATE_WIDGETS);
      context.startService(widgetUpdateIntent);
    }

    // If this is a replacement or change in the package, update all active extensions from
    // this package.
    String action = intent.getAction();
    if (Intent.ACTION_PACKAGE_CHANGED.equals(action)
        || Intent.ACTION_PACKAGE_REPLACED.equals(action)) {
      String packageName = intent.getData().getSchemeSpecificPart();
      if (TextUtils.isEmpty(packageName)) {
        return;
      }

      List<ComponentName> activeExtensions = extensionManager.getActiveExtensionNames();
      for (ComponentName cn : activeExtensions) {
        if (packageName.equals(cn.getPackageName())) {
          Intent extensionUpdateIntent = new Intent(context, DashClockService.class);
          extensionUpdateIntent.setAction(DashClockService.ACTION_UPDATE_EXTENSIONS);
          extensionUpdateIntent.putExtra(
              DashClockService.EXTRA_COMPONENT_NAME, cn.flattenToShortString());
          context.startService(extensionUpdateIntent);
        }
      }
    }
  }
Ejemplo n.º 2
0
  public void initialize() {
    this.sourceType = ExtensionManager.getInstance().getType(this.sourceTypeName);
    if (this.sourceType == null)
      throw new RuntimeException("Unknown source type '" + this.sourceType + "'");

    this.resultType = ExtensionManager.getInstance().getType(this.resultTypeName);
    if (this.resultType == null)
      throw new RuntimeException("Unknown result type '" + this.resultType + "'");

    for (Parameter par : this.parameter) {
      par.setType(ExtensionManager.getInstance().getType(par.getTypeName()));

      if (par.getType() == null)
        throw new RuntimeException("Unknown parameter type '" + this.resultType + "'");
    }
  }
Ejemplo n.º 3
0
  public void postPurge(Session session, String fldPath)
      throws AccessDeniedException, RepositoryException, PathNotFoundException, DatabaseException {
    log.debug("postPurge({}, {})", new Object[] {session, fldPath});

    try {
      ExtensionManager em = ExtensionManager.getInstance();
      List<FolderExtension> col = em.getPlugins(FolderExtension.class);
      Collections.sort(col, new OrderComparator<FolderExtension>());

      for (FolderExtension ext : col) {
        log.debug("Extension class: {}", ext.getClass().getCanonicalName());
        ext.postPurge(session, fldPath);
      }
    } catch (ServiceConfigurationError e) {
      log.error(e.getMessage(), e);
    }
  }
Ejemplo n.º 4
0
  public void postCopy(XASession session, Ref<Node> refSrcFolderNode, Ref<Node> refNewFolderNode)
      throws AccessDeniedException, RepositoryException, PathNotFoundException, ItemExistsException,
          IOException, DatabaseException, UserQuotaExceededException {
    log.debug("postCopy({}, {}, {})", new Object[] {session, refSrcFolderNode, refNewFolderNode});

    try {
      ExtensionManager em = ExtensionManager.getInstance();
      List<FolderExtension> col = em.getPlugins(FolderExtension.class);
      Collections.sort(col, new OrderComparator<FolderExtension>());

      for (FolderExtension ext : col) {
        log.debug("Extension class: {}", ext.getClass().getCanonicalName());
        ext.postCopy(session, refSrcFolderNode, refNewFolderNode);
      }
    } catch (ServiceConfigurationError e) {
      log.error(e.getMessage(), e);
    }
  }
Ejemplo n.º 5
0
  protected void wikiProfile() {
    ext.use(NoTransformer.class).withRole("parse");
    ext.use(new DateParser("yyyy-MM-dd HH:mm:ss Z"));
    ext.use(SyntaxTransformer.class).withRole("syntax");
    ext.use(ContentClassifier.class);
    ext.use(ArchiveIndex.class);
    ext.use(SiteUpdated.class);
    ext.use(TemplateContentTransformer.class)
        .withRole("template")
        .forContent(not(prop("class", "template")));
    ext.use(TemplateContentTransformer.class).forContent(prop("class", "template"));
    ext.use(TemplateLayoutTransformer.class).withRole("layout");

    ext.use(HandlebarsTemplateLanguage.class).withRole("default");

    ext.use(PegdownSyntax.class).withRole("md");
    ext.use(PegdownSyntax.class).withRole("markdown");
    ext.use(SimpleSyntax.class).withRole("html");

    ext.use(new HighlightJsHighlighter().withStyle("idea"));
  }
Ejemplo n.º 6
0
  protected void blogProfile() {
    ext.use(NoTransformer.class).withRole("parse");
    ext.use(new MetadataTransfromer("class", "post")).forContent(path("_posts/.*"));
    ext.use(new MetadataTransfromer("layout", "post")).forContent(path("_posts/.*"));
    ext.use(new JekyllDateParser()).forContent(prop("class", "post"));
    ext.use(new ShortUrlTransformer()).forContent(prop("class", "post"));
    ext.use(SyntaxTransformer.class).withRole("syntax");
    ext.use(ContentClassifier.class);
    ext.use(ArchiveIndex.class);
    ext.use(SiteUpdated.class);
    ext.use(TemplateContentTransformer.class)
        .withRole("template")
        .forContent(not(prop("class", "template")));
    ext.use(TemplateContentTransformer.class).forContent(prop("class", "template"));
    ext.use(TemplateLayoutTransformer.class).withRole("layout");

    ext.use(HandlebarsTemplateLanguage.class).withRole("default");

    ext.use(PegdownSyntax.class).withRole("md");
    ext.use(PegdownSyntax.class).withRole("markdown");
    ext.use(SimpleSyntax.class).withRole("html");
    ext.use(SimpleSyntax.class).withRole("xml");

    ext.use(new HighlightJsHighlighter().withStyle("idea"));
  }
Ejemplo n.º 7
0
  @Override
  protected void configure() {
    if (profile != null) {
      LOG.debug("Starting configuration with profile " + profile);
    }
    bind(String.class).annotatedWith(Names.named("sourcedir")).toInstance(rootdir);
    bind(Site.class).asEagerSingleton();
    bind(ContentWriter.class).asEagerSingleton();
    bind(ContentParser.class).to(YamlHeaderContentParser.class).asEagerSingleton();

    if ("blog".equals(profile)) {
      blogProfile();
    } else {
      wikiProfile();
    }

    Matcher<TypeLiteral<?>> m =
        new AbstractMatcher<TypeLiteral<?>>() {
          @Override
          public boolean matches(TypeLiteral<?> typeLiteral) {
            return typeLiteral.getRawType().equals(String.class);
          }
        };
    bindListener(
        Matchers.any(),
        new TypeListener() {

          @Override
          public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
            encounter.register(
                new InjectionListener<I>() {
                  @Override
                  public void afterInjection(I injectee) {
                    for (Field f : injectee.getClass().getDeclaredFields()) {
                      if (f.isAnnotationPresent(Parameter.class)) {
                        if (parameters.get(injectee.getClass()) != null) {
                          String v = parameters.get(injectee.getClass()).get(f.getName());
                          if (v != null) {
                            try {
                              f.setAccessible(true);
                              f.set(injectee, v);
                            } catch (IllegalAccessException e) {
                              throw new GeneratorException(
                                  "Can't inject parameter " + f.getName() + " to " + injectee, e);
                            }
                          }
                        }
                      }
                    }
                  }
                });
          }
        });

    // extend the config with scripts.
    ext.closeUsage();
    readConfig();
    ext.closeUsage();

    bind(ExtensionManager.class).toInstance(ext);
    bind(GuiceConfig.class).toInstance(this);
  }