Skip comments & surroundingSpacesNeedQuotes with supercsv 2.2.0 - supercsv

I would ignore comments start with '#' char and surrounding spaces with quotes but with opencsv 2.2.0 does not work.
I searched into the source of supercsv but the skip comment feature preference it never used into the code.
Can you help me ?
Thanks in advance.

As the documentation on the website demonstrates, you have to create a custom CsvPreference and pass that to your CsvReader's constructor. e.g.
// create the custom preference
CsvPreference skipCommentsPreference = new CsvPreference.Builder(
CsvPreference.STANDARD_PREFERENCE)
.skipComments(new CommentStartsWith("#").build();
// create your reader with the preference
ICsvBeanReader beanReader = new CsvBeanReader(
new FileReader("my.csv"), skipCommentsPreference);

Related

Problem to Extending Localization Sources in abp v 6.3.0

I need to extend localization sources.
According to the descriptions in the documentation,
I added the localization sources files in a folder named AbpWebXmlSource and marked embed.
After that, I registered them in the PreInitialize() method of module.
Configuration.Localization.Sources.Extensions.Add(
new LocalizationSourceExtensionInfo("AbpWeb",
new XmlEmbeddedFileLocalizationDictionaryProvider(
Assembly.GetExecutingAssembly(),
"HMS.Core.Localization.AbpWebXmlSource"
)
)
);
But unfortunately it does not work when used. Can anyone help me with this?
after a series of test I find the answer.
first must to added AbpWeb-fr.xml to abp.core project in any folder you want.
then need to get proprties of AbpWeb-fr.xml and convert it to embeded resource.
then must add this code to [your]coremodule.cs in preinitialize() method.
Configuration.Localization.Sources.Extensions.Add(
new LocalizationSourceExtensionInfo("AbpWeb",
new XmlEmbeddedFileLocalizationDictionaryProvider(
Assembly.GetExecutingAssembly(),
"" //important - this line need to fill empty string
)
)
);

How to rename all symbols using Roslyn?

I'm building a Standalone app which will load a folder with c# code, and allow the user to write Regex to select and rename namespace/types/fields/properties/methods/argument/variable/events'name, but i'm stuck at renaming source code.
I have analyzed the SyntaxTree and collected all items, and also searched/matched/renamed with regex.
I have done a plenty of codes trying to get roslyn rename "items", but i only the first "item" is renamed while all the next ones are discarded.
I am aware of Immutability of the Syntax API, and after calling Renamer I save the solution, and also re-search the document in the new solution in the next loop.
//renaming code
var newSolution = await Renamer.RenameSymbolAsync(solution, isymbol, newName, solution.Workspace.Options).ConfigureAwait(false);
this.solution = newSolution;
//re-search code
if (solution.Projects.First ().ContainsDocument(doc.Document.Id)) {
var document = project.GetDocument(doc.Document.Id);
...
}
At the end i call SyntaxTree.GetRoot().ToString (); to get the final edited code, which as mentioned above has only the first edit.
Could anyone explain me the correct way to do this or provide me a sample how this could be implemented so i can try on my own?

meta fields using elasticsearch-dsl

I'm looking at the changelog for the elasticsearch-dsl python library, and one of the comments says:
you can no longer access meta fields on a Document instance by
specifying ._id or similar. Instead all access needs to happen via the
.meta attribute.
Can I get a little more color on that? My old (5.x) code did this
self._id = a_nice_natural_identiifer
How should that be replaced?
self.meta._id = a_nice_natural_identifier
or
self.meta['_id'] = a_nice_natural_identifier
or
self.meta['id'] = a_nice_natural_identifier
It appears that the correct answer is
self.meta['id'] = a_nice_natural_identifier
(Interestingly, you can also set meta properties at construction time by doing)
foo = SomeSubclassOfDocument(_id=a_nice_natural_identifier)

Xpath Part NULL, with xpaths set via content control toolkit

I've been able to set, via code, the xpaths for the placeholders found in the document.
for (Object o : finderSdtRun.results) {
if (o instanceof SdtRun){
SdtPr sdtPr=((SdtRun) o).getSdtPr();
Tag t = sdtPr.getTag();
CTDataBinding ctDataBinding = Context.getWmlObjectFactory().createCTDataBinding();
//JAXBElement jaxbDB = Context.getWmlObjectFactory().createSdtPrDataBinding(ctDataBinding);
sdtPr.setDataBinding(ctDataBinding);
ctDataBinding.setXpath("tuttappostaferragost");
ctDataBinding.setStoreItemID("something");
ObjectFactory factory = new org.opendope.xpaths.ObjectFactory();
DataBinding db = factory.createXpathsXpathDataBinding();
db.setXpath("tuttappostaferragost");
db.setStoreItemID("something");
Xpaths.Xpath xp = factory.createXpathsXpath();
xp.setDataBinding(db);
xp.setId("something");
try {
wordMLPackage.getMainDocumentPart().getXPathsPart().getContents().getXpath().add(xp);
} catch (Docx4JException e) {
e.printStackTrace();
}
;
The problem is that, once set, they are not recognized by word, so I thought to add the created Xpaths to a new XpathPart, and then add it to the main Document part.
But I failed because the method:
wordMLPackage.getMainDocumentPart().getXPathsPart()
returns null. This sounded reasonable, since only content control was set, without any Xpath.
Then I set the Xpaths via content control toolkit and the same line of code like above, returned me null, which added a lot of confusion in my yet confused ideas.
Is there any way to tell the document that new Xpath have been added to the document?
I mean, if there is a way to add Xpath via code (the w:databinding w:storedItemId tags), why it is not possible to make it work?
In general I want to add Xpath and all information necessary, via code, avoiding the use of any toolkit.
Thank you :D
First, you have to decide whether you want plain old Word databinding, or the additional OpenDoPE capabilities (which use the content control tag to support repeats, conditionals etc).
You only need an XPaths part if you are using the OpenDoPE extensions.
I'll assume for now that you are just looking to do basic Word content control databinding.
To set that up programmatically, you need to add a custom xml part, and a rel from it to its itemProps.xml part, which contains something like:
<ds:datastoreItem ds:itemID="{5448916C-134B-45E6-B8FE-88CC1FFC17C3}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml">
<ds:schemaRefs/>
</ds:datastoreItem>
(to add a part B to part A, use partA.addTargetPart)
You can see it is this part with gives the custom xml part its itemID; this corresponds with the value you set in:
DataBinding db = factory.createXpathsXpathDataBinding();
db.setStoreItemID("something");
Then, set the XPath via the method you were using.

Variable autoescape in Smarty templates

I have recently found out that Smarty, differently from Django template engine, does not escape variables automatically and I need to put |escape next to most of the variables in my templates.
Following the docs, http://www.smarty.net/docsv2/en/variable.default.modifiers.tpl I need to set default modifiers, needn't I?
So, here's my code:
$smarty = new Smarty();
$smarty->default_modifiers = array('escape:"htmlall"');
... and still variables ARE NOT escaped until I add |escape next to them.
What am I doing wrong?
If you are on Smarty 3, try this:
$smarty = new Smarty();
$smarty->loadFilter(Smarty::FILTER_VARIABLE, "htmlentities");
Tadà!
Update: Smarty::FILTER_VARIABLE is undocumented as of 28/11/2014. Use $smarty->escape_html = true if you want to stick to offical docs.
It appears that this feature was removed from Smarty v3, and docs are outdated. See:
http://www.smarty.net/forums/viewtopic.php?p=62207
I'd recommend a workaround - which is template level. Either create a new style v3 function to take care of filtration, or, do a simple include.
Include method
Put this in a clean.tpl file:
{$text|escape:htmlall}
Then invoke as {include file=clean.tpl text=$myvariabletofilter}
Function method
The new functions in Smarty could also take care of that:
{function clean}
{$text|escape:htmlall}
{/function}
And invoke as {clean text=$myvariabletofilter}
As always, make sure that these things get trimmed right and don't insert unncessary spaces.

Resources