示例#1
0
static void
gsf_output_get_property (GObject     *object,
			 guint        property_id,
			 GValue      *value,
			 GParamSpec  *pspec)
{
	GsfOutput *output = GSF_OUTPUT (object);

	/* gsf_off_t is typedef'd to gint64 */

	switch (property_id) {
	case PROP_NAME:
		g_value_set_string (value, gsf_output_name (output));
		break;
	case PROP_SIZE:
		g_value_set_int64 (value, gsf_output_size (output));
		break;
	case PROP_CLOSED:
		g_value_set_boolean (value, gsf_output_is_closed (output));
		break;
	case PROP_POS:
		g_value_set_int64 (value, gsf_output_tell (output));
		break;
	case PROP_MODTIME:
		g_value_set_boxed (value, gsf_output_get_modtime (output));
		break;
	case PROP_CONTAINER:
		g_value_set_object (value, output->container);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
示例#2
0
/* write the metadata (dirents, small block, xbats) and close the sink */
static gboolean
gsf_outfile_msole_close_root (GsfOutfileMSOle *ole)
{
	GsfOutfile *tmp;
	guint8  buf [OLE_HEADER_SIZE];
	guint32	sbat_start, num_sbat, sb_data_start, sb_data_size, sb_data_blocks;
	guint32	bat_start, num_bat, dirent_start, num_dirent_blocks, next, child_index;
	unsigned i, j, blocks, num_xbat, xbat_pos;
	gsf_off_t data_size;
	unsigned metabat_size = ole->bb.size / BAT_INDEX_SIZE - 1;
	GPtrArray *elem = ole->root->content.dir.root_order;

	/* write small block data */
	blocks = 0;
	sb_data_start = ole_cur_block (ole);
	data_size = gsf_output_tell (ole->sink);
	for (i = 0 ; i < elem->len ; i++) {
		GsfOutfileMSOle *child = g_ptr_array_index (elem, i);
		if (child->type == MSOLE_SMALL_BLOCK) {
			gsf_off_t size = gsf_output_size (GSF_OUTPUT (child));
			if (size > 0) {
				child->blocks = ((size - 1) >> ole->sb.shift) + 1;
				gsf_output_write (ole->sink,
						  child->blocks << ole->sb.shift,
						  child->content.small_block.buf);
				child->first_block = blocks;
				blocks += child->blocks;
			} else {
示例#3
0
static void
gsf_output_get_property (GObject     *object,
			 guint        property_id,
			 GValue      *value,
			 GParamSpec  *pspec)
{
	/* gsf_off_t is typedef'd to gint64 */
	switch (property_id) {
	case PROP_NAME:
		g_value_set_string (value, gsf_output_name (GSF_OUTPUT (object)));
		break;
	case PROP_SIZE:
		g_value_set_int64 (value, gsf_output_size (GSF_OUTPUT (object)));
		break;
	case PROP_POS:
		g_value_set_int64 (value, gsf_output_tell (GSF_OUTPUT (object)));
		break;
	case PROP_CLOSED:
		g_value_set_boolean (value, gsf_output_is_closed (GSF_OUTPUT (object)));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}
示例#4
0
static GsfInput *
make_local_copy (GFile *file, GInputStream *stream)
{
    GsfOutput *out;
    GsfInput  *copy;
    GFileInfo *info;

    out = gsf_output_memory_new ();

    while (1) {
        guint8 buf[4096];
        gssize nread;

        nread = g_input_stream_read (stream, buf, sizeof(buf), NULL, NULL);

        if (nread > 0) {
            if (!gsf_output_write (out, nread, buf)) {
                copy = NULL;
                goto cleanup_and_exit;
            }
        }
        else if (nread == 0)
            break;
        else {
            copy = NULL;
            goto cleanup_and_exit;
        }
    }

    copy = gsf_input_memory_new_clone
           (gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
            gsf_output_size (out));

    if (copy != NULL) {
        info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, NULL);
        if (info) {
            gsf_input_set_name (GSF_INPUT (copy), g_file_info_get_name (info));
            g_object_unref (info);
        }
    }

cleanup_and_exit:

    gsf_output_close (out);
    g_object_unref (out);

    g_input_stream_close (stream, NULL, NULL);
    g_object_unref (stream);

    set_name_from_file (copy, file);

    return copy;
}
示例#5
0
static GsfInput *
make_local_copy (FILE *stream, const char *filename, GError **err)
{
	GsfOutput *out;
	GsfInput *copy = NULL;

	out = gsf_output_memory_new ();

	while (1) {
		guint8 buf[4096];
		gssize nread;

		nread = fread (buf, 1, sizeof(buf), stream);

		if (nread > 0) {
			if (!gsf_output_write (out, nread, buf))
				goto error;
		} else if (nread == 0)
			break;
		else
			goto error;
	}

	copy = gsf_input_memory_new_clone
		(gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (out)),
		 gsf_output_size (out));

	gsf_output_close (out);
	g_object_unref (out);

	if (filename)
		gsf_input_set_name_from_filename (GSF_INPUT (copy), filename);

	return copy;

error:
	if (err) {
		char *utf8name = filename
			? g_filename_display_name (filename)
			: g_strdup ("?");
		g_set_error (err, gsf_input_error_id (), 0,
			     "%s: not a regular file",
			     utf8name);
		g_free (utf8name);
	}

	gsf_output_close (out);
	g_object_unref (out);

	return NULL;
}
UT_Error AbiCollabSessionManager::serializeDocument(const PD_Document* pDoc, std::string& document, bool encodeBase64)
{
	UT_return_val_if_fail(pDoc, false);

	// Don't put this auto-save in the most recent list.
	XAP_App::getApp()->getPrefs()->setIgnoreNextRecent();
	
	// maskExport();
	GsfOutputMemory* sink = GSF_OUTPUT_MEMORY(gsf_output_memory_new());
	GsfOutput* gzSink = gsf_output_gzip_new(GSF_OUTPUT(sink), NULL);
	bool bAuthor = pDoc->isExportAuthorAtts();
	const_cast<PD_Document *>(pDoc)->setExportAuthorAtts(true);
	UT_Error result = const_cast<PD_Document*>(pDoc)->saveAs(GSF_OUTPUT(gzSink), IE_Exp::fileTypeForSuffix(".abw"), true);
	const_cast<PD_Document *>(pDoc)->setExportAuthorAtts(bAuthor);
	gsf_output_close(GSF_OUTPUT(gzSink));
	// unmaskExport();
	
	if (result == UT_OK)
	{
		guint32 size = gsf_output_size (GSF_OUTPUT(sink));
		const guint8* zabwBuf = gsf_output_memory_get_bytes (sink);
		
		if (encodeBase64)
		{
			// this would be more efficient if we had a GsfOutputBase64.. ah well, this will do for now
			guint8* base64zabwBuf = gsf_base64_encode_simple(zabwBuf, size);
			document += (char*)base64zabwBuf;
			g_free(base64zabwBuf);
		}
		else
		{
			// just copy raw zipped data into string
			document.resize( size );
			memcpy( &document[0], zabwBuf, size );
		}
	} 
	else
    {
		UT_DEBUGMSG(("Failed to export! Handle this gracefully!\n"));
    }

	g_object_unref(G_OBJECT(gzSink));
	g_object_unref(G_OBJECT(sink));
	return result;
}
bool ODe_Style_MasterPage::write(GsfOutput* pODT) const {
    
    UT_UTF8String output;
    
    UT_UTF8String_sprintf(output,
        "  <style:master-page style:name=\"%s\" style:page-layout-name=\"%s\">\n",
        m_name.utf8_str(), m_pageLayoutName.utf8_str());
        
    ODe_writeUTF8String(pODT, output);
    
    /*
    We have to deal with two confusion things when writing out header/footers:
    
    1. Oddly enough AbiWord uses "header-even" and "footer-even" for page 1, 3, 5, etc :)
    
    2. In OpenDocument you can specify an alternative header/footer for "left" pages.
       Oddly enough OpenOffice.org seems to interpret "left" pages as page 2, 4, 6, etc.
    */

    if (!m_abiHeaderId.empty()) {
        // It has a header
        ODe_writeUTF8String(pODT, "   <style:header>\n");

        // Swap even/uneven when there is an alternative header for uneven pages to
        // match what OpenOffice expects
        if (m_abiHeaderEvenId.empty()) {
            ODe_gsf_output_write(pODT, gsf_output_size (m_pHeaderContentTemp), 
                   gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pHeaderContentTemp)));
        } else {
            ODe_gsf_output_write(pODT, gsf_output_size (m_pHeaderEvenContentTemp), 
                   gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pHeaderEvenContentTemp)));
        }
        
        ODe_writeUTF8String(pODT, "   </style:header>\n");
    }

    if (!m_abiHeaderEvenId.empty()) {
        // It has a different header for uneven pages
        ODe_writeUTF8String(pODT, "   <style:header-left>\n");

        ODe_gsf_output_write(pODT, gsf_output_size (m_pHeaderContentTemp), 
                gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pHeaderContentTemp)));
        
        ODe_writeUTF8String(pODT, "   </style:header-left>\n");
    }

    if (!m_abiFooterId.empty()) {
        // It has a footer
        ODe_writeUTF8String(pODT, "   <style:footer>\n");

        // Swap even/uneven when there is an alternative footer for uneven pages to
        // match what OpenOffice expects
        if (m_abiFooterEvenId.empty()) {
            ODe_gsf_output_write(pODT, gsf_output_size (m_pFooterContentTemp), 
                   gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pFooterContentTemp)));
        } else {
            ODe_gsf_output_write(pODT, gsf_output_size (m_pFooterEvenContentTemp), 
                   gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pFooterEvenContentTemp)));
        }

        ODe_writeUTF8String(pODT, "   </style:footer>\n");
    }

    if (!m_abiFooterEvenId.empty()) {
        // It has a footer for uneven pages
        ODe_writeUTF8String(pODT, "   <style:footer-left>\n");

        ODe_gsf_output_write(pODT, gsf_output_size (m_pFooterContentTemp), 
                gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pFooterContentTemp)));

        ODe_writeUTF8String(pODT, "   </style:footer-left>\n");
    }

    ODe_writeUTF8String(pODT, "  </style:master-page>\n");

    return true;
}
bool ODe_DocumentData::writeContentXML(GsfOutfile* pOdt) {
    GsfOutput* pContentStream;
    
    pContentStream = gsf_outfile_new_child (pOdt, "content.xml", FALSE);
    
    const char * const preamble [] = {
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n",
    "\n",
    "<office:document-content"
    " xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\""
    " xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\""
    " xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\""
    " xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\""
    " xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\""
    " xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\""
    " xmlns:xlink=\"http://www.w3.org/1999/xlink\""
    " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
    " xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\""
    " xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\""
    " xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\""
    " xmlns:chart=\"urn:oasis:names:tc:opendocument:xmlns:chart:1.0\""
    " xmlns:dr3d=\"urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0\""
    " xmlns:math=\"http://www.w3.org/1998/Math/MathML\""
    " xmlns:form=\"urn:oasis:names:tc:opendocument:xmlns:form:1.0\""
    " xmlns:script=\"urn:oasis:names:tc:opendocument:xmlns:script:1.0\""
    " xmlns:ooo=\"http://openoffice.org/2004/office\""
    " xmlns:ooow=\"http://openoffice.org/2004/writer\""
    " xmlns:oooc=\"http://openoffice.org/2004/calc\""
    " xmlns:dom=\"http://www.w3.org/2001/xml-events\""
    " xmlns:xforms=\"http://www.w3.org/2002/xforms\""
    " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
    " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
    " xmlns:delta=\"http://www.deltaxml.com/ns/track-changes/delta-namespace\""
    " xmlns:ac=\"http://www.deltaxml.com/ns/track-changes/attribute-change-namespace\""
    " xmlns:split=\"http://www.deltaxml.com/ns/track-changes/split-namespace\""
    " office:version=\"1.1\">\n"};
    
    ODe_writeToStream(pContentStream, preamble, G_N_ELEMENTS(preamble));
    
    m_contentXMLFontDecls.write( pContentStream );
    
    m_contentAutoStyles.write( pContentStream );

    m_contentRevisions.write( pContentStream, m_pAbiDoc );
    
    ODe_writeUTF8String(pContentStream, " <office:body>\n"
                                        "  <office:text>\n");
    // FIXME: here OR the one above?
//    m_contentRevisions.write( pContentStream, m_pAbiDoc );
       
    ODe_gsf_output_write(pContentStream, gsf_output_size (m_pOfficeTextTemp),
			 gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (m_pOfficeTextTemp)));
    
    ODe_gsf_output_close (m_pOfficeTextTemp);
    m_pOfficeTextTemp = NULL;
    
    ODe_writeUTF8String(pContentStream,
        "  </office:text>\n"
        " </office:body>\n"
        "</office:document-content>");
        
    ODe_gsf_output_close(pContentStream);
    
    return true;
}
示例#9
0
文件: excel.c 项目: ranguba/chupatext
static gboolean
feed(ChupaDecomposer *decomposer, ChupaFeeder *feeder,
     ChupaData *data, GError **error)
{
    GOFileSaver *saver;
    GOFileOpener *opener = NULL;
    GOIOContext *io_context;
    WorkbookView *view = NULL;
    Workbook *workbook;
    GODoc *document;
    GsfInput *source;
    GsfOutput *output;
    GInputStream *input;
    ChupaData *next_data;
    const gchar *filename;
    GPrintFunc old_print_error_func;
    ChupaMetadata *metadata;

    filename = chupa_data_get_filename(data);

    source = chupa_data_input_new(data);
    io_context = go_io_context_new(command_context);
    old_print_error_func = g_set_printerr_handler(printerr_to_log_delegator);
    view = wb_view_new_from_input(source, filename, opener, io_context, NULL);
    g_object_unref(source);
    g_set_printerr_handler(old_print_error_func);
    if (go_io_error_occurred(io_context)) {
        go_io_error_display(io_context);
    }
    if (!view) {
        g_set_error(error,
                    CHUPA_DECOMPOSER_ERROR,
                    CHUPA_DECOMPOSER_ERROR_FEED,
                    "[decomposer][excel][feed][error][%s]"
                    ": failed to create workbook",
                    filename);
        g_object_unref(io_context);
        return FALSE;
    }
    workbook = wb_view_get_workbook(view);
    document = wb_view_get_doc(view);

    saver = find_file_saver(filename, view, workbook, document, error);
    if (!saver) {
        g_object_unref(workbook);
        g_object_unref(io_context);
        return FALSE;
    }

    output = gsf_output_memory_new();
    if (!output) {
        g_set_error(error,
                    CHUPA_DECOMPOSER_ERROR,
                    CHUPA_DECOMPOSER_ERROR_FEED,
                    "[decomposer][excel][feed][%s][error]"
                    ": failed to create output",
                    filename);
        g_object_unref(workbook);
        g_object_unref(io_context);
        return FALSE;
    }

    wbv_save_to_output(view, saver, output, io_context);
    if (go_io_error_occurred(io_context)) {
        go_io_error_display(io_context);
        g_object_unref(workbook);
        g_object_unref(io_context);
        g_object_unref(output);
        return FALSE;
    }

    metadata = chupa_metadata_new();
    chupa_metadata_merge_original_metadata(metadata,
                                           chupa_data_get_metadata(data));
    collect_metadata(metadata, document);
    g_object_unref(workbook);
    g_object_unref(io_context);

    input = chupa_memory_input_stream_new(GSF_OUTPUT_MEMORY(output));
    g_object_unref(output);

    chupa_metadata_set_content_length(metadata, gsf_output_size(output));
    next_data = chupa_data_new(input, metadata);
    g_object_unref(metadata);
    g_object_unref(input);
    chupa_feeder_accepted(feeder, next_data);
    chupa_data_finished(next_data, NULL);
    g_object_unref(next_data);

    return TRUE;
}
示例#10
0
/**
 * stf_text_to_columns:
 * @wbc: The control making the request
 * @cc:
 *
 * Main routine, handles importing a file including all dialog mumbo-jumbo
 **/
void
stf_text_to_columns (WorkbookControl *wbc, GOCmdContext *cc)
{
	DialogStfResult_t *dialogresult = NULL;
	SheetView	*sv;
	Sheet		*src_sheet, *target_sheet;
	GnmRange const	*src;
	GnmRange	 target;
	GsfOutput	*buf;
	guint8 const	*data;
	size_t data_len;

	sv    = wb_control_cur_sheet_view (wbc);
	src_sheet = sv_sheet (sv);
	src = selection_first_range (sv, cc, _("Text to Columns"));
	if (src == NULL)
		return;
	if (range_width	(src) > 1) {
		go_cmd_context_error (cc, g_error_new (go_error_invalid (), 0,
			_("Only one column of input data can be parsed at a time")));
		return;
	}

	/* FIXME : how to do this cleanly ? */
	if (!GNM_IS_WBC_GTK (wbc))
		return;

#warning Add UI for this
	target_sheet = src_sheet;
	target = *src;
	range_translate (&target, target_sheet, 1, 0);

	buf = gsf_output_memory_new ();
	sheet_foreach_cell_in_range (src_sheet,
		CELL_ITER_ALL,
		src->start.col, src->start.row,
		src->end.col, src->end.row,
		(CellIterFunc) &cb_get_content, buf);

	gsf_output_close (buf);
	data = gsf_output_memory_get_bytes (GSF_OUTPUT_MEMORY (buf));
	data_len = (size_t)gsf_output_size (buf);
	if (data_len == 0) {
		go_cmd_context_error_import (GO_CMD_CONTEXT (cc),
					     _("There is no data "
					       "to convert"));
	} else {
		dialogresult = stf_dialog (WBC_GTK (wbc),
					   NULL, FALSE, NULL, FALSE,
					   _("Text to Columns"),
					   data, data_len);
	}
	if (dialogresult != NULL) {
		GnmCellRegion *cr = stf_parse_region (dialogresult->parseoptions,
			dialogresult->text, NULL, target_sheet->workbook);
		if (cr != NULL) {
			stf_dialog_result_attach_formats_to_cr (dialogresult, cr);
			target.end.col = target.start.col + cr->cols - 1;
			target.end.row = target.start.row + cr->rows - 1;
		}
		if (cr == NULL ||
		    cmd_text_to_columns (wbc, src, src_sheet,
					 &target, target_sheet, cr))
			go_cmd_context_error_import (GO_CMD_CONTEXT (cc),
					     _("Error while trying to "
					       "parse data into sheet"));
		stf_dialog_result_free (dialogresult);
	}

	g_object_unref (buf);
}