How can I get xTextFields from .odt document properly?
I tried something like that, but it doesn't work (Any returns a nullptr address):
Reference <XTextFieldsSupplier> xTextFieldsSupplier (xTextDoc, UNO_QUERY);
if (!xTextFieldsSupplier.is())
return { };
Reference<XNameAccess> xTextFieldsInfo = xTextFieldsSupplier->getTextFieldMasters();
if (!xTextFieldsInfo.is())
return { };
Sequence<OUString> xTextFieldsNames = xTextFieldsInfo->getElementNames();
Any any;
for (::rtl::OUString* field = xTextFieldsNames.begin();
field != xTextFieldsNames.end();
field++) {
std::stringstream field_string;
field_string << *field;
QString fieldName = QString::fromStdString(field_string.str());
any = xTextFieldsInfo->getByName(*field);
Reference< XTextField > xField(any, UNO_QUERY);
// other code to work with xField
}
UPD:
I got a solution that helped me here:
Libreoffice API (UNO): need to change user's xTextField text
XTextFieldsSupplier has two methods, and it looks like you chose the wrong one. The method to get text fields is getTextFields().
Example code:
Reference< XEnumerationAccess > xFieldsEnumAccess = xTextFieldsSupplier->getTextFields();
Reference< XEnumeration > xFieldsEnum = xFieldsEnumAccess->createEnumeration();
Reference< XTextRange > xTextRange;
while ( xFieldsEnum->hasMoreElements() )
{
Any aNextElement = xFieldsEnum->nextElement();
Reference< XTextField > xField(aNextElement, UNO_QUERY);
OUString presentation = xField->getPresentation(true);
xTextRange = xText->getEnd();
xTextRange->setString(presentation + OUString::createFromAscii("\n"));
}
If you want to deal with text field masters instead, then your code is mostly correct.
Any aFieldMaster;
aFieldMaster = xNamedFieldMasters->getByName(*field);
EDIT:
Here is where xText comes from.
Reference < XTextDocument > xTextDocument (xComponent,UNO_QUERY);
Reference< XText > xText = xTextDocument->getText();
EDIT 2:
Here is an example of changing a text field. Start with a new Writer document and go to Insert -> Field -> More Fields. Under the Functions tab, double-click Input Field. Enter "hello" in the text box area and press OK.
Then, run the following code.
Reference< XServiceInfo > xInfo (xField, UNO_QUERY);
OUString sContent;
if (xInfo->supportsService("com.sun.star.text.TextField.Input"))
{
Reference< XPropertySet > xProps (xField, UNO_QUERY);
Any aContent = xProps->getPropertyValue(OUString::createFromAscii("Content"));
aContent >>= sContent;
sContent += OUString::createFromAscii(" there");
aContent <<= sContent;
xProps->setPropertyValue(OUString::createFromAscii("Content"), aContent);
Reference< XRefreshable > xRefreshable (xFieldsEnumAccess, UNO_QUERY);
xRefreshable->refresh();
}
Now, the field contains "hello there".
For more information, please review Andrew's Macro Document section 5.18 User Fields.
Related
Is there any proper way to change text in the user's created xTextField using C++ UNO?
These fields names are com.sun.star.text.fieldmaster.User.[FIELD NAME]
I tried this before, but it didn't help:
Libreoffice API (UNO) : text and data from xTextField
Also I've tried something like this but still didn't help:
// current_field - xTextField I got before
Reference<XText> xText = Reference<XText>(current_field, UNO_QUERY);
if (!xText.is())
{
qDebug() << "XText FROM xTextField IS NULL!";
return;
}
OUStringBuffer bufText;
bufText.append( new_value.utf16() );
std::stringstream textStr;
textStr << bufText.toString();
xText->setString( bufText.toString() );
Any suggestions?
Did you read section 5.18 of Andrew's Macro Document as recommended in my other answer? Here is Listing 5.49 translated into C++. It seems there is a bug in that listing because I had to add "." to make it work.
OUString sName = OUString::createFromAscii("Author Name");
OUString sServ = OUString::createFromAscii("com.sun.star.text.FieldMaster.User");
OUString sFieldName = sServ + OUString::createFromAscii(".") + sName;
Reference< XMultiServiceFactory > xDocFactory (xTextDocument, UNO_QUERY);
if (xNamedFieldMasters->hasByName(sFieldName))
{
fieldMaster = xNamedFieldMasters->getByName(sFieldName);
Reference< XPropertySet> xProps (fieldMaster, UNO_QUERY);
Any aContent;
aContent <<= OUString::createFromAscii("Andrew Pitonyak");
xProps->setPropertyValue(OUString::createFromAscii("Content"), aContent);
}
else
{
fieldMaster <<= xDocFactory->createInstance(sServ);
Reference< XPropertySet> xProps (fieldMaster, UNO_QUERY);
Any aName;
aName <<= sName;
xProps->setPropertyValue(OUString::createFromAscii("Name"), aName);
Any aContent;
aContent <<= OUString::createFromAscii("Andrew Pitonyak");
xProps->setPropertyValue(OUString::createFromAscii("Content"), aContent);
}
If this code is run on a blank document, the newly created field can be seen by going to Insert -> Fields -> More Fields, Variables, User Field.
I am new to Solr and SolrJ. I am trying to use for a desktop application and I have files(text files) to index and search. I wanted to use highlight feature and display the fragments with highlight,but I don't get them to display in yellow background as you highlight a text, please let me know how to display the text in yellow background.
here is my code snippet:
public void TestHighLight(SolrQuery query) throws
SolrServerException, IOException {
query.setQuery("*");
query.set("hl", "true");
query.set("hl.snippets", "5");
query.set("q", "text:Pune");
query.set("hl.fl", "*");
QueryResponse queryResponse = client.query(query);
SolrDocumentList docs = queryResponse.getResults();
Iterator iter = docs.iterator();
for (int i = 0; i < docs.size(); i++) {
iter = docs.get(i).getFieldNames().iterator();
String fldVal = (String) docs.get(i).getFieldValue("id");
String docID = (String) docs.get(i).get("id");
while (iter.hasNext()) {
String highlighText = getHighlightedText(queryResponse,
"text", docID);
System.out.println(" tHighlightedText is " + highlighText );
}
}
}
The output looks like this:how do I color it ?
[ for Java Developer at Pune
Thanks a lot !
Set the pre and post parameters of the highlighter. Specifies the “tag” to use before a highlighted term. This can be any string, but is most often an HTML or XML tag.
e.g:
solrQueryHandler.setHighlightSimplePre("<font color="yellow">");
solrQueryHandler.setHighlightSimplePost("/font");
But note that this will work only for the Original Highlighter
To be able to use different templates in a TYPO3 CMS 7.6.18 setup. I include a pageTSConfig.ts file with a backend layout looking like this. (see also this pastebin: https://pastebin.com/BcYKrYKh and this how it looks like in the TYPO3 object browser: https://pastebin.com/LVXqNUZC
### Backend Layouts #####
mod.web_layout.BackendLayouts{
1 {
title = Standaard Layout
config {
backend_layout {
colCount = 2
rowCount = 1
rows {
1 {
columns {
1 {
name = linker_inhoud
colPos = 1
}
2 {
name = midden_inhoud
colPos = 0
}
}
}
}
}
}
}
}
Since the BE-Layout is done with a file, in my TSconfig.ts I have added pagets__0 to it like the manual mentioned. Still this is not working. What Am I missing here? This is a part of the TSconfig I have in place here is the complete config:
page.10.file.stdWrap.cObject = CASE
page.10.file.stdWrap.cObject {
key.data = levelfield:-1, backend_layout_next_level, pagelayout, slide
key.override.field = pagelayout
default = TEXT
default.value = fileadmin/templates/index.html
pagets__0 = TEXT
pagets__0.value = fileadmin/templates/index.html
pagets__1 = TEXT
pagets__1.value = fileadmin/templates/layouts/small_header_page.html
pagets__2 = TEXT
pagets__2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
All to be included with:
There is a difference between "backend_layout", which is a the name of a real database field that can be fetched by "levelfield" and "pagelayout", which is a kind of virtual field to get rid of the "levelfield" approach.
https://docs.typo3.org/typo3cms/TyposcriptReference/DataTypes/Gettext/Index.html#pagelayout
key.data = pagelayout
should do the whole job for you and only in this case you can use stuff like
pagets__x
to access the actual layout.
So your code should either be:
page.10 = FLUIDTEMPLATE
page.10.file.cObject = CASE
page.10.file.cObject {
key.data = pagelayout
default = TEXT
default.value = fileadmin/templates/index.html
pagets__0 = TEXT
pagets__0.value = fileadmin/templates/index.html
pagets__1 = TEXT
pagets__1.value = fileadmin/templates/layouts/small_header_page.html
pagets__2 = TEXT
pagets__2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
or it should be
page.10 = FLUIDTEMPLATE
page.10.file.cObject = CASE
page.10.file.cObject {
key.data = levelfield:-1, backend_layout_next_level, slide
key.override.field = backend_layout
default = TEXT
default.value = fileadmin/templates/index.html
1 = TEXT
1.value = fileadmin/templates/layouts/small_header_page.html
2 = TEXT
2.value = fileadmin/templates/layouts/alternatieve_pagina.html
}
But not a mix of both approaches.
Before I tell you what might be wrong with your code, let me explain you a few things.
You have placed your templates in the fileadmin directory. This is not the place where to put these files any longer, because the fileadmin is a public place for resources like images, videos or documents. It might be available for every backend user in the filelist and the editor should not be able to edit the template in any case. The suggested way to handle your templates is to put them into an own extension that can be installed via the extension manager.
In your pastebin snippets, there is a line with userFunc = tx_templavoila_pi1->main_page, you may mixing up stuff in your installation and don't want to use FLUIDTEMPLATE alongside templavoila, because it could be confusing what rendering method is used for what stuff on your page. Better stick to templavoila or Fluid for the entirety of the TYPO3 installation.
Now, you have these lines in your TypoScript:
key.data = levelfield:-1, backend_layout_next_level, pagelayout, slide
key.override.field = pagelayout
There is no field pagelayout in the pages records. The field you rather want to address is backend_layout.
I'm implementing a custom field in Sitecore for the Content Editor, and I need to be able to open the Rich Text editor and get the data from there. I'm not really sure where to look though, nor how to go about it.
Had to decompile the Sitecore.Kernel DLL in order to figure this out.
First thing is to spin off a call from the Context.ClientPage object
So, for my situation:
switch (message.Name)
{
case "richtext:edit":
Sitecore.Context.ClientPage.Start(this, "EditText");
break;
}
You will then need to have a method in your class with the same name as defined in the above Start method. Then, you either start the rich text control if the request isn't a postback, or handle the posted data
protected void EditText(ClientPipelineArgs args)
{
Assert.ArgumentNotNull(args, "args");
if (args.IsPostBack)
{
if (args.Result == null || args.Result == "undefined")
return;
var text = args.Result;
if (text == "__#!$No value$!#__")
text = string.Empty;
Value = text;
UpdateHtml(args); //Function that executes Javascript to update embedded rich text frame
}
else
{
var richTextEditorUrl = new RichTextEditorUrl
{
Conversion = RichTextEditorUrl.HtmlConversion.DoNotConvert,
Disabled = Disabled,
FieldID = FieldID,
ID = ID,
ItemID = ItemID,
Language = ItemLanguage,
Mode = string.Empty,
Source = Source,
Url = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx",
Value = Value,
Version = ItemVersion
};
UrlString url = richTextEditorUrl.GetUrl();
handle = richTextEditorUrl.Handle;
ID md5Hash = MainUtil.GetMD5Hash(Source + ItemLanguage);
SheerResponse.Eval("scContent.editRichText(\"" + url + "\", \"" + md5Hash.ToShortID() + "\", " +
StringUtil.EscapeJavascriptString(GetDeviceValue(CurrentDevice)) + ")");
args.WaitForPostBack();
}
I need to get the primary key for a row and then insert it into one of the other columns in a string.
So I've tried to do it something like this:
newsObj = new news();
newsObj.name = "test"
newsObj.Save();
newsObj.url = String.Format("blah.aspx?p={0}",newsObj.col_id);
newsObj.Save();
But it doesn't treat it as the same data object so newsObj.col_id always comes back as a zero. Is there another way of doing this? I tried this on another page and to get it to work I had to set newsObj.SetIsLoaded(true);
This is the actual block of code:
page p;
if (pageId > 0)
p = new page(ps => ps.page_id == pageId);
else
p = new page();
if (publish)
p.page_published = 1;
if (User.IsInRole("administrator"))
p.page_approved = 1;
p.page_section = staticParent.page_section;
p.page_name = PageName.Text;
p.page_parent = parentPageId;
p.page_last_modified_date = DateTime.Now;
p.page_last_modified_by = (Guid)Membership.GetUser().ProviderUserKey;
p.Add();
string urlString = String.Empty;
if (parentPageId > 0)
{
urlString = Regex.Replace(staticParent.page_url, "(.aspx).*$", "$1"); // We just want the static page URL (blah.aspx)
p.page_url = String.Format("{0}?p={1}", urlString, p.page_id);
}
p.Save();
If I hover the p.Save(); I can see the correct values in the object but the DB is never updated and there is no exception.
Thanks!
I faced the same problem with that :
po oPo = new po();
oPo.name ="test";
oPo.save(); //till now it works.
oPo.name = "test2";
oPo.save(); //not really working, it's not saving the data since isLoaded is set to false
and the columns are not considered dirty.
it's a bug in the ActiveRecord.tt for version 3.0.0.3.
In the method public void Add(IDataProvider provider)
immediately after SetIsNew(false);
there should be : SetIsLoaded(true);
the reason why the save is not working the second time is because the object can't get dirty if it is not loaded. By adding the SetIsLoaded(true) in the ActiveRecord.tt, when you are going to do run custom tool, it's gonna regenerate the .cs perfectly.