POIXMLProperties read Property Sets - java

I am trying to read a specific property using Apache POI, my aim is to change its value and save the file in a different location. The issue is that the property in question is not a core, custom or extended one...Its format as shown by Apache Tika is:
<meta name="meta:just-a-name" content="165" />
I have read that with the HPSF API it was possible to read every kind of property in Property Sets, but since my file is a newer version, I cannot use it.
With a custom property I was able to do:
POIXMLProperties properties = document.getProperties();
CTProperty aProperty = properties.getCustomProperties().getProperty("Custom_prop");
aProperty.setI4(12);
properties.commit();
document.write(out);
Do you know how I can do the same thing with the non-standard property?

Related

Read a toml file in java 2022

After a quick research, I found the following three libraries for parsing Toml files in java.
toml4j
tomlj
jackson-dataformats-text
What I am looking for is a library that can parse toml files without a corresponding POJO class. While both toml4j, and tomlj can achieve that, they do not seem to be maintained.
jackson-dataformats-text on the other is actively maintained but I can not parse a toml file without the corresponding POJO class.
Is there a way to create a dynamic class in java that I can use to parse any toml file?
If you just need to read a TOML file without a POJO, FasterXML Jackson libraries are a great choice. The simplest method is to just read the content as a java.util.Map:
final var tomlMapper = new TomlMapper();
final var data = tomlMapper.readValue(new File("config.toml"), Map.class);
After that, the content of the file will be available in data.
If you need even lower level parsing, all formats supported by FasterXML Jackson can be read using the stream API. In case you need that, read about the stream API on the core module: FasterXML/jackson-core, just make sure you use the right factory class (TomlFactory instead of JsonFactory).

How to validate values in a YAML configuration file while loading it?

Is there a way to validate values in a YAML file while loading it in the code. The requirement is I have some elements in the YAML file which must have values. If the validation fails, then YAML should not be loaded.
I'm using snakeyaml library and heard there is a way to do this via Representer.
Code I'm currently using to load the YAML,
Reader in = new InputStreamReader(Files.newInputStream(file), StandardCharsets.UTF_8);
Yaml yaml = new Yaml();
yaml.setBeanAccess(BeanAccess.FIELD);
return yaml.loadAs(in, School.class);
Since you can have any value in a YAML file, you should load the file in a function, test the values and raise an error if the values are not what you want. Return the loaded data if they are.
This may have side-effects if your YAML has tags that create arbitrary objects, but checking during loading will not prevent that, as such object might have been created before you come to the value you want to check.
If you do have tags in your YAML and that is a real problem, then you would have to make a safe_load-er for the YAML file that can handle the tags (by creating normal mapping objects), then check the values and reload with full tag support.

First key from Language properties file not accessible

I have a language properties file with around 3000+ keys. When I try to read the value of a key using
ResourceBundle messages = ResourceBundle.getBundle("com.mt.asm.language.MessagesBundle", locale);, I see that the first key alone is missing in the messages bundle.
I try to retrieve the value using:
String value = new String(messages.getString(key).getBytes("ISO-8859-1") , "UTF-8");
I tried a lot to identify the root cause, but my tries were of no use.
What could be the possible reason for this strange behaviour.
I was able to find the cause of the problem.
The properties file was in UTF-8 BOM format which was expecting Byte Order Mark in the file. This has been solved by using a properties file in UTF-8 format.

Force resolution of xsl:include, xsl:import in Java

I'm using Saxon 9.3 HE and Java 1.6. I can resolve xsl:include and xsl:import statements in the xsl by supplying a resolver to setURIResolver on the TransformerFactory instance.
However the Source resolve(String includee, String includer) method doesn't get called if the file was resolved previously. This is a problem for me because I want to resolve differently based on the includer file. For example <xsl:include href="foo.xsl"/> in file1.xsl would be a different file from <xsl:include href="foo.xsl"/> in file2.xsl, and file1.xsl and file2.xsl would be included by file3.xsl. I have some "base" code and "customer-specific" code that can override the template file and I need to resolve them differently for a framework I'm building.
The XSLT specification is clear that resolving a relative URI in the href attribute against the base URI of the containing element must be done according to the standard rules for handling relative URIs, while dereferencing the resulting absolute URI can be done any way the implementation likes. I'd suggest rethinking your design to take account of this.
I would have expected that because the two XSLs that have that includes in them have different base URIs that the URIResolver would need to be called for each one (what if they are in different directories?).
When creating sources for file1.xsl and file2.xsl, what are their system IDs? If they are null, exist in the same directory or don't have any path information (i.e. systemId is just file1.xsl and file2.xsl) maybe Saxon is trying to do an optimization by assuming they are in the same directory and therefore assuming foo.xsl referred to by each one is the same file.
Maybe try explicitly setting the systemId of the source of the base files and make them have different directories?

How can I get content from Exchange.In:Body object from a ProcessDefinition in Camel

I am integrating data between two systems using Apache Camel. I want the resulting xml to be written to an xml file. I want to base the name of that file on some data which is unknown when the integration chain starts.
When I have done the first enrich step the data necessary is in the Exchange object.
So the question is how can I get data from the exchange.getIn().getBody() method outside of the process chain in order to generate a desirable filename for my output file and as a final step, write the xml to this file? Or is there some other way to accomplish this?
Here is my current Process chain from the routebuilders configuration method:
from("test_main", "jetty:server")
.process(new PiProgramCommonProcessor())
.enrich("piProgrammeEnricher", new PiProgrammeEnricher())
// after this step I have the data available in exchange.in.body
.to(freeMarkerXMLGenerator)
.to(xmlFileDestination)
.end();
best regards
RythmiC
The file component takes the file name from a header (if present). So you can just add a header to your message with the desired file name.
The header should use the key "CamelFileName" which is also defined from Exchange.FILE_NAME.
See more details at: http://camel.apache.org/file2

Categories

Resources