Search in sources :

Example 1 with StorageLocation

use of org.opendatakit.briefcase.ui.StorageLocation in project briefcase by opendatakit.

the class BaseFormParserForJavaRosa method redirectOutput.

private static void redirectOutput() {
    File jrLogFile = new File(new StorageLocation().getBriefcaseFolder(), ".briefcase-javarosa.log");
    log.info("Redirecting javarosa output to {}", jrLogFile);
    try {
        PrintStream jrOut = new PrintStream(jrLogFile);
        Std.setOut(jrOut);
        Std.setErr(jrOut);
    } catch (FileNotFoundException e) {
        log.warn("Failed to redirect javarosa output");
    }
}
Also used : PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) StorageLocation(org.opendatakit.briefcase.ui.StorageLocation) File(java.io.File)

Example 2 with StorageLocation

use of org.opendatakit.briefcase.ui.StorageLocation in project briefcase by opendatakit.

the class XmlManipulationUtils method parseXml.

public static Document parseXml(File submission) throws ParsingException, FileSystemException {
    // parse the xml document...
    Document doc = null;
    try {
        InputStream is = null;
        InputStreamReader isr = null;
        try {
            is = new FileInputStream(submission);
            isr = new InputStreamReader(is, UTF_8);
            Document tempDoc = new Document();
            KXmlParser parser = new KXmlParser();
            parser.setInput(isr);
            parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
            tempDoc.parse(parser);
            isr.close();
            doc = tempDoc;
        } finally {
            if (isr != null) {
                try {
                    isr.close();
                } catch (Exception e) {
                // no-op
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (Exception e) {
                // no-op
                }
            }
        }
    } catch (XmlPullParserException e) {
        try {
            return BadXMLFixer.fixBadXML(submission);
        } catch (CannotFixXMLException e1) {
            File debugFileLocation = new File(new StorageLocation().getBriefcaseFolder(), "debug");
            try {
                if (!debugFileLocation.exists()) {
                    FileUtils.forceMkdir(debugFileLocation);
                }
                long checksum = FileUtils.checksumCRC32(submission);
                File debugFile = new File(debugFileLocation, "submission-" + checksum + ".xml");
                FileUtils.copyFile(submission, debugFile);
            } catch (IOException e2) {
                throw new RuntimeException(e2);
            }
            throw new ParsingException("Failed during parsing of submission Xml: " + e.toString());
        }
    } catch (IOException e) {
        throw new FileSystemException("Failed while reading submission xml: " + e.toString());
    }
    return doc;
}
Also used : CannotFixXMLException(org.opendatakit.briefcase.model.CannotFixXMLException) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.kxml2.kdom.Document) FileInputStream(java.io.FileInputStream) FileSystemException(org.opendatakit.briefcase.model.FileSystemException) CannotFixXMLException(org.opendatakit.briefcase.model.CannotFixXMLException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MetadataUpdateException(org.opendatakit.briefcase.model.MetadataUpdateException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ParsingException(org.opendatakit.briefcase.model.ParsingException) KXmlParser(org.kxml2.io.KXmlParser) FileSystemException(org.opendatakit.briefcase.model.FileSystemException) ParsingException(org.opendatakit.briefcase.model.ParsingException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) StorageLocation(org.opendatakit.briefcase.ui.StorageLocation) MediaFile(org.opendatakit.briefcase.util.ServerFetcher.MediaFile) File(java.io.File)

Example 3 with StorageLocation

use of org.opendatakit.briefcase.ui.StorageLocation in project briefcase by opendatakit.

the class FileSystemUtils method getTempFormDefinitionFile.

public static File getTempFormDefinitionFile() throws FileSystemException {
    File briefcase = new StorageLocation().getBriefcaseFolder();
    File tempDefnFile;
    try {
        tempDefnFile = File.createTempFile("tempDefn", ".xml", briefcase);
    } catch (IOException e) {
        log.error("failed to create temp file for form def", e);
        return null;
    }
    return tempDefnFile;
}
Also used : IOException(java.io.IOException) StorageLocation(org.opendatakit.briefcase.ui.StorageLocation) File(java.io.File)

Example 4 with StorageLocation

use of org.opendatakit.briefcase.ui.StorageLocation in project briefcase by opendatakit.

the class Common method bootCache.

static void bootCache(String storageDir) {
    BriefcasePreferences.setBriefcaseDirectoryProperty(storageDir);
    File f = new StorageLocation().getBriefcaseFolder();
    LOGGER.info("Trying to use {} as storage directory", f);
    if (!f.exists()) {
        if (!f.mkdirs()) {
            LOGGER.error("Unable to create directory");
            System.exit(1);
        }
    } else if (f.exists() && !f.isDirectory()) {
        LOGGER.error("Not a directory");
        System.exit(1);
    }
    if (BriefcasePreferences.appScoped().getBriefcaseDirectoryOrNull() != null) {
        FileSystemUtils.createFormCacheInBriefcaseFolder();
    }
}
Also used : StorageLocation(org.opendatakit.briefcase.ui.StorageLocation) File(java.io.File)

Aggregations

File (java.io.File)4 StorageLocation (org.opendatakit.briefcase.ui.StorageLocation)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintStream (java.io.PrintStream)1 MalformedURLException (java.net.MalformedURLException)1 KXmlParser (org.kxml2.io.KXmlParser)1 Document (org.kxml2.kdom.Document)1 CannotFixXMLException (org.opendatakit.briefcase.model.CannotFixXMLException)1 FileSystemException (org.opendatakit.briefcase.model.FileSystemException)1 MetadataUpdateException (org.opendatakit.briefcase.model.MetadataUpdateException)1 ParsingException (org.opendatakit.briefcase.model.ParsingException)1 MediaFile (org.opendatakit.briefcase.util.ServerFetcher.MediaFile)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1