I need to filter some pages so that they won't appear in search.
For that there is a method called
addPredicate(new Predicate("mytype", "type").set("group.4_group.1_property", "jcr:content/cq:template"));
This method is not present in com.day.cq.wcm.foundation.Search. I'm not sure in which API this addPredicate method is present.
In the CQ5 docs, it is said that this method is implemented in SimpleSearchImpl, which is present in the package com.day.cq.search.impl.SimpleSearchImpl. However, when I try to import that package, it throws an error saying that package is invalid.
If SimpleSearchImpl is not the required class for addPredicate method, can you please tell me what is the class that is needed for the method addPredicate?
The com.day.cq.search.SimpleSearch interface is exported from the cq-search bundle, but not the com.day.cq.search.impl.SimpleSearchImpl implementation class.
You can see a list of the exported packages here:
http://localhost:4502/system/console/bundles/com.day.cq.cq-search
You can get a reference to a SimpleSearch implementation by adapting a Resource or using a SCR reference.
Alex Klimetschek gave a great presentation on [using the QueryBuilder API]http://www.slideshare.net/alexkli/cq5-querybuilder-adapttoberlin-2011) as an alternative to the SimpleSearch approach, this might be useful for helping to understand predicates.
Related
I am new to Java. I have the following package structure.
Package 1
AppName
Main
SomeOtherClass
Package 2
API
Load
Callback
From the Main class of AppName Package I want to create an object of Load class of the API package.
Now I can easily do that by import API.* and then using new Load();.
But what I want the full connotation of the Load class. I want to make a new API call using new API.Load();
So What I want is to be able to use API. prefix with Load class's construction. Is it possible at all? What kind of import will work? Simply using new API.Load(); doesn't work. Android studio doesn't recognize the API keyword.
Any ideas?
Edit:
Ok I sort of have what I want. com.achshar.testapp.API is the complete name. So
new com.achshar.testapp.API.Load(); works fine. Now how can I make it new API.Load();?
If you have a doubt, you can use Class#getCanonicalName to print the full path of a class.
Here, an example with ArrayList
List<String> str = new ArrayList<>();
System.out.println(str.getClass().getCanonicalName()); // java.util.ArrayList
And now if I want I can write my lists like the following
java.util.List<String> list = new java.util.ArrayList<>();
You can create your API (some what like Proxy layer). In it you can create your Load.java class, Callback.Java class. Provide some different name to your package.
If classes in API package of package 2 are not declared as final and also have public constructors, you can extend each class to create a new class in your created new API package.
In the new class you create, you can override the methods (functions) and give your behavior. You can use super.methodOfAPI to get the behavior provided by the parent class and then can write your code to add the behavior you want.
You need to take care as when you wish to use original API package classes and when from your created layer. Use your imports accordingly. Another way out is to append some common word like 'Proxy' in the end of the classes you creae in the new API package you create, it will resolve the conflicts.
First of all some context, to thoroughly explain the methods I've already tried:
I'm working in a java-based programming platform on windows which provides access to custom java functions with several other extensions. Within the source code of this modelling platform, there is a class "CVODE" which grants access to native library "cvode" to import the functionality of a C++ library CVODE.
//imports
public class CVODE {
static {
Native.register("cvode");
}
public static native int ... //methods
}
I created shared libraries from the CVODE library, which resulted in 2 files: sundials_cvode.dll and sundials_nvecserial.dll.
Adding the first library to my java path obviously resulted in
Unexpected Exception UnsatisfiedLinkError: Unable to load library 'cvode': The specified module could not be found.
as the names were not compatible. Therefore I changed the name of sundials_cvode.dll to cvode.dll and retried. Resulting in an error indicating that not all methods are present in the library sundials_cvode.dll:
Unexpected Exception UnsatisfiedLinkError: Error looking up function 'N_VDestroy_Serial': The specified procedure could not be found.
This convinces me that the library is being found and loaded correctly, but not all methods are available. Examining the dll's in question led me to the conclusion that the CVODE class requires functions from both the sundials_cvode.dll and sundials_nvecserial.dll libraries. Therefore I tried changing the platform source-code to
public class CVODE {
static {
Native.register("sundials_cvode");
Native.register("sundials_nvecserial");
}
public static native int ... //methods
}
which still results in
Unexpected Exception UnsatisfiedLinkError: Error looking up function 'N_VNew_Serial': The specified procedure could not be found.
I have confirmed this method is present in both the class file and in the dll:
So I can only guess the error results from calling the Native.register() twice. resulting in the 2nd library not being loaded or an error down the way. I'd appreciate some insight in what I'm doing wrong or how I can gain a better overview of what's going wrong.
As far as I know, you can only load one dll per class, i.e. split the classes into two, each providing the methods the particular dll provides.
See also here: https://stackoverflow.com/a/32630857/1274747
I'm developing an android test app and i'm going to access all internal class of android.view package. android.view is a package that is present in jar file. I tried by loading package name but it doesn't display the classes if any one tried
this already, please help.
Here's what I tried so far:
public static void main() throws ClassNotFoundException{
Class o =Class.forName("android.view");
Class[] C=o.getDeclaredClasses();
for(int i=0;i<C.length;i++) {
Classname = C[i].getName();
ClassesDisplayActivity.your_array_list3.add(Classname);
Log.i("Ramu","classname "+ C[i].getName());
}
}
}
It is not possible to determine at runtime all of the classes that are in a package using a standard class loader.
You might have some luck with this library though:
https://code.google.com/p/reflections/
Package is not a class. You cannot call Class.forName() for package and access classes that belong to class using getDelcaredClasses().
I do not know what do you really need, so I'd recommend you to explain this in separate question. probably you will receive better solutions.
However if you really need this you have to do the following:
Get your classpath by calling System.getProperty(java.class.path)
split this property to its elements by colon
iterate over the list and read each resource. If resource is jar you can use ZipInputStream, if it is a directory use File class.
filter list of resources you got at #3.
Fortunately you can use 3rd party library named Reflections that helps you to do all this without writing code.
I tried to cast Action response like this:
private void mappingMethod(ActionResponse response) {
ActionResponseImpl actionResponseImpl = (ActionResponseImpl)response;
...}
In debugging on "Expression Evaluation" window I can see the type of "responce" is ActionResponseImpl, and cast does not cause exception. But on runtime I have this exeption:
java.lang.ClassCastException: com.liferay.portlet.ActionResponseImpl cannot be cast to com.liferay.portlet.ActionResponseImpl
Please tell me what is the problem.
P.S.: In PortalImpl class, the copyRequestParameters method has same string, but here it's working....
It would do you good if you refrained from using classes from portal-impl.jar in your custom plugin portlet.
ActionResponseImpl is a class in the portal-impl.jar. So if you can give a use-case as to why you are planning to use this class, then we can suggest alternative.
You have ActionResponseImpl twice on the classpath - what jars from Liferay did you include in your project? As Prakash mentions, it's portal-impl.jar, which you can not have in a plugin.
What the ClassCastException wants to tell you is that your class extends one implementation of ActionResponseImpl, but the runtime environments expects it to be another implementation - they might be identical, but as they are loaded from two different sources, the classloader cannot refer one to another superclass than it extends.
I saw this issue, when I call a method using Ajax from XHTML page. I modified my method to return simple string and removed the code that tries to modify the actionResponseImpl and that resolved the issue.
This type of errors are produced by different classloaders. A class is identified by their fully qualified class name AND its Classloader. So if you embedd portal-impl in your portlet; the action is going to receive an ActionResponseImpl instance from the portal classloader and is trying to cast this one to a class of your portlet class loader .
see more: http://www.javaspecialists.eu/archive/Issue018.html
Currently my project developed using simple JSP and servlets has the following packages
1-Business package (Contains summed up methods from service package under a business rule)
2-Service package (Contains different services and their implementation - along with factory
method to call a specific implementation of each service)
3-Controller package (All the servlet controls ..)
3-Views (All the jsps)
4-CustomTags (Contain the Custom Tags)
5-Domain (Contains Domain objects)
Now I am planning to implement the same project using struts2 could you tell me what packages should i introduce. I know the service and business package will remain intact what about the controller package ? Should i place all the actions in the controller package ? Any suggestion will be appreciated.
Do not organise all your classes based on their type, they should be organised or grouped together with their immediate collaborators. If you can help it, place XAction and XController together in the same package. Its silly to place XAction in a separate package with 49 other actions that really have no relation while its controller is somewhere else.
If you group collaborators together in the same package its quite easy to know the working group and be reasonably more confident that changing one probably affects the other. With your original suggestion, who really knows what Action works with what Controller and so on.
Is possible!
Struts from 2.0 to 2.3.x (I used theses versions), if you use the annotations struts2-convention-plugin.jar dependency, you can do that:
The package default (generally is zx.yz.actions) mapped all Actions on the project and it is your package namespace from image above.
When you create a new package inner Actions package, zx.yz.actions.example for instance, you are creating a new namespace /servletContext/example in your application.
To disable it, you only need put a '/' before your "Action()" annotation method. For example:
public class ExampleAction {
#Action(value="/example",
#Result(name="ok", type="httpheader", params={"status", "200"})
public String execute() {
}
}
The '/' in '/example', will put in de namespace default.