Concept:Extension/Java

From BITPlan Wiki
Revision as of 14:29, 24 November 2020 by Wf (talk | contribs) (created by WikiTask 2020-11-24T13:29:45Z)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

java code

@// This is a rythm template
@// the args are the standard wikiTask arguments
@import org.sidif.triple.TripleQuery
@import org.sidif.triple.Triple
@import com.alibaba.fastjson.JSON
@args() {
  String title 
  String logo
  org.sidif.wiki.WikiTask wikiTask
  org.sidif.triple.TripleStore tripleStore
}


@def static {

  /**
   * Base class
   */
  static abstract class TopicBase {
    // each Topic has a pageid - for non subobject thats the pagename
    public String pageid;

    /**
     * get a WikiSon version of the given name value
     * 
     * @param name
     * @param value
     * @return - the string representation
     */
    public String toWikiSon(String name, String value) {
      String result = "<!-- " + name + " is null-->\n";
      if (value != null)
        result = "|" + name + "=" + value + "\n";
      return result;
    }

    /**
     * get the SiDIF representation of the given property
     * 
     * @param name - the name of the property
     * @param value - the value of the property
     * @param type - the type of the property
     * @return - the SiDIF Sting representation of the property
     */
    public static String propertySiDIF(String name, String value, String type) {
      // default is a comment line which can be filled by uncommenting
      String result = String.format("# is is %s of it\n",name);;
      // if the value is not empty
      if ((value != null) && (!("".equals(value.trim())))) {
        // do we need to quote the result?
        String quote = "";
        // this depends on the Type
        if ("Text".equals(type)) {
          quote = "\"";
        }
        // create a SIDIF Property line like
        // "John" is lastname of it
        // convert double quotes to single quotes - FIXME - should we escape instead?
        value=value.replace("\"","'");
        result = String.format("%s%s%s is %s of it\n",quote,value,quote,name);
      }
      // return the SiDIF property line
      return result;
    }

    /**
     * get me as a String
     * 
     * @param name
     * @param value
     * @return
     */
    public static String propertySiDIF(String name, String value) {
      String result = propertySiDIF(name, value, "Text");
      return result;
    }

    /**
     * check if the given boolean String value is true
     * 
     * @param value
     * @return true if the value is not null and has true/TRUE as it's string
     *         content
     */
    public boolean isTrue(String value) {
      boolean result = false;
      if (value != null && value.toLowerCase().equals("true")) {
        result = true;
      }
      return result;
    }

    /**
     * initialize
     */
    public void init(TripleQuery query) {
    }
  } // TopicBase
 /**
  * Wiki
  * A wiki is an application, typically a web application, which allows collaborative modification, extension, or deletion of its content and structure. In a typical wiki, text is written using a simplified markup language (known as 'wiki markup') or a rich-text editor. While a wiki is a type of content management system, it differs from a blog or most other such systems in that the content is created without any defined owner or leader, and wikis have little implicit structure, allowing structure to emerge according to the needs of the users.
  */
  public static class Wiki extends TopicBase {
  
    public String id;
    public String siteurl;
    public String scriptPath;
    public String purpose;
    public String language;
    public String since;
    public String until;
    public String backup;
    public String server;
    public String safes;
    public String owner;
    public String project;

    public String getId() { return id; }
    public void setId(String pId) { id=pId; }
    public String getSiteurl() { return siteurl; }
    public void setSiteurl(String pSiteurl) { siteurl=pSiteurl; }
    public String getScriptPath() { return scriptPath; }
    public void setScriptPath(String pScriptPath) { scriptPath=pScriptPath; }
    public String getPurpose() { return purpose; }
    public void setPurpose(String pPurpose) { purpose=pPurpose; }
    public String getLanguage() { return language; }
    public void setLanguage(String pLanguage) { language=pLanguage; }
    public String getSince() { return since; }
    public void setSince(String pSince) { since=pSince; }
    public String getUntil() { return until; }
    public void setUntil(String pUntil) { until=pUntil; }
    public String getBackup() { return backup; }
    public void setBackup(String pBackup) { backup=pBackup; }
    public String getServer() { return server; }
    public void setServer(String pServer) { server=pServer; }
    public String getSafes() { return safes; }
    public void setSafes(String pSafes) { safes=pSafes; }
    public String getOwner() { return owner; }
    public void setOwner(String pOwner) { owner=pOwner; }
    public String getProject() { return project; }
    public void setProject(String pProject) { project=pProject; }
    /**
     * convert this Wiki to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Wiki to a WikiSon string
     * @return the WikiSon representation of this Wiki
     */
    public String toWikiSon() {
      String wikison= "{{Wiki\n";
      wikison+=toWikiSon("id",id);
      wikison+=toWikiSon("siteurl",siteurl);
      wikison+=toWikiSon("scriptPath",scriptPath);
      wikison+=toWikiSon("purpose",purpose);
      wikison+=toWikiSon("language",language);
      wikison+=toWikiSon("since",since);
      wikison+=toWikiSon("until",until);
      wikison+=toWikiSon("backup",backup);
      wikison+=toWikiSon("server",server);
      wikison+=toWikiSon("safes",safes);
      wikison+=toWikiSon("owner",owner);
      wikison+=toWikiSon("project",project);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this Wiki to a SiDIF string
     * @return the SiDIF representation of this Wiki
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Wiki\n",this.pageid);
      siDIF+=propertySiDIF("id",id,"Text");
      siDIF+=propertySiDIF("siteurl",siteurl,"Text");
      siDIF+=propertySiDIF("scriptPath",scriptPath,"Text");
      siDIF+=propertySiDIF("purpose",purpose,"Text");
      siDIF+=propertySiDIF("language",language,"Text");
      siDIF+=propertySiDIF("since",since,"Date");
      siDIF+=propertySiDIF("until",until,"Date");
      siDIF+=propertySiDIF("backup",backup,"Date");
      siDIF+=propertySiDIF("server",server,"Page");
      siDIF+=propertySiDIF("safes",safes,"Text");
      siDIF+=propertySiDIF("owner",owner,"Page");
      siDIF+=propertySiDIF("project",project,"Page");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Wiki
     */
    public Wiki() {}

    /**
     * construct a Wiki from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pWikiTriple - the triple to construct me from
     */
    public Wiki(TripleQuery query,Triple pWikiTriple) {
      this(query,pWikiTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Wiki from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Wiki(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple idTriple=query.selectSingle(pageid,"id",null);
      if (idTriple==null)
        idTriple=query.selectSingle(pageid,"Property:Wiki_id",null);
      if (idTriple!=null) 
        id=idTriple.getObject().toString();
      Triple siteurlTriple=query.selectSingle(pageid,"siteurl",null);
      if (siteurlTriple==null)
        siteurlTriple=query.selectSingle(pageid,"Property:Wiki_siteurl",null);
      if (siteurlTriple!=null) 
        siteurl=siteurlTriple.getObject().toString();
      Triple scriptPathTriple=query.selectSingle(pageid,"scriptPath",null);
      if (scriptPathTriple==null)
        scriptPathTriple=query.selectSingle(pageid,"Property:Wiki_scriptPath",null);
      if (scriptPathTriple!=null) 
        scriptPath=scriptPathTriple.getObject().toString();
      Triple purposeTriple=query.selectSingle(pageid,"purpose",null);
      if (purposeTriple==null)
        purposeTriple=query.selectSingle(pageid,"Property:Wiki_purpose",null);
      if (purposeTriple!=null) 
        purpose=purposeTriple.getObject().toString();
      Triple languageTriple=query.selectSingle(pageid,"language",null);
      if (languageTriple==null)
        languageTriple=query.selectSingle(pageid,"Property:Wiki_language",null);
      if (languageTriple!=null) 
        language=languageTriple.getObject().toString();
      Triple sinceTriple=query.selectSingle(pageid,"since",null);
      if (sinceTriple==null)
        sinceTriple=query.selectSingle(pageid,"Property:Wiki_since",null);
      if (sinceTriple!=null) 
        since=sinceTriple.getObject().toString();
      Triple untilTriple=query.selectSingle(pageid,"until",null);
      if (untilTriple==null)
        untilTriple=query.selectSingle(pageid,"Property:Wiki_until",null);
      if (untilTriple!=null) 
        until=untilTriple.getObject().toString();
      Triple backupTriple=query.selectSingle(pageid,"backup",null);
      if (backupTriple==null)
        backupTriple=query.selectSingle(pageid,"Property:Wiki_backup",null);
      if (backupTriple!=null) 
        backup=backupTriple.getObject().toString();
      Triple serverTriple=query.selectSingle(pageid,"server",null);
      if (serverTriple==null)
        serverTriple=query.selectSingle(pageid,"Property:Wiki_server",null);
      if (serverTriple!=null) 
        server=serverTriple.getObject().toString();
      Triple safesTriple=query.selectSingle(pageid,"safes",null);
      if (safesTriple==null)
        safesTriple=query.selectSingle(pageid,"Property:Wiki_safes",null);
      if (safesTriple!=null) 
        safes=safesTriple.getObject().toString();
      Triple ownerTriple=query.selectSingle(pageid,"owner",null);
      if (ownerTriple==null)
        ownerTriple=query.selectSingle(pageid,"Property:Wiki_owner",null);
      if (ownerTriple!=null) 
        owner=ownerTriple.getObject().toString();
      Triple projectTriple=query.selectSingle(pageid,"project",null);
      if (projectTriple==null)
        projectTriple=query.selectSingle(pageid,"Property:Wiki_project",null);
      if (projectTriple!=null) 
        project=projectTriple.getObject().toString();
      init(query);
    } // constructor for Wiki
    
    // >>>{user defined topic code}{Wiki}{Wiki}
    // <<<{user defined topic code}{Wiki}{Wiki}
  } // class Wiki
  /**
   * Manager for Wiki
   */
  public static class WikiManager extends TopicBase {
 
    public String topicName="Wiki";
    public transient List<Wiki> mWikis=new ArrayList<Wiki>();
    public transient Map<String,Wiki> mWikiMap=new LinkedHashMap<String,Wiki>();

    /**
     * get my Wikis
     */
    public List<Wiki> getWikis() {
      List<Wiki> result=this.mWikis;
      return result;
    }

    /**
     *  add a new Wiki 
     */
    public Wiki add(Wiki pWiki) {
      mWikis.add(pWiki);
      mWikiMap.put(pWiki.getPageid(),pWiki);
      return pWiki;
    }

    /**
     *  add a new Wiki from the given triple
     */
    public Wiki add(TripleQuery query,Triple pWikiTriple) {
      Wiki lWiki=new Wiki(query,pWikiTriple);
      add(lWiki);
      return lWiki;
    }

    // reinitialize my mWiki map
    public void reinit() {
      mWikiMap.clear();
      for (Wiki lWiki:mWikis) {
        mWikiMap.put(lWiki.getPageid(),lWiki);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static WikiManager fromJson(String json) {
      WikiManager result=JSON.parseObject(json, WikiManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Wiki Manager
    public WikiManager() {}

    // add Wikis from the given query
    public void addWikis(TripleQuery pWikiQuery,TripleQuery query) {
      if (pWikiQuery!=null) {
        for (Triple lWikiTriple:pWikiQuery.getTriples()) {
          add(query,lWikiTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public WikiManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lWikiQuery=query.query(null,"isA","Wiki");
      addWikis(lWikiQuery,query);
      // then the SMW triplestore
      lWikiQuery=query.query(null,"Property:IsA","Wiki");
      addWikis(lWikiQuery,query);
      init(query);
    } // constructor for Wiki Manager
    
    // >>>{user defined topicmanager code}{Wiki}{Wiki}
    // <<<{user defined topicmanager code}{Wiki}{Wiki}
  } // class Wiki Manager
 /**
  * TransferPage
  * a Wiki page which might be bulk-transferred to another Wiki
  */
  public static class TransferPage extends TopicBase {
  
    public String page;
    public String wiki;

    public String getPage() { return page; }
    public void setPage(String pPage) { page=pPage; }
    public String getWiki() { return wiki; }
    public void setWiki(String pWiki) { wiki=pWiki; }
    /**
     * convert this TransferPage to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this TransferPage to a WikiSon string
     * @return the WikiSon representation of this TransferPage
     */
    public String toWikiSon() {
      String wikison= "{{TransferPage\n";
      wikison+=toWikiSon("page",page);
      wikison+=toWikiSon("wiki",wiki);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this TransferPage to a SiDIF string
     * @return the SiDIF representation of this TransferPage
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA TransferPage\n",this.pageid);
      siDIF+=propertySiDIF("page",page,"Text");
      siDIF+=propertySiDIF("wiki",wiki,"Page");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for TransferPage
     */
    public TransferPage() {}

    /**
     * construct a TransferPage from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pTransferPageTriple - the triple to construct me from
     */
    public TransferPage(TripleQuery query,Triple pTransferPageTriple) {
      this(query,pTransferPageTriple.getSubject().toString());
    } // constructor

    /**
     * construct a TransferPage from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public TransferPage(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple pageTriple=query.selectSingle(pageid,"page",null);
      if (pageTriple==null)
        pageTriple=query.selectSingle(pageid,"Property:TransferPage_page",null);
      if (pageTriple!=null) 
        page=pageTriple.getObject().toString();
      Triple wikiTriple=query.selectSingle(pageid,"wiki",null);
      if (wikiTriple==null)
        wikiTriple=query.selectSingle(pageid,"Property:TransferPage_wiki",null);
      if (wikiTriple!=null) 
        wiki=wikiTriple.getObject().toString();
      init(query);
    } // constructor for TransferPage
    
    // >>>{user defined topic code}{TransferPage}{TransferPage}
    // <<<{user defined topic code}{TransferPage}{TransferPage}
  } // class TransferPage
  /**
   * Manager for TransferPage
   */
  public static class TransferPageManager extends TopicBase {
 
    public String topicName="TransferPage";
    public transient List<TransferPage> mTransferPages=new ArrayList<TransferPage>();
    public transient Map<String,TransferPage> mTransferPageMap=new LinkedHashMap<String,TransferPage>();

    /**
     * get my TransferPages
     */
    public List<TransferPage> getTransferPages() {
      List<TransferPage> result=this.mTransferPages;
      return result;
    }

    /**
     *  add a new TransferPage 
     */
    public TransferPage add(TransferPage pTransferPage) {
      mTransferPages.add(pTransferPage);
      mTransferPageMap.put(pTransferPage.getPageid(),pTransferPage);
      return pTransferPage;
    }

    /**
     *  add a new TransferPage from the given triple
     */
    public TransferPage add(TripleQuery query,Triple pTransferPageTriple) {
      TransferPage lTransferPage=new TransferPage(query,pTransferPageTriple);
      add(lTransferPage);
      return lTransferPage;
    }

    // reinitialize my mTransferPage map
    public void reinit() {
      mTransferPageMap.clear();
      for (TransferPage lTransferPage:mTransferPages) {
        mTransferPageMap.put(lTransferPage.getPageid(),lTransferPage);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static TransferPageManager fromJson(String json) {
      TransferPageManager result=JSON.parseObject(json, TransferPageManager.class);
      result.reinit();
      return result;
    }

    // default constructor for TransferPage Manager
    public TransferPageManager() {}

    // add TransferPages from the given query
    public void addTransferPages(TripleQuery pTransferPageQuery,TripleQuery query) {
      if (pTransferPageQuery!=null) {
        for (Triple lTransferPageTriple:pTransferPageQuery.getTriples()) {
          add(query,lTransferPageTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public TransferPageManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lTransferPageQuery=query.query(null,"isA","TransferPage");
      addTransferPages(lTransferPageQuery,query);
      // then the SMW triplestore
      lTransferPageQuery=query.query(null,"Property:IsA","TransferPage");
      addTransferPages(lTransferPageQuery,query);
      init(query);
    } // constructor for TransferPage Manager
    
    // >>>{user defined topicmanager code}{TransferPage}{TransferPage}
    // <<<{user defined topicmanager code}{TransferPage}{TransferPage}
  } // class TransferPage Manager
 /**
  * Extension
  * A MediaWiki extension
  */
  public static class Extension extends TopicBase {
  
    public String name;
    public String url;
    public String purpose;
    public String since;
    public String wiki;

    public String getName() { return name; }
    public void setName(String pName) { name=pName; }
    public String getUrl() { return url; }
    public void setUrl(String pUrl) { url=pUrl; }
    public String getPurpose() { return purpose; }
    public void setPurpose(String pPurpose) { purpose=pPurpose; }
    public String getSince() { return since; }
    public void setSince(String pSince) { since=pSince; }
    public String getWiki() { return wiki; }
    public void setWiki(String pWiki) { wiki=pWiki; }
    /**
     * convert this Extension to a JSON string
     */
    public String toJson() { return JSON.toJSONString(this); }

    /**
     * convert this Extension to a WikiSon string
     * @return the WikiSon representation of this Extension
     */
    public String toWikiSon() {
      String wikison= "{{Extension\n";
      wikison+=toWikiSon("name",name);
      wikison+=toWikiSon("url",url);
      wikison+=toWikiSon("purpose",purpose);
      wikison+=toWikiSon("since",since);
      wikison+=toWikiSon("wiki",wiki);
      wikison+="}}\n";
      return wikison;
    }

    /**
     * convert this Extension to a SiDIF string
     * @return the SiDIF representation of this Extension
     */
    public String toSiDIF() {
      String siDIF = String.format("%s isA Extension\n",this.pageid);
      siDIF+=propertySiDIF("name",name,"Text");
      siDIF+=propertySiDIF("url",url,"Url");
      siDIF+=propertySiDIF("purpose",purpose,"Text");
      siDIF+=propertySiDIF("since",since,"Date");
      siDIF+=propertySiDIF("wiki",wiki,"Page");
      return siDIF;
    }
 
    /**  
     * get the pageid for this topic
     */
    public String getPageid() { return pageid; };

    /**
     * default constructor for Extension
     */
    public Extension() {}

    /**
     * construct a Extension from the given Triple
     * @param query - the TripleQuery to get the triples from
     * @param pExtensionTriple - the triple to construct me from
     */
    public Extension(TripleQuery query,Triple pExtensionTriple) {
      this(query,pExtensionTriple.getSubject().toString());
    } // constructor

    /**
     * construct a Extension from the given pageId
     * @param query - the TripleQuery to get the triples from
     * @param pageid - pageid
     */
    public Extension(TripleQuery query,String pageid) {
      this.pageid=pageid;
      Triple nameTriple=query.selectSingle(pageid,"name",null);
      if (nameTriple==null)
        nameTriple=query.selectSingle(pageid,"Property:Extension_name",null);
      if (nameTriple!=null) 
        name=nameTriple.getObject().toString();
      Triple urlTriple=query.selectSingle(pageid,"url",null);
      if (urlTriple==null)
        urlTriple=query.selectSingle(pageid,"Property:Extension_url",null);
      if (urlTriple!=null) 
        url=urlTriple.getObject().toString();
      Triple purposeTriple=query.selectSingle(pageid,"purpose",null);
      if (purposeTriple==null)
        purposeTriple=query.selectSingle(pageid,"Property:Extension_purpose",null);
      if (purposeTriple!=null) 
        purpose=purposeTriple.getObject().toString();
      Triple sinceTriple=query.selectSingle(pageid,"since",null);
      if (sinceTriple==null)
        sinceTriple=query.selectSingle(pageid,"Property:Extension_since",null);
      if (sinceTriple!=null) 
        since=sinceTriple.getObject().toString();
      Triple wikiTriple=query.selectSingle(pageid,"wiki",null);
      if (wikiTriple==null)
        wikiTriple=query.selectSingle(pageid,"Property:Extension_wiki",null);
      if (wikiTriple!=null) 
        wiki=wikiTriple.getObject().toString();
      init(query);
    } // constructor for Extension
    
    // >>>{user defined topic code}{Extension}{Extension}
    // <<<{user defined topic code}{Extension}{Extension}
  } // class Extension
  /**
   * Manager for Extension
   */
  public static class ExtensionManager extends TopicBase {
 
    public String topicName="Extension";
    public transient List<Extension> mExtensions=new ArrayList<Extension>();
    public transient Map<String,Extension> mExtensionMap=new LinkedHashMap<String,Extension>();

    /**
     * get my Extensions
     */
    public List<Extension> getExtensions() {
      List<Extension> result=this.mExtensions;
      return result;
    }

    /**
     *  add a new Extension 
     */
    public Extension add(Extension pExtension) {
      mExtensions.add(pExtension);
      mExtensionMap.put(pExtension.getPageid(),pExtension);
      return pExtension;
    }

    /**
     *  add a new Extension from the given triple
     */
    public Extension add(TripleQuery query,Triple pExtensionTriple) {
      Extension lExtension=new Extension(query,pExtensionTriple);
      add(lExtension);
      return lExtension;
    }

    // reinitialize my mExtension map
    public void reinit() {
      mExtensionMap.clear();
      for (Extension lExtension:mExtensions) {
        mExtensionMap.put(lExtension.getPageid(),lExtension);
      }
    }

    // convert this manager to json format 
    public String toJson() { return JSON.toJSONString(this); }
    
    // get a new manager from the given json string
    public static ExtensionManager fromJson(String json) {
      ExtensionManager result=JSON.parseObject(json, ExtensionManager.class);
      result.reinit();
      return result;
    }

    // default constructor for Extension Manager
    public ExtensionManager() {}

    // add Extensions from the given query
    public void addExtensions(TripleQuery pExtensionQuery,TripleQuery query) {
      if (pExtensionQuery!=null) {
        for (Triple lExtensionTriple:pExtensionQuery.getTriples()) {
          add(query,lExtensionTriple);
        }
      }
    }

    // construct me from the given triple Query query
    public ExtensionManager(TripleQuery query) {
      // first query the SiDIF bases triplestore
      TripleQuery lExtensionQuery=query.query(null,"isA","Extension");
      addExtensions(lExtensionQuery,query);
      // then the SMW triplestore
      lExtensionQuery=query.query(null,"Property:IsA","Extension");
      addExtensions(lExtensionQuery,query);
      init(query);
    } // constructor for Extension Manager
    
    // >>>{user defined topicmanager code}{Extension}{Extension}
    // <<<{user defined topicmanager code}{Extension}{Extension}
  } // class Extension Manager

}
Showing below 0 pages.

Retrieved from "https://wiki.bitplan.com/index.php?title=Concept:Extension/Java&oldid=13303#smw-result"