Class ProjectFileUtil
- java.lang.Object
- 
- java.nio.file.spi.FileTypeDetector
- 
- com.inductiveautomation.ignition.common.project.ProjectFileUtil
 
 
- 
 public class ProjectFileUtil extends java.nio.file.spi.FileTypeDetectorA utility class for inspecting, identifying and loading Projects from Files or streams.Provides utilities for both legacy XML exported projects, as well as 8.0 disk-based project zip exports. Also registers with the ServiceLoader to act as a FileTypeDetector. See the docs on probeContentType(java.nio.file.Path)
- 
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringXML_FILE_TYPEstatic java.lang.StringZIP_FILE_TYPE
 - 
Constructor SummaryConstructors Constructor Description ProjectFileUtil()
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidexportToZip(ProjectManifest manifest, java.util.List<ProjectResource> resources, java.io.OutputStream destination)static ProjectImportfromInputStream(java.io.InputStream s, java.lang.String projectNameOverwrite)static java.util.Optional<ProjectImport>fromProjectFile(java.io.File projectFile)static java.util.Optional<ProjectImport>fromProjectFile(java.io.File projectFile, java.lang.String projectNameOverride)static ProjectImportimportFromXml(java.io.File projectFile, java.lang.String newProjectName)Creates a RuntimeProject from a legacy (Ignition 7.9 and older) xml-based project exportstatic ProjectImportimportFromXml(java.io.InputStream is, java.lang.String newProjectName)static ProjectImportimportFromZip(java.io.File projectFile, java.lang.String projectNameOverwrite)static ProjectImportimportFromZip(java.io.InputStream zipStream, java.lang.String projectName)static booleanisSingleton(ProjectResource r)static booleanisXmlProjectFile(java.io.File file)Detect if a file appears to be an xml based project exportstatic booleanisZipProjectFile(java.io.File file)Detect if a file appears to be a zip based (8.0+) project export filejava.lang.StringprobeContentType(java.nio.file.Path path)This class is registered with the ServiceLoader to provide itself as a FileTypeDetector, which makes it possible to use Files.probeContentType(someFilePath) and then compare the result to see if it matches the staticXML_FILE_TYPEorZIP_FILE_TYPE, the latter being the format for project exports in 8.0 and higher.static ProjectResourcesanitizeSingletons(ProjectResource r)
 
- 
- 
- 
Field Detail- 
XML_FILE_TYPEpublic static final java.lang.String XML_FILE_TYPE - See Also:
- Constant Field Values
 
 - 
ZIP_FILE_TYPEpublic static final java.lang.String ZIP_FILE_TYPE - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
exportToZippublic static void exportToZip(ProjectManifest manifest, java.util.List<ProjectResource> resources, java.io.OutputStream destination) throws java.io.IOException - Throws:
- java.io.IOException
 
 - 
probeContentType@Nullable public java.lang.String probeContentType(@Nonnull java.nio.file.Path path) throws java.io.IOExceptionThis class is registered with the ServiceLoader to provide itself as a FileTypeDetector, which makes it possible to use Files.probeContentType(someFilePath) and then compare the result to see if it matches the staticXML_FILE_TYPEorZIP_FILE_TYPE, the latter being the format for project exports in 8.0 and higher.- Specified by:
- probeContentTypein class- java.nio.file.spi.FileTypeDetector
- Parameters:
- path- path to a file possibly being an Ignition project export in either zip or .proj xml format.
- Returns:
- the discovered file type, or null if no match was found
- Throws:
- java.io.IOException- on failure to read the path as a buffered input stream
 
 - 
isXmlProjectFilepublic static boolean isXmlProjectFile(java.io.File file) throws java.io.IOExceptionDetect if a file appears to be an xml based project export- Parameters:
- file- a file to detect
- Returns:
- true if the file is an xml based project export
- Throws:
- java.io.IOException- on failure to read file
 
 - 
isZipProjectFilepublic static boolean isZipProjectFile(java.io.File file) throws java.io.IOExceptionDetect if a file appears to be a zip based (8.0+) project export file- Parameters:
- file- to detect
- Returns:
- true if the file is believed to be a zip based export
- Throws:
- java.io.IOException- on failure to read file
 
 - 
importFromXmlpublic static ProjectImport importFromXml(@Nonnull java.io.File projectFile, java.lang.String newProjectName) throws java.io.IOException, org.xml.sax.SAXException, ProjectInvalidException Creates a RuntimeProject from a legacy (Ignition 7.9 and older) xml-based project export- Parameters:
- projectFile- file to import from
- newProjectName- if non-null or empty string, will create the new project with the given name, building the resources with the appropriate project/resource paths.
- Throws:
- java.io.IOException
- org.xml.sax.SAXException
- ProjectInvalidException
 
 - 
importFromXmlpublic static ProjectImport importFromXml(@Nonnull java.io.InputStream is, java.lang.String newProjectName) throws java.io.IOException, org.xml.sax.SAXException - Throws:
- java.io.IOException
- org.xml.sax.SAXException
 
 - 
isSingletonpublic static boolean isSingleton(ProjectResource r) 
 - 
sanitizeSingletonspublic static ProjectResource sanitizeSingletons(ProjectResource r) 
 - 
fromProjectFilepublic static java.util.Optional<ProjectImport> fromProjectFile(java.io.File projectFile) throws java.io.IOException, org.xml.sax.SAXException, ProjectInvalidException - Throws:
- java.io.IOException
- org.xml.sax.SAXException
- ProjectInvalidException
 
 - 
fromProjectFilepublic static java.util.Optional<ProjectImport> fromProjectFile(java.io.File projectFile, java.lang.String projectNameOverride) throws java.io.IOException, org.xml.sax.SAXException, ProjectInvalidException - Parameters:
- projectFile- the exported project file
- projectNameOverride- if the resources in the incoming project should be loaded with a different project name than exists in the file, pass the desired name in as this arg
- Returns:
- optional containing a runtime project on success, or empty if parsing or creation of the project failed.
- Throws:
- java.io.IOException- on failure to read the file
- org.xml.sax.SAXException- on failure to read/parse xml
- ProjectInvalidException
 
 - 
importFromZippublic static ProjectImport importFromZip(@Nonnull java.io.File projectFile, java.lang.String projectNameOverwrite) throws ProjectInvalidException, java.io.IOException - Throws:
- ProjectInvalidException
- java.io.IOException
 
 - 
fromInputStreampublic static ProjectImport fromInputStream(java.io.InputStream s, java.lang.String projectNameOverwrite) throws java.io.IOException, ProjectInvalidException, org.xml.sax.SAXException - Throws:
- java.io.IOException
- ProjectInvalidException
- org.xml.sax.SAXException
 
 - 
importFromZippublic static ProjectImport importFromZip(@Nonnull java.io.InputStream zipStream, java.lang.String projectName) throws ProjectInvalidException, java.io.IOException - Throws:
- ProjectInvalidException
- java.io.IOException
 
 
- 
 
-