ProscFM — FileMaker Integration Library

The com.prosc.fm package provides FileMaker-specific utilities and integrations used throughout MirrorSync. It covers five areas: (1) system-clipboard access for FileMaker schema objects, (2) FMPXMLRESULT format parsing and generation, (3) the FileMaker XML REST API client, (4) schema metadata types, and (5) general FileMaker utilities (dates, files, directories, error codes, text comparison, and Let-statement serialization).


Clipboard Access

FileMaker places schema objects (tables, fields, layouts, scripts, script steps, custom functions) on the system clipboard in proprietary binary formats. Java's standard clipboard API cannot access these formats. The two classes below use a native JNI library (clipfunctions) to bridge this gap.

{@link com.prosc.fm.ClipboardType}
Enum of the six FileMaker schema-object clipboard types plus a plainText fallback. Each constant carries three platform-specific format codes: macOS FM 12+ (dyn.ah62d4r…), macOS FM <12 (dyn.agk8…), and Windows (Mac-* strings despite the name). Call getFormatCode(majorVersion, isMac) to get the right code for the current runtime. Call forXml(xml) to identify a type by inspecting the XML root element — it uses an early-exit SAX parse and returns plainText on malformed XML. Known bug: forCode() tests mac12Format twice instead of testing mac11Format, so pre-FM-12 Mac codes will not match.
{@link com.prosc.fm.FMClipboard}
Low-level clipboard I/O. On first construction, extracts the native clipfunctions library from the JAR to a temp file and loads it via System.load (one-time, guarded by a static lock). An instance is bound to a FileMaker major version, which determines the layout clipboard format code (changed in FM 12). Key methods: Relationship to ClipboardType: FMClipboard is the raw byte-level I/O layer; ClipboardType is the enum that names the types and maps them to format codes. Both duplicate the XML-inspection logic for identifying types. Prefer ClipboardType.forXml for new callers.
{@link com.prosc.fm.InvalidClipboardException}
Thrown when clipboard XML is well-formed but does not contain a recognized FileMaker root element. Returned from forXml / getClipboardType. Note: malformed XML does not throw this; instead plainText is returned.

There is also a package-private StopParsing SAX exception used as a control-flow device to abort parsing early once the clipboard type is identified. This is the standard pattern for early-exit with SAX.


FMPXMLRESULT Format

FileMaker's FMPXMLRESULT XML format is used both to import records into FileMaker and as the response format from the FileMaker Web Publishing Engine (FMPXMLRESULT endpoint). There are two generators.

{@link com.prosc.fm.FMPXMLExport} (deprecated)
Builds the full FMPXMLRESULT document in a StringBuffer from a List<Map>. Simple but requires the entire result set to be in memory. Use only for small result sets or legacy code. Replace with FMPXMLExport2.
{@link com.prosc.fm.FMPXMLExport2}
Streaming FMPXMLRESULT generator using a SAX TransformerHandler. Writes directly to an OutputStream — never accumulates the document in memory. Preferred for all new code. FieldElement (nested static class) describes one column: name, FM type constant (TEXT, NUMBER, DATE, TIME, TIMESTAMP), emptyOk, and maxRepeat.

FileMaker XML REST API Client

{@link com.prosc.fm.FMRestClient}

HTTP client for FileMaker's legacy XML API (/fmi/xml/fmresultset.xml). Treats a FileMaker layout as a document-oriented store: fetch records (with portal rows), modify them in-memory, and save back. Not to be confused with the modern FileMaker Data API (REST JSON); this targets the older XML endpoint available in all FileMaker Server versions.

When to use vs. JDBC: Use FMRestClient when you need portal row read/write, when the JDBC driver is unavailable, or when targeting a remote FileMaker Server over HTTP. Use JDBC (with the FileMaker JDBC driver) when you need SQL query semantics or batch processing of base-table rows without portals.

Key operations:

Portal rows are stored in Record.data as List<Record> values keyed by portal/relationship name. FileMaker only allows one portal-row insertion and one portal-row deletion per HTTP request, so the client queues additional insert/delete operations (via PortalSaveHelper and QueuedRequest) and issues multiple requests as needed. Callers do not need to manage this directly.

The FieldFilter interface controls which fields are written on insert/update. Use it to skip auto-entered, calculated, global, or read-only fields (omitting them prevents FM error 507 and avoids overwriting system-managed values).

FieldDefinition (nested) is the parsed metadata for one field from FM's <metadata> element — result type, storage type, auto-enter, global, repetitions. Updated on every request. Keyed by fully-qualified name ("Portal::Field" or plain "Field").

Number fields are parsed as BigDecimal (if fractional) or BigInteger (if integer). Date, time, and timestamp fields are returned as String by default; subclass and override dateFor, timeFor, and timestampFor to parse them into richer types.


Schema Metadata Types

These classes model the FileMaker schema as read by TableAndFieldParser. FileMaker distinguishes base tables (physical storage) from table occurrences (named aliases in the relationship graph). A base table can have many occurrences; an occurrence belongs to exactly one base table.

{@link com.prosc.fm.DatabaseInfo}
Top-level schema snapshot for one FileMaker file. Holds a list of BaseTableInfo and a list of TableOccurrenceInfo. Use baseTableWithName(name) to look up a base table by name (throws IllegalArgumentException if missing), and firstTableOccurrenceInfoFor(baseTable) to find a valid occurrence for a base table. Instances are populated by TableAndFieldParser and then treated as read-only snapshots.
{@link com.prosc.fm.BaseTableInfo}
Describes one base table within a FileMaker file. Holds the base table name, filename (used as the equality key together with name), a list of all occurrence names that expose it, a list of FieldInfo objects, and an isExternal flag for tables from external files. Equality and ordering are by (baseTableName, filename). Fields are only populated for the first occurrence encountered during parsing; subsequent occurrences share the same BaseTableInfo instance.
{@link com.prosc.fm.TableOccurrenceInfo}
Represents one table occurrence in the relationship graph. Holds the occurrence name, FileMaker internal ID, modification count (useful for detecting schema changes between sync runs), and a reference back to the shared BaseTableInfo. Created by TableAndFieldParser.parse.
{@link com.prosc.fm.FieldInfo}
Plain data holder for one field on a base table. All members are public. Key fields: name, dataType (e.g. "decimal", "varchar", "global varchar", "timestamp"), fieldType ("Normal", "Calculation", "Summary"), id, repetitions, modCount. Use isGlobal() (checks dataType.startsWith("global")) rather than inspecting dataType directly.
{@link com.prosc.fm.TableAndFieldParser}
Parses the comma-delimited table-occurrence and field metadata that MirrorSync retrieves from a FileMaker database (via FileMaker script steps or DDR) into a DatabaseInfo object. Input is newline/CR-delimited rows; each row is comma-separated with columns in a fixed order documented in the class Javadoc. The includeExternalBaseTables flag controls whether tables from external FileMaker files are included in the result. This is the primary entry point for schema discovery in non-JDBC code paths.

Utilities

{@link com.prosc.fm.FMDateUtils}

Converts between FileMaker numeric date/time representations and Java types. FileMaker's epoch is January 1, year 1 (Gregorian proleptic), not January 1, 1970:

All time-zone-aware conversions use a two-pass DST algorithm: a first rough pass establishes the approximate date, which determines the correct DST offset for the second pass. This is intentional and required for correctness near DST transitions.

fmTimestampMillisecondsToMilliseconds handles values from FileMaker's Get(CurrentTimeUTCMilliseconds), which uses the FM millisecond epoch (not the timestamp-second epoch). The conversion is simply fmMilliseconds - FM_MILLISECONDS_EPOCH.

sqlTimeToFMTime uses TimeZone.getOffset(0) (not getRawOffset()) by design — java.sql.Time is defined as milliseconds since Jan 1, 1970 00:00:00 GMT, so the epoch offset is the correct one to apply. This matters for British Summer Time, which was in effect on Jan 1, 1970.

{@link com.prosc.fm.FMFileUtils}
Converts between Java File objects and FileMaker's proprietary path format. FileMaker uses platform-specific prefixes: filemac: (Mac, with volume name replacing /Volumes), filewin:/ (Windows, with forward slashes and a leading slash before the drive letter), and filelinux: (Linux). Directory paths always end with a trailing /. getBootVolumeName() is cached after first call — on Mac it runs ls -l /Volumes and parses the symlink to root; on Windows returns "C:" (hard-coded; does not detect alternate boot drives). isFileMakerDatabase(name) recognizes .fmp7 (FM 7–11) and .fmp12 (FM 12+) extensions, case-insensitively.
{@link com.prosc.fm.FMDirectoryUtils}
Locates the FileMaker Server installation directory on the local machine. Search order: FMS_HOME env var; Mac default /Library/FileMaker Server/ then ~fmserver; Linux /opt/FileMaker/FileMaker Server; Windows via PowerShell registry enumeration under HKLM\SOFTWARE\FileMaker\FileMaker Server\<version>\Services\InstallLocation then %PROGRAMFILES% then %PROGRAMFILES(X86)%. A candidate is accepted only if the FMS daemon binary (fmserverd on Mac/Linux, fmserver.exe on Windows) exists inside it. Maintenance note: Hard-coded paths require updates for each new major FMS version. getFMSVersion() is not yet implemented.
{@link com.prosc.fm.ErrorCodes}
Resolves FileMaker numeric error codes to human-readable messages by reading ErrorCodes.properties (co-located with the class, entries keyed as error.<n>). Note: the properties file is re-read on every call — no caching. Code 0 means no error. getCodeAndMessage(n) returns "n: message" for use in log messages and exception text.
{@link com.prosc.fm.FMException}
Checked exception carrying a FileMaker error code. getHttpCode() maps FM codes to HTTP status codes: 201→403, 100–199→400, 200–299→401, 300–305→409, 306→412, 401→404, others→400. Also provides a static helper getErrorCode(ProcessExecutionException) that parses the FM error code out of a CLI tool's output (pattern: "Error: <code>").
{@link com.prosc.fm.FMVersionInfo}
Parses a FileMaker version string of the form "<ClientType> v<major>.<minor>" (e.g. "Pro v12.3" or "Server v18.0"). Use isClient() to distinguish FileMaker Pro from FileMaker Server. getMajorVersion() and getMinorVersion() return strings. Throws NoSuchElementException on malformed input.
{@link com.prosc.fm.FileMakerTextComparator}
Comparator<String> that matches FileMaker's sort order: strips leading non-alphanumeric characters from both values before comparing case-insensitively. Null sorts before non-null. Locale-sensitive collation is not yet applied (noted as a future fix in the source).
{@link com.prosc.fm.LetStatementFormat}
Serializes a Java object into a FileMaker Let() expression suitable for passing to FileMaker's Evaluate() function. This is preferred over JSON in FileMaker contexts because FM can evaluate Let() natively without a custom parsing function. Supports primitives, strings, dates/times/timestamps (wrapped in FileMaker Date(), Time(), Timestamp() calls), Maps, Iterables (top-level produces one Let() per element; nested uses one-based repeat notation $key[n]), and plain objects (reflected via non-transient, non-static fields). Null → empty string literal. Complex values recurse via dot-notation prefixing.

FileMaker-Specific Quirks Callers Must Know