java.lang.Object
org.nasdanika.html.model.app.gen.Util

public final class Util extends Object
  • Field Details

  • Method Details

    • generateSite

      public static void generateSite(Label root, org.nasdanika.html.model.bootstrap.Page pageTemplate, org.nasdanika.exec.resources.Container container, ActionContentProvider.Factory actionContentProviderFactory, PageContentProvider.Factory pageContentProviderFactory, org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor)
      Generates application site from an Action model root.
      Parameters:
      root - Root action to generate header and footer. Can be null.
      pageTemplate - Page template.
      context - Context used for uri resolution - interpolation of action locations and names. can be null.
      container - Receiver of generated resources.
      progressMonitor - Progress monitor.
    • generateSite

      public static void generateSite(Label root, Label principal, Label activeAction, List<Label> actionPath, org.nasdanika.html.model.bootstrap.Page pageTemplate, org.nasdanika.exec.resources.Container container, ActionContentProvider.Factory contentProviderFactory, PageContentProvider.Factory pageProviderFactory, org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor)
      Generates application site from an Action model using a random base URI and a caching URI resolver created from the argument context with base-uri injected.
      Parameters:
      root - Root action to generate header and footer. Can be null.
      principal - Principal action to generate navigation bar and navigation panel. Can be null.
      activeAction - Active action to generate the content panel if instance of action.
      actionPath - Action path to show in breadcrumbs.
      pageTemplate - Page template.
      context - Context used for uri resolution - interpolation of action locations and names. can be null.
      container - Receiver of generated resources.
      progressMonitor - Progress monitor.
    • generateSite

      public static void generateSite(Label root, Label principal, Label activeAction, List<Label> actionPath, org.nasdanika.html.model.bootstrap.Page pageTemplate, BiFunction<Label,URI,URI> uriResolver, URI baseURI, org.nasdanika.exec.resources.Container container, ActionContentProvider actionContentProvider, PageContentProvider pageContentProvider, org.nasdanika.common.ProgressMonitor progressMonitor)
      Generates application site from an Action model
      Parameters:
      root - Root action to generate header and footer. Can be null.
      principal - Principal action to generate navigation bar and navigation panel. Can be null.
      activeAction - Active action to generate the content panel.
      pageTemplate - Page template.
      uriResolver - Resolves Action to URI.
      baseURI - Base URI for resolution, specifically to create relative URI's.
      container - Receiver of generated resources.
      progressMonitor - Progress monitor.
    • createLabel

      public static Label createLabel(Label source, Label activeAction, BiFunction<Label,URI,URI> uriResolver, Function<Label,String> idProvider, String appearancePath, boolean recursive, boolean inNavPanel, boolean decorate)
      Creates a Link from Action with a relative location for locations.
      Parameters:
      source -
      uri -
      active -
      appearancePath -
      Returns:
    • createSearchDocument

      public static org.json.JSONObject createSearchDocument(String path, File file, Consumer<Exception> errorConsumer) throws IOException
      Throws:
      IOException
    • createSearchDocument

      public static org.json.JSONObject createSearchDocument(String path, File file, Consumer<? super org.jsoup.nodes.Element> contentConsumer, BiFunction<String,org.jsoup.nodes.Document,Boolean> processor, Consumer<Exception> errorConsumer) throws IOException
      For Nasdanika App pages extracts page title, breadcrumbs and content text into a JSONObject to add to a collector and then to use for constructing search indices.
      Parameters:
      path -
      file -
      contentConsumer - Consumer of content elements which can be used to analyze page contents, e.g. find dead links. Can be null.
      processor - If not null the document is passed to the processor. If the processor returns true that means that the document was manipulated by the processor and shall be saved to the source file.
      Returns:
      Search document object for non-empty Nasdanika App pages, null otherwise.
      Throws:
      IOException
    • loadDrawioDocument

      public static org.nasdanika.drawio.Document loadDrawioDocument(org.jsoup.nodes.Element mxGraphDiv) throws ParserConfigurationException, SAXException, IOException
      Loads mxGraphModel from mxgraph div.
      Parameters:
      mxGraphDiv -
      Returns:
      Throws:
      IOException
      SAXException
      ParserConfigurationException
    • traverseDrawio

      public static void traverseDrawio(org.jsoup.nodes.Element mxGraphDiv, Consumer<org.nasdanika.drawio.Element> visitor, org.nasdanika.drawio.ConnectionBase connectionBase) throws ParserConfigurationException, SAXException, IOException
      Throws:
      ParserConfigurationException
      SAXException
      IOException
    • filterDrawio

      public static String filterDrawio(String spec, Consumer<org.nasdanika.drawio.Element> visitor, org.nasdanika.drawio.ConnectionBase connectionBase, Boolean compress) throws ParserConfigurationException, SAXException, IOException, TransformerException
      Loads document, traverses all elements and then saves and returns the document.
      Parameters:
      spec -
      visitor -
      connectionBase -
      compress -
      Returns:
      Throws:
      IOException
      SAXException
      ParserConfigurationException
      TransformerException
    • createInspector

      public static Consumer<? super org.jsoup.nodes.Element> createInspector(Predicate<String> linkPredicate, Consumer<String> errorConsumer)
      Creates an inspector consumer which finds and reports broken links, missing images and elements with nsd-error class.
      Parameters:
      file -
      path -
      siteDir -
      errorConsumer -
      Returns:
    • createRelativeLinkPredicate

      public static Predicate<String> createRelativeLinkPredicate(File file, File dir)
      Creates a predicate checking for links relative to the argument file in the argument directory.
      Parameters:
      file - Base file
      dir - Directory within which check for relative links
      Returns:
    • configureSearch

      public static boolean configureSearch(String path, org.jsoup.nodes.Document doc, String searchDocumentsPath, Supplier<InputStream> searchScriptSupplier)
      Inserts search json and search script tags into the document.
      Parameters:
      path -
      doc -
      Returns:
    • configureSearch

      public static boolean configureSearch(String path, org.jsoup.nodes.Document doc, String searchDocumentsPath)
      Inserts search json and search script tags into the document. Uses search.js resource for the search script.
      Parameters:
      path -
      doc -
      Returns:
    • generateSitemapAndSearch

      public static org.json.JSONObject generateSitemapAndSearch(File dir, String domain, BiPredicate<File,String> siteMapPredicate, com.redfin.sitemapgenerator.ChangeFreq changeFrequency, BiPredicate<File,String> searchPredicate, BiConsumer<String,String> errorConsumer, BiFunction<String,org.jsoup.nodes.Document,Boolean> searchConfigurator) throws IOException
      Generates sitemap and search index for lunrjs by scanning files in a directory.
      Parameters:
      dir - Directory to scan
      base - URI prefix for file paths with or without dangling /
      Throws:
      IOException
    • generateSitemapAndSearch

      public static org.json.JSONObject generateSitemapAndSearch(File dir, String domain, BiPredicate<File,String> siteMapPredicate, com.redfin.sitemapgenerator.ChangeFreq changeFrequency, BiPredicate<File,String> searchPredicate, BiConsumer<String,String> errorConsumer, String searchDocumentsPath, Supplier<InputStream> searchScriptSupplier) throws IOException
      Throws:
      IOException
    • generateSitemapAndSearch

      public static org.json.JSONObject generateSitemapAndSearch(File dir, String domain, BiPredicate<File,String> siteMapPredicate, com.redfin.sitemapgenerator.ChangeFreq changeFrequency, BiPredicate<File,String> searchPredicate, BiConsumer<String,String> errorConsumer, String searchDocumentsPath) throws IOException
      Generates sitemap and search using search.js resource.
      Parameters:
      dir -
      domain -
      siteMapPredicate -
      changeFrequency -
      searchPredicate -
      errorConsumer -
      searchDocumentsPath -
      Throws:
      IOException
    • generateSitemapAndSearch

      public static void generateSitemapAndSearch(File dir, String domain, BiPredicate<File,String> siteMapPredicate, com.redfin.sitemapgenerator.ChangeFreq changeFrequency, BiPredicate<File,String> searchPredicate, BiConsumer<String,String> errorConsumer) throws IOException
      Throws:
      IOException
    • createResourceSet

      public static ResourceSet createResourceSet(org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor)
      Creates NcoreResourceSet with XMIResourceFactoryImpl, ObjectLoaderResourceFactory handling yml, json extensions and data scheme. NcoreDrawioResourceFactory for drawio extension. Uses GitMarkerFactory for EObjectLoader. Registers AppAdapterFactory. Registers Ncore, Exec, and HTML packages.
      Parameters:
      progressMonitor -
      Returns:
    • generateContainer

      public static void generateContainer(URI resourceModelURI, org.nasdanika.resources.BinaryEntityContainer container, org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor) throws DiagnosticException
      Generates files (binary entities) from a resource model .
      Throws:
      DiagnosticException
      Exception
    • generateContainer

      public static void generateContainer(Resource containerResource, org.nasdanika.resources.BinaryEntityContainer container, org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor) throws DiagnosticException
      Generates files (binary entities) from a resource model .
      Throws:
      DiagnosticException
      Exception
    • generateContainer

      public static void generateContainer(EObject eObj, org.nasdanika.resources.BinaryEntityContainer container, org.nasdanika.common.Context context, org.nasdanika.common.ProgressMonitor progressMonitor) throws DiagnosticException
      Generates files (binary entities) from a resource model .
      Throws:
      DiagnosticException
      Exception
    • loadSemanticMap

      public static Map<org.nasdanika.ncore.ModelElement,Label> loadSemanticMap(URI uri, BiFunction<String,String,org.nasdanika.ncore.ModelElement> factory) throws IOException
      Loads a semantic map (EObject -> Label) from JSON or YAML resource. The resource is considered to by YAML if its URI ends with .yml or .yaml case insensitive.
      Parameters:
      uri - Semantic map URI. Link locations in the map are resolved relative to this URI.
      factory - Factory for creating key EObjects if map entries have type key. Keys must implement ModelElement so URI's can be injected into them.
      Returns:
      Throws:
      IOException
    • loadSemanticMap

      public static Map<org.nasdanika.ncore.ModelElement,Label> loadSemanticMap(URI uri, ResourceSet resourceSet) throws IOException
      Loads a semantic map (EObject -> Label) from JSON or YAML resource. The resource is considered to by YAML if its URI ends with .yml or .yaml case insensitive.
      Parameters:
      uri - Semantic map URI. Link locations in the map are resolved relative to this URI.
      resouceSet - Resource set to use the package registry to create semantic elements.
      Returns:
      Throws:
      IOException
    • processHTML

      public static void processHTML(Util.HTMLProcessor processor, File... files)