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).
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.
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.
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:
getClipboardFormats() — returns available format codes as strings
(UTI strings on Mac, decimal integers on Windows).getBestFileMakerClipboardFormat() — returns the first registered FM
format that is currently on the clipboard.getClipboardData(format, isFileMaker) — reads raw bytes; on Windows,
strips the 4-byte big-endian length prefix that FileMaker prepends.setClipboardData(format, data, isFileMaker, clearExisting) — writes
bytes; on Windows, prepends the 4-byte little-endian length prefix and also writes
an empty format-2 entry (required by FileMaker on Windows or paste silently fails
or crashes).getClipboardType(xmlData) — identifies type by XML root element,
same as ClipboardType.forXml.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.
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.
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.
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.
TransformerHandler. Writes
directly to an OutputStream — never accumulates the document in memory. Preferred
for all new code.
OutputStream, an array of
FMPXMLExport2.FieldElement descriptors, and an expected row count.setErrorCode(Integer) before writing any rows to
override the default 401 error code that is used when no rows are added.addRow(Object[]) once per record. Array length must match the
FieldElement array. Repeating fields (maxRepeat > 1) may receive an
Object[] or Collection which is expanded into multiple
<DATA> elements.close() exactly once when done; it flushes, writes closing tags,
and closes the stream. A mismatch between foundCount and actual rows
logged as a WARNING.<RESULTSET>) are written lazily
on the first addRow or close call, so
setErrorCode must be called before either.FieldElement (nested static class) describes one column: name, FM type constant
(TEXT, NUMBER, DATE, TIME,
TIMESTAMP), emptyOk, and maxRepeat.
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:
get(args) — HTTP GET with URL query string; returns
List<Record>.post(data) — HTTP POST with URL-encoded body.insert, update, delete, save
— higher-level write operations. save routes to insert/update/delete
based on Record state.
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.
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.
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.
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.
BaseTableInfo. Created by
TableAndFieldParser.parse.
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.
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.
Converts between FileMaker numeric date/time representations and Java types. FileMaker's epoch is January 1, year 1 (Gregorian proleptic), not January 1, 1970:
GetAsNumber(timestamp) returns this. Constant:
FM_TIMESTAMP_EPOCH = 62135596800L seconds.GetAsNumber(Date(1,1,1970)) = 719163.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.
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.
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.
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.
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>").
"<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.
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).
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.
FMRestClient, the -lay parameter refers to a table
occurrence name. When reading schema via TableAndFieldParser, you get both;
use BaseTableInfo for field lists and identity, and
TableOccurrenceInfo for relationship graph names.
FMClipboard handles this automatically, but callers working with raw bytes
must be aware of it.
FMClipboard.setClipboardData does this automatically when
clearExisting=true.
FMDateUtils for conversions — do not hard-code epoch
arithmetic.
PortalSaveHelper inside FMRestClient. Callers should not assume
a single insert or update call maps to a single HTTP request.
dataType.startsWith("global")
in FieldInfo. Global fields are shared across all records and sessions; writing
them via the FM API sets them for the whole database, not just the current record.
FMPXMLExport and FMPXMLExport2 emit 401
in the XML <ERRORCODE> element when no rows are present.
FMRestClient treats 401 as an empty result, not an error.
ClipboardType.forCode() tests
mac12Format twice and never tests mac11Format. Pre-FM-12 Mac
codes will not match. Use forXml() instead when the XML is available.