static int xps_find_doc_props_path(xps_context *ctx, char path[1024]) { xml_element *root; int code = xps_open_and_parse(ctx, "/_rels/.rels", &root); if (code != fz_okay) return code; *path = '\0'; if (!strcmp(xml_tag(root), "Relationships")) { xml_element *item; for (item = xml_down(root); item; item = xml_next(item)) { if (!strcmp(xml_tag(item), "Relationship") && xml_att(item, "Type") && !strcmp(xml_att(item, "Type"), REL_CORE_PROPERTIES) && xml_att(item, "Target")) { xps_absolute_path(path, "", xml_att(item, "Target"), 1024); } } } else code = fz_error_make(ctx->ctx, "couldn't parse part '/_rels/.rels'"); xml_free_element(ctx->ctx, root); return code; }
static int xps_find_doc_props_path(xps_context *ctx, char path[1024]) { xml_element *root; int code = xps_open_and_parse(ctx, "/[Content_Types].xml", &root); if (code != fz_okay) return code; *path = '\0'; if (root && !strcmp(xml_tag(root), "Types")) { xml_element *item; for (item = xml_down(root); item; item = xml_next(item)) { if (!strcmp(xml_tag(item), "Override") && xml_att(item, "ContentType") && !strcmp(xml_att(item, "ContentType"), CONTENT_TYPE_CORE_PROPS) && xml_att(item, "PartName")) { fz_strlcpy(path, xml_att(item, "PartName"), 1024); } } } else code = fz_throw("couldn't parse part '[Content_Types].xml'"); xml_free_element(root); return code; }
static int xps_read_and_process_dest_names(xps_named_dest **destsp, xps_context *ctx, xps_document *doc) { char base_uri[1024]; xml_element *root; int code = xps_open_and_parse(ctx, doc->name, &root); if (code != fz_okay) return code; fz_strlcpy(base_uri, doc->name, sizeof(base_uri)); *(xps_get_part_base_name(base_uri) - 1) = '\0'; xps_parse_names_imp(destsp, ctx, doc, root, base_uri, 0); xml_free_element(root); return fz_okay; }
static int xps_parse_outline_structure(xps_outline **outlinep, xps_context *ctx, char *name) { char base_uri[1024]; xml_element *root; int code = xps_open_and_parse(ctx, name, &root); if (code != fz_okay) return code; fz_strlcpy(base_uri, name, sizeof(base_uri)); *(xps_get_part_base_name(base_uri) - 1) = '\0'; xps_parse_outline_imp(outlinep, root, base_uri); xml_free_element(root); return fz_okay; }
static int xps_read_and_process_document_outline(xps_outline **outlinep, xps_context *ctx, xps_document *doc) { char base_uri[1024]; xml_element *root; xml_element *item; int code = fz_okay; xps_rels_for_part(base_uri, doc->name, sizeof(base_uri)); code = xps_open_and_parse(ctx, base_uri, &root); if (code != fz_okay) return code; *strstr(base_uri, "/_rels/") = '\0'; for (item = root; item; item = xml_next(item)) { xml_element *relItem; if (strcmp(xml_tag(item), "Relationships") != 0) continue; for (relItem = xml_down(item); relItem; relItem = xml_next(relItem)) { char *target, *type; if (!strcmp(xml_tag(relItem), "Relationship") && (target = xml_att(relItem, "Target")) && (type = xml_att(relItem, "Type")) && !strcmp(type, REL_DOC_STRUCTURE)) { char tgtbuf[1024]; xps_absolute_path(tgtbuf, base_uri, target, sizeof(tgtbuf)); code = xps_parse_outline_structure(outlinep, ctx, tgtbuf); } } } xml_free_element(root); return code; }