Class JSFile

    • Constructor Summary

      Constructors 
      Constructor Description
      JSFile​(java.io.File root, java.io.File file)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String escapeZoneName​(java.lang.String name)  
      protected AssemblyFile find​(java.util.ArrayList<java.io.File> includePath, java.lang.String fileName, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Find a javascript file somewhere on the include path.
      protected void findAll​(java.util.ArrayList<java.io.File> includePath, java.util.ArrayList<IlibLocale> locales, java.lang.String baseName, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Find all json files for a given basename across all locales.
      protected void findAllForLocale​(java.util.ArrayList<java.io.File> includePath, java.lang.String baseName, IlibLocale locale, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Find all json files for a particular locale with the given baseName.
      protected void findZones​(java.util.ArrayList<java.io.File> includePath, java.util.ArrayList<IlibLocale> locales, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Load in the zoneinfo files that are relevant to all the given locales.
      protected JSONFile locate​(java.util.ArrayList<java.io.File> includePath, java.lang.String baseName, java.lang.String fileName, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Locate a json file somewhere on the include path.
      protected java.lang.String pathDiff()  
      void process​(java.util.ArrayList<java.io.File> includePath, java.util.ArrayList<IlibLocale> locales, java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
      Process the file to find all the dependencies on other files and on data.
      void writeDependencies​(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales)
      Write out the files that this file is dependent upon to the out writer, and recorded that the files have already been visited in the visited array.
      void writeParents​(java.io.Writer out, java.util.ArrayList<java.lang.String> visited, java.util.ArrayList<IlibLocale> locales)
      Write the dependencies for the farthest ancestors above the current node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logger

        protected org.apache.log4j.Logger logger
      • dependsPatterns

        protected java.util.ArrayList<java.util.regex.Pattern> dependsPatterns
      • dataPatterns

        protected java.util.ArrayList<java.util.regex.Pattern> dataPatterns
      • macroPatterns

        protected java.util.ArrayList<java.util.regex.Pattern> macroPatterns
      • zonetab

        protected org.json.JSONObject zonetab
      • deletePatterns

        protected java.util.ArrayList<java.util.regex.Pattern> deletePatterns
    • Constructor Detail

      • JSFile

        public JSFile​(java.io.File root,
                      java.io.File file)
    • Method Detail

      • find

        protected AssemblyFile find​(java.util.ArrayList<java.io.File> includePath,
                                    java.lang.String fileName,
                                    java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
                             throws java.lang.Exception
        Find a javascript file somewhere on the include path.
        Parameters:
        includePath - list of directories to search
        fileName - relative path to the javascript file
        allFiles - cache of all files already processed
        Returns:
        a JSFile instance
        Throws:
        java.lang.Exception - if the file cannot be found
      • locate

        protected JSONFile locate​(java.util.ArrayList<java.io.File> includePath,
                                  java.lang.String baseName,
                                  java.lang.String fileName,
                                  java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
        Locate a json file somewhere on the include path.
        Parameters:
        includePath - list of directories to search
        baseName - the base name of the json file without the locale spec attached
        fileName - relative path to the javascript file
        allFiles - cache of all files already processed
      • findAllForLocale

        protected void findAllForLocale​(java.util.ArrayList<java.io.File> includePath,
                                        java.lang.String baseName,
                                        IlibLocale locale,
                                        java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
                                 throws java.lang.Exception
        Find all json files for a particular locale with the given baseName.
        Parameters:
        includePath -
        baseName -
        locale -
        allFiles -
        Throws:
        java.lang.Exception
      • findAll

        protected void findAll​(java.util.ArrayList<java.io.File> includePath,
                               java.util.ArrayList<IlibLocale> locales,
                               java.lang.String baseName,
                               java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
                        throws java.lang.Exception
        Find all json files for a given basename across all locales. This method always finds the generic shared json, even if the locale list is empty, so that there is always a default if a particular ilib function does not have locale data or if the copy of ilib is used with dynamic loading instead of preassembled data.
        Parameters:
        includePath -
        locales -
        baseName -
        allFiles -
        Throws:
        java.lang.Exception
      • escapeZoneName

        protected java.lang.String escapeZoneName​(java.lang.String name)
      • findZones

        protected void findZones​(java.util.ArrayList<java.io.File> includePath,
                                 java.util.ArrayList<IlibLocale> locales,
                                 java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
                          throws java.lang.Exception
        Load in the zoneinfo files that are relevant to all the given locales. Basically, this looks up each locale's country in the zonetab.json file, and adds all time zones it finds there.
        Parameters:
        includePath -
        locales -
        allFiles -
        Throws:
        java.lang.Exception - if something went wrong or if the zonetab.json file could not be found
      • process

        public void process​(java.util.ArrayList<java.io.File> includePath,
                            java.util.ArrayList<IlibLocale> locales,
                            java.util.HashMap<java.lang.String,​AssemblyFile> allFiles)
                     throws java.lang.Exception
        Description copied from class: AssemblyFile
        Process the file to find all the dependencies on other files and on data. This method reads the file contents and searches for comments of the form "// @depends" or "/* @depends *\/". The contents of the comment with that form is a list of files that the current file depends upon. The includePath is a list of directories in which to search for the depended files. The path of a file that is depended upon should be listed as relative to one of the directories in the include path. This method adds all the files found to the allFile hash, mapping the file name to the assembly file instance. In the case where the file already exists in the allFiles hash because some other assembly file already depended upon it, then the dependency is stored, but the mapping is not added again to allFiles.
        Specified by:
        process in class AssemblyFile
        Parameters:
        includePath - a path to search for depended upon files
        allFiles - a hash where all the depended upon files are stored
        Throws:
        java.lang.Exception
      • writeParents

        public void writeParents​(java.io.Writer out,
                                 java.util.ArrayList<java.lang.String> visited,
                                 java.util.ArrayList<IlibLocale> locales)
                          throws java.lang.Exception
        Description copied from class: AssemblyFile
        Write the dependencies for the farthest ancestors above the current node. To get all the dependencies right, we start with any arbitrary node in the graph. From there, we traverse the parent links until we find a source node. That is, a node with no parents. From there, we do a depth-first search of the dependencies of that source until we get to a sink node. (A node with no dependencies.) Then, we write out that sink node and recurse back up. Each level writes out all its dependencies first, then itself and then returns to the previous level. We keep track of all the nodes we have already done so that if a subsequent depth first search hits a node that was already done, we can avoid doing that subtree more than once. Once all the dependencies of the source have been satisfied, we recurse back again to find other sources. Once all the parents for a node have been done, we attempt to do the dependencies for the current node if there are any left. This method is the one that traces the ancestry to the source node and then calls the writeDependencies call to actually write out the entire dependency tree from there.
        Specified by:
        writeParents in class AssemblyFile
        Parameters:
        out - a writer to write the files to
        visited - an array of paths to nodes that have already been visited
        locales - set of locales to generate data for
        Throws:
        CircularDependencyException - if there are any circular dependencies in the code
        java.lang.Exception
      • pathDiff

        protected java.lang.String pathDiff()
      • writeDependencies

        public void writeDependencies​(java.io.Writer out,
                                      java.util.ArrayList<java.lang.String> visited,
                                      java.util.ArrayList<IlibLocale> locales)
                               throws java.lang.Exception
        Description copied from class: AssemblyFile
        Write out the files that this file is dependent upon to the out writer, and recorded that the files have already been visited in the visited array.
        Specified by:
        writeDependencies in class AssemblyFile
        locales - set of locales to generate data for
        Throws:
        java.lang.Exception