Programmatically multi language content in Alfresco - java

The requirement I receive is to model some existing content available on a SQL Server database using Alfresco content managment so, I create my new content model and it seems to working fine. But I've a problem with multi language: I know in Alfresco is possible for one node add multiple language (how can I do that using Java for a massive load?) but, I used also some aspects that need to be translated.
What do you usually do in that case? I thoug to follow this steps:
Create Eng content and add aspects
Create new child translted and add aspects
Is it correct? How can I make a node Multilingual programmatically (Java) and how can I add the new translate content with aspects? I took a look to Alfresco documentation but, I didn't find it, could you help me to find some documentation or tutorial about that?
UPDATE:
I'm trying to make a content multilangue:
void makeTranslation(Reference contentNodeRef, Locale locale) throws AlfrescoRuntimeException, Exception
{
try {
NodeRef nodeRef = new NodeRef("workspace://SpacesStore/" + contentNodeRef.getUuid());
MultilingualContentServiceImpl multilingualContentServiceImpl = new MultilingualContentServiceImpl();
multilingualContentServiceImpl.makeTranslation(nodeRef, locale);
}
catch (org.alfresco.error.AlfrescoRuntimeException ex) {
throw new AlfrescoRuntimeException(ex.getMessage());
}
catch (Exception ex) {
throw new Exception(ex.getMessage());
}
}
but, makeTranslation raise an nullPoint exception because MultilingualContentServiceImpl it's not initialized correctly. Any suggestion how to initialize it? I've to use spring but, how?
Any suggerstion or reply will be very helpful!
Thanks,
Andrea

You can use MultilingualContentService to add translations. But! I guess your properties should be of type d:mltext (like cm:title and cm:description are) to support multilingual content.
This means if you access alfresco using browser with english language you will see a different description as someone using german language settings in browser. This can be a little confusing because in Share there is (was?) no identifier that the property is multilingual.
If you want your translations to appear everywhere, no matter what kind of language in browser people are using, then the better approach is to define some aspect (for example ex:translatable) with as many properties as you need translations. Then you can programatically (using Java or JavaScript) use search service to find nodes you want and add the aspect to them. Finally you then add properties (translations) of that aspect to the node.
I hope this helps to clear things a bit... :)

Related

How to clear LastActivityViewer by removing registry keys? Which keys would I remove?

So I'm using the WinRegistry class, found in an answer on this page.
I need to stop my JAR file showing up in LastActivityViewer - which apparently uses Registry Keys to obtain it's information. Now on this site, it explains which registry keys to delete.
I specifically need to clear; Windows Prefetch Folder, Open/Save MRU list in the registry and the Windows Shell Bag Registry (you will understand if you look at the site I linked).
So this much I've figured out, but basically, the WinRegistry class has a deleteKey and deleteValue method which I can use - but how do I know the parameters that I should enter / which method to use?
Please help me on this; I've been looking everywhere and cannot seem to find an answer.
Proof of research:
Finding a specific registry key using java in windows
https://coderanch.com/t/517229/java/Editing-reading-windows-registry-java
Disclaimer: I've tried to word this question as understandable as possible. If it isn't clear then please leave a comment about what is unclear.
try {
//ls = WinRegistry.readStringSubKeys(WinRegistry.HKEY_CURRENT_USER,
// "Software\\Classes\\Local Settings\\Software\\Microsoft\\Windows\\Shell\\");
WinRegistry.deleteKey(WinRegistry.HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ComDlg32\\OpenSavePidlMRU\\jar");
} catch (Exception ex) {
ex.printStackTrace();
}
This is returning a NPE -> will try to fix, but in the meanwhile any help appreciated.
EDIT: I've been looking through regedit and I found this; OpenSavePidlMRU folder which contains "exe, jar, jpg, png" etc inside. I used the RegistryWin.deleteKey method and the jar file disappeared from the registry - this is a good thing but is it dangerous?

RUL-05717: The identifier "Header.Teachers.Courses" is not valid here

I am trying to add rules in my Oracle dictionary through programming in ADF and JDeveloper:
Rule rule = ruleset.getRuleTable().add();
rule.setName(aliasRule);
rule.setAlias(aliasRule);
rule.setPriority(property);
rule.setAdvancedMode(true);
rule.setDescription(description);
return rule;
then:
diccionaryRules.validate(exceptions, warnings);
I have three warnings with the same message:
RUL-05717: The identifier "Header.Teachers.Courses" is not valid here.
Where in my Oracle.rules file I have three viewobjects connected by links through private key ids:
HeaderVVO
TeachersVVO
CoursesVVO
And the route is correct: Header.Teachers.Courses.
I created an expression from the follwoing path:
Header.Teachers by:
Expression ePath = simpleTest.getExpressionTable().get(0);
ePath.setValue("Header.Teachers");
// Here comes some validation
List<SDKWarning> warnings = new ArrayList<SDKWarning>();
List<SDKException> exceptions = new ArrayList<SDKException>();
ePath.validate(exceptions, warnings);
it doesn't give warnings, but this:
ePath.setValue("Header.Teachers.Courses");
gives the above warning.
I don't know why I get these warnings.
You should presume that most of the people trying to answer this question (myself included) while having a good understanding on ADF, don't know much about Oracle Rules.
That being said, this looks like a problem on Rules side, rather than on ADF. As I see you are using view objects, you can probably test this integration logic from Business Components Tester and you can inject your Rules logic through application modules custom methods.
Bottom line, you are building a Rules client from java, this is not directly related to ADF. If you can make your client work from a java main(String[] args) method, it will work from ADF too.

Extracting Geometry from IFC File

I have to extract the geometry of a ifc file in JAVA. My problem is, that i don't know how to do it.
I tried to use openifctools but the documentation is really bad. For now i have the ifc file loaded, but i cannot get the geometry out of the model.
Does anyone have experience with ifc model loading?
Thanks in advance.
EDIT: This is what I've done so far
try {
IfcModel ifcModel = new IfcModel();
ifcModel.readStepFile(new File("my-project.ifc"));
Collection<IfcClass> ifcObjects = ifcModel.getIfcObjects();
System.out.println(ifcObjects.iterator().next());
} catch (Exception e) {
e.printStackTrace();
}
This correctly loads the ifc file. But I don't know what to do with this information.
I also tried to use IfcOpenShell but the provided jar container hadn't worked either. At the moment I try to build IfcOpenShell by myself.
I'm kinda desperate because everything is very undocumented and I really need to load and parse the ifc geometry.
Depending on what you want to do with the geometry, how deep you want to delve into the IFC standard and what performance you need for your solution you have two different options:
Extract the implicit geometry on your own
Use an external geometry engine
If you go for the first option, you'd have to study the IFC schema intensively. You would only be interested in IFCProducts, because only those can have geometry. Using OpenIfcTools you could do something like:
Collection<IfcProduct> products = model.getCollection(IfcProduct.class);
for(IfcProduct product: products){
List<IfcRepresentation> representations = product.getRepresentation().getRepresentations();
assert ! representations.isEmpty();
assert representations.get(0) instanceof IfcShapeRepresentation:
Collection<IfcRepresentationItem> repr = representations.get(0).getItems();
assert !repr.isEmpty();
IfcRepresentationItem representationItem = repr.iterator().next();
assert representationItem instanceof IfcFacetedBrep;
for(IfcFace face: ((IfcFacetedBrep)representationItem).getOuter().getCfsFaces()){
for(IfcFaceBound faceBound: face.getBounds()){
IfcLoop loop = faceBound.getBound();
assert loop instanceof IfcPolyLoop;
for(IfcCartesianPoint point: ((IfcPolyLoop) loop).getPolygon()){
point.getCoordinates();
}
}
}
}
However, there are a lot of different GeometryRepresentations, which you'd have to cover, probably doing triangulation and stuff on your own. I've shown one special case and made a lot of assertions. And you'd have to fiddle with coordinate transformations, because these may be nested recursively.
If you go for the second option the geometry engines I know are all written in C/C++ (Ifcopenshell, RDF IfcEngine), so you'd have to cope with native library integration. The jar package provided with IFCOpenshell is intended to be used as a Bimserver plugin. Those you can't use it without the respective dependencies. However you can grab the native binaries from this package. In order to use the engine you can draw some inspiration from the Bimserver plugin source. The key native methods you're gonna use are
boolean setIfcData(byte[] ifc) to parse the ifc data
IfcGeomObject getGeometry() to access the extracted geometry successively.

How to set the Locale Value based on the country the user belongs to

Currently my J2EE Application supports these below countries
MessagesBundle_en_GB.properties (United Kingdom )
MessagesBundle_en_US.properties (United States )
MessagesBundle_it_IT.properties (Italy )
MessagesBundle_pt_BR.properties (Brazil )
MessagesBundle_sv_SE .properties (Sweden)
So i made a properties files for all these countries above and defined the Key value pairs in it .
I am using Resource Bundle for this concept .
And the way i will be accessing the key name is this way
bundle.getString("userName"));
bundle.getString("Mobile"));
Now my question is ,
How can i set the Locale value inside the JSP Page , because the user might belong any of the country as mentioned above
Please let me know , thank you very much
// This one is hardcoded , how can i set this dynamically ??
ResourceBundle bundle = ResourceBundle.getBundle("MessagesBundle", Locale.UK);
use ResourceBundle.getBundle(BUNDLE_NAME).getString(key); to access the Strings.
when updating the Default Locale e.g. via Locale.setDefault(<REQUIRED_LOCALE>); clear the Resourcebundle cache: ResourceBundle.clearCache();
the next call of ResourceBundle.getBundle(BUNDLE_NAME).getString(key); should the return the localized String of the chosen Locale.
The simplest way to do it is to implement HttpFilter. Call it for example LocaleHttpFilter. It should be mapped to/*` in your web.xml, so it will be called every time the request arrives to your application.
The filter will discover your request and decide what should be the current locale. It may base its decision on URL parameters, HTTP headers, GeoIP lookup etc. Once it decided about the locale it should call:
Locale.setDefault(locale)
Then you can use
ResourceBundle.getBundle("MessageBundle").getString("hello");
at any place in your code. This line will return value of string "hello" according to the current locale that was set into the filter.
First thing first: you may use ResourceBundle.getBundle(Locale) in your back-end code. However, you should never use this in the JSP Page directly. You should use JSTL instead. Now, let's get into details.
There are two reasons why it is not necessary the good idea to use ResourceBundle directly. One is related to this:
<%
try {
ResourceBundle rb = ResourceBundle.getBundle("messages", locale);
} catch (MissingResourceException mre) {
// LOG THIS!
}
%>
This looks pretty ugly, doesn't it? That's because you have to beware of MissingResourceException that will be thrown if there is no bundle for base name you are looking for. To make matters worse, the same exception might be thrown if there is no key in the given scenario:
rb.getString("key");
So you also need to take this into account:
<%
try {
rb.getString("key");
} catch (MissingResourceException mre) {
// LOG THIS!
}
%>
How does it look?
Of course you can derive from ResourceBundle and override these methods so they won't throw an exception, but this is substantially more work than just this:
<fmt:setLocale value="fr_CA" scope="session"/>
<fmt:bundle basename="com.taglib.weblog.Greeting">
<fmt:message key="com.taglib.weblog.Greeting.greeting">
This is the reason you should use JSTL with JSP. Read more about how to use JSTL for i18n in this article.
Now, your original question was about language negotiation (W3C term), or Locale detection if you prefer. How to do that in JSP application?
The easiest and most typical scenario is to read the contents of HTTP's Accept-Language header. In Java Servlet world that means calling ServletRequest's getLocale() or getLocales() method and assign to variable in HttpSession object, which is accessible from JSP page. If you wonder how to access HttpSession on the servlet side, there is a getSession() method.
That works if you have direct access to Servlet. If you don't you need to create (or assign existing) Locale filter which will do all that for you. As you may imagine, this is fairly common scenario. That's the reason people already written (long time ago) necessary classes. You can find in few frameworks, let me notably mention Spring Framework.
I know it might sound strange, but if you are looking for simple solution, learning and using common web framework (i.e. Spring MVC) is better that re-inventing the wheel. I know that learning curve might be a bit steep, but it is worth it.

Is there a library for reading maven2/3 pom xml files?

I would like to read a pom.xml in Java code. I wonder if there is a library for that, so I can have an iterator for different sections, e.g., dependenes, plugins, etc. I want to avoid to build a parser by hand.
You can try MavenXpp3Reader which is part of maven-model. Sample code:
MavenXpp3Reader reader = new MavenXpp3Reader();
Model model = reader.read(new FileReader(mypom));
Firstly, I'm assuming you are not already running inside a Maven plugin, as there are easier ways to achieve that with the available APIs there.
The MavenXpp3Reader solution posted earlier will allow you to read the POM easily, however does not take into account inheritance of the parent and interpolation of expressions.
For that, you would need to use the ModelBuilder class.
Use of this is quite simple, for example from Archiva is this code fragment:
ModelBuildingRequest req = new DefaultModelBuildingRequest();
req.setProcessPlugins( false );
req.setPomFile( file );
req.setModelResolver( new RepositoryModelResolver( basedir, pathTranslator ) );
req.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
Model model;
try
{
model = builder.build( req ).getEffectiveModel();
}
catch ( ModelBuildingException e )
{
...
}
You must do two things to run this though:
instantiate and wire an instance of ModelBuilder including its private fields
use one of Maven's resolvers for finding the parent POMs, or write your own (as is the case in the above snippet)
How best to do that depends on the DI framework you are already using, or whether you want to just embed Maven's default container.
This depends on what you're trying to achieve. If you just want to treat it as an XML with embedded XML files, go with suggestions already offered.
If you are looking to implement some form of Maven functionality into your app, you could try the new aether library. I haven't used it, but it looks simple enough to integrate and should offer Maven functionality with little effort on your part.
BTW, this library is a Maven 3 lib, not Maven 2 (as specified in your tag). Don't know if that makes much difference to you

Categories