示例#1
0
  public void importSite(OperationCallback op) {
    // =============== COLLECT ==============
    XElement feed = op.getContext().getDomain().getSettings().find("Feed");

    if (feed != null) {
      // there are two special channels - Pages and Blocks
      for (XElement chan : feed.selectAll("Channel")) this.collectChannel(chan);
    }

    /* TODO need to update Stored Proc to handle Path instead of UUID as a key
    this.collectWWW();
    */

    if (op.hasErrors()) {
      op.error("Unable to import site, file collection failed");
      return;
    }

    // =============== PREP ==============
    this.prep();

    if (op.hasErrors()) {
      op.error("Unable to import site, file prep failed");
      return;
    }

    // =============== IMPORT ==============
    this.doImport(op);
  }
示例#2
0
  public void collectChannel(XElement chan) {
    String alias = chan.getAttribute("Alias");

    if (alias == null) alias = chan.getAttribute("Name");

    // don't index blocks be themselves
    // if ("Blocks".equals(alias))
    //	return;

    // TODO remove
    // if (!"Pages".equals(alias))
    //	return;

    String perpath = chan.getAttribute("Path", ""); // or empty string

    this.collectArea("feed", alias, false, perpath);

    this.collectArea("feed", alias, true, perpath);
  }
示例#3
0
  public static ISettingsObfuscator prepDomainObfuscator(String obclass, String seed) {
    ISettingsObfuscator obfuscator = null;

    if (StringUtil.isEmpty(obclass)) obclass = "divconq.util.BasicSettingsObfuscator";

    try {
      obfuscator = (ISettingsObfuscator) Hub.instance.getInstance(obclass);
    } catch (Exception x) {
      OperationContext.get().error("Bad Settings Obfuscator");
      return null;
    }

    XElement clock1 = Hub.instance.getConfig().find("Clock");

    String obid = (clock1 != null) ? clock1.getAttribute("Id") : null;

    obfuscator.init(
        new XElement("Clock", new XAttribute("Id", obid), new XAttribute("Feed", seed)));

    return obfuscator;
  }
示例#4
0
  public void prepDomainSchedule() {
    // cancel and remove any previous schedules
    if (this.schedulenodes.size() > 0) {
      OperationContext.get().info("Cancelling schedules for " + this.getAlias());

      for (ISchedule sch : this.schedulenodes) {
        OperationContext.get().info("- schedule: " + sch.task().getTitle());
        sch.cancel();
      }
    }

    this.schedulenodes.clear();

    if (this.overrideSettings == null) return;

    // now load new schedules
    OperationContext.get().info("Prepping schedules for " + this.getAlias());

    for (XElement schedule : this.overrideSettings.selectAll("Schedules/*")) {
      OperationContext.get().info("- find schedule: " + schedule.getAttribute("Title"));

      ISchedule sched =
          "CommonSchedule".equals(schedule.getName()) ? new CommonSchedule() : new SimpleSchedule();

      sched.init(schedule);

      sched.setTask(
          new Task()
              .withId(Task.nextTaskId("DomainSchedule"))
              .withTitle("Domain Scheduled Task: " + schedule.getAttribute("Title"))
              .withContext(
                  new OperationContextBuilder()
                      .withRootTaskTemplate()
                      .withDomainId(this.getId())
                      .toOperationContext())
              .withWork(
                  trun -> {
                    OperationContext.get()
                        .info(
                            "Executing schedule: "
                                + trun.getTask().getTitle()
                                + " for domain "
                                + trun.getTask().getContext().getDomain().getAlias());

                    if (schedule.hasAttribute("MethodName") && (this.watcher != null))
                      this.watcher.tryExecuteMethod(
                          schedule.getAttribute("MethodName"), new Object[] {trun});
                  }));

      OperationContext.get()
          .info(
              "- prepped schedule: "
                  + schedule.getAttribute("Title")
                  + " next run "
                  + new DateTime(sched.when()));

      this.schedulenodes.add(sched);

      Hub.instance.getScheduler().addNode(sched);
    }
  }
示例#5
0
  public void collectFeedFile(Path sfile) {
    XElement feed = OperationContext.get().getDomain().getSettings().find("Feed");

    if ((feed == null) || (sfile == null)) return;

    sfile = sfile.toAbsolutePath().normalize();

    DomainInfo di = OperationContext.get().getDomain();

    Path dmpath = di.getPath().toAbsolutePath().normalize();

    Path relpath = dmpath.relativize(sfile);

    if (relpath.getNameCount() < 3) return;

    // String wwwpathf1 = preview ? "/" + area +  "-preview/" + alias : "/" + area +  "/" + alias;
    // Path wwwsrc1 = di.resolvePath(wwwpathf1).toAbsolutePath().normalize();

    String area = "feed";
    String alias = relpath.getName(1).toString();
    String perpath = "";

    // there are two special channels - Pages and Blocks
    for (XElement chan : feed.selectAll("Channel")) {
      String calias = chan.getAttribute("Alias");

      if (calias == null) calias = chan.getAttribute("Name");

      if (calias.equals(alias)) {
        perpath = chan.getAttribute("Path", ""); // or empty string
        break;
      }
    }

    System.out.println("relpath: " + relpath);

    relpath = relpath.subpath(2, relpath.getNameCount());

    // System.out.println("abs: " + feedsrc1);

    // Path relpath = wwwsrc1.relativize(sfile);

    // System.out.println("rel: " + relpath);

    String cleanpath = relpath.toString();

    int pos = cleanpath.indexOf('.');

    if (pos != -1) cleanpath = cleanpath.substring(0, pos); // + ".dcf.xml";

    String innerpath = perpath + "/" + cleanpath;

    FileImporter imp = new FeedImporter();

    imp.setKey(innerpath);
    imp.setArea(area);
    imp.setAlias(alias);

    OperationContext.get().info("Indexing " + alias + " > " + innerpath);

    ImportWebsiteTool.this.feedpaths.put(innerpath, imp);

    String pubfeedpath = "/" + area + "/" + alias + "/" + cleanpath + ".dcf.xml";
    Path pubfeedsrc = di.resolvePath(pubfeedpath).normalize();

    if (Files.exists(pubfeedsrc)) {
      OperationContext.get().info("Indexing published " + alias + " > " + innerpath);
      imp.setFile(pubfeedsrc);
    }

    String prefeedpath = "/" + area + "-preview/" + alias + "/" + cleanpath + ".dcf.xml";
    Path prefeedsrc = di.resolvePath(prefeedpath).normalize();

    if (Files.exists(prefeedsrc)) {
      OperationContext.get().info("Indexing preview " + alias + " > " + innerpath);
      imp.setPreviewFile(prefeedsrc);
    }
  }
示例#6
0
  public void init(XElement config) {
    this.dictionary = null;
    this.locales.clear();

    // for a sub-site, may have additional dict to load
    if (this != this.domain.getRootSite()) {
      LocalFileStore pubfs = Hub.instance.getPublicFileStore();

      Path cpath =
          pubfs.resolvePath("/dcw/" + this.domain.getAlias() + "/sites/" + this.alias + "/config");

      if ((cpath != null) && Files.exists(cpath)) {
        // dictionary

        Path dicpath = cpath.resolve("dictionary.xml");

        if (Files.exists(dicpath)) {
          this.dictionary = new Dictionary();
          this.dictionary.setParent(this.domain.getDomainInfo().getDictionary());
          this.dictionary.load(dicpath);
        }
      }
    }

    if (config != null) {
      // this settings are only valid for sub sites
      if (this != this.domain.getRootSite()) {
        if (config.hasAttribute("Integration")) {
          try {
            this.integration = SiteIntegration.valueOf(config.getAttribute("Integration", "Files"));
          } catch (Exception x) {
            this.integration = SiteIntegration.Files;
          }
        }
      }

      if (config.hasAttribute("Locale")) {
        this.locale = config.getAttribute("Locale");

        this.localedef = this.getLocaleDefinition(this.locale);

        // add the list of locales supported for this site
        this.locales.put(this.locale, this.localedef);
      }

      // these settings are valid for root and sub sites

      for (XElement pel : config.selectAll("Locale")) {
        String lname = pel.getAttribute("Name");

        if (StringUtil.isEmpty(lname)) continue;

        LocaleDefinition def = this.getLocaleDefinition(lname);

        this.locales.put(lname, def);

        for (XElement del : pel.selectAll("Domain")) {
          String dname = del.getAttribute("Name");

          if (StringUtil.isEmpty(lname)) continue;

          this.domainlocales.put(dname, def);
        }
      }
    }
  }