I have created a eclipse plugin which implement a new WorkbenchRendererFactory.
public class MyRendererFactory extends WorkbenchRendererFactory {
private MyStackRenderer stackRenderer;
#Override
public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent) {
if (uiElement instanceof MPartStack) {
if (stackRenderer == null) {
stackRenderer = new MyStackRenderer();
super.initRenderer(stackRenderer);
}
return stackRenderer;
}
return super.getRenderer(uiElement, parent);
}
}
But I do not know to how to replace the default renderfactory with my new renderfactory.
I tried to register it in the plugin.xml
<extension
id="product"
name="stacker"
point="org.eclipse.core.runtime.products">
<product
name="com.fakecoder.stackrenderer"
application="org.eclipse.e4.ui.workbench.swt.E4Application">
<property
name="appName"
value="com.fakecoder.stackrenderer">
</property>
<property
name="rendererFactoryUri"
value="bundleclass://com.fakecoder.stackrenderer/com.fakecoder.stackrenderer.swt.MyRendererFactory">
</property>
</product>
</extension>
but failed.
How could I change the default render of eclipse in a eclipse plugin?
Related
I'm new to selenium, can anyone help me on how to run the same test case in 2 different URL which has the same functionality
Two ways you can do it.
1) Passing value from xml in testng file.
Test code you can refer.
public class ParameterTest
{
#Parameters({ "url" })
#Test
public void optionTest(String value) {
System.out.println("This is: " + value);
}
}
<suite name="Optional test Suite" verbose="1">
<test name="Optional Test one">
<parameter name="url" value="https://xy.cm" />
<classes>
<class name="test.parameter.OptionalTest" />
</classes>
</test>
<test name="Optional Test two">
<parameter name="url" value="https://abc.om" />
<classes>
<class name="test.parameter.OptionalTest" />
</classes>
</test>
</suite>
2) You can use data provider in testng to pass url as parameter in your test case.
public class SameClassDataProvider
{
#DataProvider(name = "url")
public Object[][] dataProviderMethod() {
return new Object[][] { { "https://yahoo.com" }, { "https://google.in" } };
}
#Test(dataProvider = "data-provider")
public void testMethod(String url) {
//write your test case
}
}
Hope this help you!
how can i use org.springframework.beans.propertyeditors.CustomDateEditor if i have 2 date formats in a single line in a flat file.
<bean id="dateEditor1" class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg>
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="MMddyyyy" />
</bean>
</constructor-arg>
<constructor-arg value="true" />
</bean>
<bean id="dateEditor2" class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg>
<bean class="java.text.SimpleDateFormat">
<constructor-arg value="MMddyyyyHHmm" />
</bean>
</constructor-arg>
<constructor-arg value="true" />
</bean>
<property name="customEditors">
<map>
<entry key="java.util.Date" value-ref="dateEditor1"/>
<entry key="java.util.Date" value-ref="dateEditor1"/>
</map>
</property>
I am trying the above code. but it doesnt work. i am useing PatternMatchingCompositeLineMapper.
Used the below custom date format:
public class CustomDateFormats extends DateFormat {
private static final long serialVersionUID = 1L;
private static final String[] formats = new String[] { "MMddyyyy", "MMddyyyyHHmm", "MMdd" };
Date result = null;
#Override
public StringBuffer format(final Date date, final StringBuffer toAppendTo, final FieldPosition fieldPosition) {
throw new UnsupportedOperationException("This custom date formatter can only be used to *parse* Dates.");
}
#Override
public Date parse(final String source, final ParsePosition pos) {
Date res = null;
for (String format : formats) {
if (source != null && format.length() == source.length()) {
SimpleDateFormat sdFormat = new SimpleDateFormat(format);
res = sdFormat.parse(source, pos);
break;
}
}
return res;
}
}
<bean id="dateEditor1" class="org.springframework.beans.propertyeditors.CustomDateEditor">
<constructor-arg>
<bean class="com.disney.wdpro.service.transaction.processing.batch.domain.logicalBatchOpen.CustomDateFormats" />
</constructor-arg>
<constructor-arg value="true" />
</bean>
You can't do that. Look at the map where you are trying using java.util.Date as key and then you are expecting it to hold 2 values. map doesn't work that way, it will always override the value if the key is already existing. Thus in your case you have to write a customized bean for to set these fields in your flat file.
According to the Spring doc,only one single registered custom editor per property path is supported.
But you can write a custom dateformat class which will hold a list of different date formats and use this class to autowire to custom editor.
For example one like given below or you create your customized editor and wrap a list of CustomDateEditor , There are multiple use , you can refer to one example like below.
<bean id="customer4" class="org.testSpring.util.DateBeanTest4">
<property name="birthDate">
<bean factory-bean="customDateFormat" factory-method="parse">
<constructor-arg value="31-01-2010" />
<!-- mm/dd/yyyy, dd-MM-yyyy, yyyyMMdd -->
</bean>
</property>
</bean>
<bean id="customDateFormat" class="org.testSpring.util.CustomDateFormats">
</bean>
And your formatter class
public class CustomDateFormats extends DateFormat {
private static final List<? extends DateFormat> DATE_FORMATS = Arrays.asList(
// or inject thorough construction with a list of formats
new SimpleDateFormat("dd-MM-yyyy"),
new SimpleDateFormat("mm/dd/yyyy"),
new SimpleDateFormat("yyyyMMdd"));
#Override
public StringBuffer format(final Date date, final StringBuffer toAppendTo, final FieldPosition fieldPosition)
{
throw new UnsupportedOperationException("This custom date formatter can only be used to *parse* Dates.");
}
#Override
public Date parse(final String source, final ParsePosition pos) {
Date res = null;
for (final DateFormat dateFormat : DATE_FORMATS) {
if ((res = dateFormat.parse(source, pos)) != null) {
return res;
}
}
return null;
}
}
I am developing a restful WS and I want to give the option to the users to take data back from my WS in the form of XML or Json and also to be able to choose a callback function if they want Jsonp. This is what I have until now and the part with the Interceptors is based on CXF - JAX-RS : Data Bindings.
My Rest Service:
#GET
#Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
#Produces({ "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getServers(#Context ServletContext context,
#Context Request request,
#QueryParam("format") String format,
#QueryParam("callback") String callback) {
some code where server object is created....
if(format.equals("json"){
if(callback!= null){
response = Response.status(Status.OK).type("application/x-javascript")
.entity(server).build();
}else{
response = Response.status(Status.OK).type("application/json")
.entity(server).build();
}
} else {
response = Response.status(Status.OK).type("application/xml")
.entity(server).build();
}
return response;
}
My Server object:
#XmlRootElement (name="Server")
public class Server implements Serializable {
private String name=null;
private String hardware = null;
public Server(){
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getHardware() {
return hardware;
}
public void setHardware(String hardware) {
this.hardware = hardware;
}
}
My beans.xml in the WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<context:property-placeholder/>
<context:annotation-config/>
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"/>
<bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/>
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<bean class="com.ba.serversws_cxf.resources.MyResource" />
</jaxrs:serviceBeans>
<jaxrs:inInterceptors>
<bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor">
<property name="callbackParam" value="callback"/>
</bean>
</jaxrs:inInterceptors>
<jaxrs:outInterceptors>
<bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor">
<property name="mediaType" value="application/x+javascript"/>
</bean>
<bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/>
</jaxrs:outInterceptors>
<jaxrs:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
</beans>
The error that I get when I set the query parameter "callback" is:
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage
WARNING: No message body writer has been found for response class Server.
It works fine for other other two cases.
I have searched to find a solution but still nothing.
Any ideas?
Thanks
Here is my class that #Overrides the wrtieTo() method of the org.apache.cxf.jaxrs.provider.json.JSONProvider;
First of all in my beans.xml file I have used the <jaxrs:extensionMappings> and I have declared a jsonp extention.
Here is the code
<jaxrs:server id="services" address="/">
<jaxrs:extensionMappings>
<entry key="xml" value="application/xml" />
<entry key="json" value="application/json" />
<entry key="jsonp" value="application/javascript"/>
</jaxrs:extensionMappings>
</jaxrs:server>
And below is my code of the writeTo() method that I have #Override
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import org.apache.cxf.jaxrs.provider.json.JSONProvider;
import org.apache.cxf.jaxrs.utils.HttpUtils;
#SuppressWarnings("rawtypes")
#Produces("application/javascript")
public class JsonpProvider extends JSONProvider {
#SuppressWarnings("unchecked")
#Override
public void writeTo(Object obj, Class cls, Type genericType,
Annotation[] anns, MediaType m, MultivaluedMap headers,
OutputStream os) throws IOException {
String requestURI = getContext().getHttpServletRequest()
.getRequestURI();
if (requestURI.contains(".jsonp")) {
String prefix = getContext().getHttpServletRequest().getParameter(
"_jsonp");
if (prefix != null && !prefix.isEmpty()) {
os.write(prefix.getBytes(HttpUtils.getSetEncoding(m, headers,
"UTF-8")));
} else {
os.write("callback".getBytes(HttpUtils.getSetEncoding(m,
headers, "UTF-8")));
}
os.write('(');
super.writeTo(obj, cls, genericType, anns, m, headers, os);
os.write(')');
} else {
super.writeTo(obj, cls, genericType, anns, m, headers, os);
}
}
}
So what I am doing in the code above is I am checking if the .jsonp extension has been given to the URL. If yes then I know that I have to return the jsopn with a callback function. The last thing is to set the name of the callback function. If the user has set the _jsonp query parameter to the URL then the value of this parameter will be the name of the callback function. If the _jsonp pquery parameter is null then I put a defult name callback.
And off course in the beans.xml file as a json provider you put the JsonpProvider above:
<jaxrs:providers>
<bean class="org.apache.cxf.jaxrs.ext.search.SearchContextProvider"/>
<bean class="com.ba.serversws_cxf.utils.JsonpProvider">
<property name="ignoreNamespaces" value="true" />
<property name="dropRootElement" value="false" />
<property name="supportUnwrapped" value="true" />
</bean>
</jaxrs:providers>
Hope that helps #bhuvan !
I'm trying to do a progarm small with spring
<bean
id="mybean"
class="com.spr.main.Persona"
p:name="Peter"
p:age="33"
p:address="LA"
p:company="Googel"
p:email="Peter#google.com"
/>
<bean id="logger" class="com.spr.main.Log" />
<aop:config>
<aop:aspect ref="logger">
<aop:pointcut id="testPointcut"
expression="execution(* com.spr.main.Person.toString(..)) and target (bean)" />
<aop:before method="logInfo" pointcut-ref="testPointcut" arg-names="bean"/>
<aop:after-returning method="logWarning" pointcut-ref="testPointcut" arg-names="bean"/>
</aop:aspect>
</aop:config>
the bean work fine, but aop doesn´t show the log messaga, this is the Log class:
public class Log
{
public static void logInfo()
{
Logger.getLogger(Log.class.getName()).log(Level.INFO, "Info Message...");
}
public static void logWarning()
{
Logger.getLogger(Log.class.getName()).log(Level.WARNING, "Warning Message...");
}
}
I'm using GWT 2.1 java.util.logging emulation to log client side messages. According to the doc, two Formatters are provided (TextFormatter and HTMLFormatter) which are appropriate to client side logging.
Can anyone provide an example on how to setup a formatter and attach it to a handler in GWT?
Thanks
See the GWT documentation for logging here. It really depends on where you want your logging to appear, but if you only care about logging in Dev mode then you only need the SystemLogHandler and the DevelopmentModeLogHandler. The ConsoleLogHandler and FirebugLogHandler are used for web mode logging to chrome, firebug and firebug lite. The PopupLogHandler and HasWidgetsLogHandler add the log messages to some sort of UI element. All of the above should be capable of being enabled/disabled in the .gwt.xml except the HasWidgetsLogHandler which requires an associated widget container. This should be possible by adding the following:
<inherits name="com.google.gwt.logging.Logging"/>
<set-property name="gwt.logging.logLevel" value="SEVERE"/> # To change the default logLevel
<set-property name="gwt.logging.enabled" value="FALSE"/> # To disable logging
<set-property name="gwt.logging.consoleHandler" value="DISABLED"/> # To disable a default Handler
<set-property name="gwt.logging.developmentModeHandler" value="DISABLED" />
<set-property name="gwt.logging.popupHandler" value="DISABLED" />
<set-property name="gwt.logging.systemHandler" value="DISABLED" />
<set-property name="gwt.logging.firebugHandler" value="DISABLED" />
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
etc...
Here is a simple example of adding a Log handler to the Root logger. The logger uses the HTMLLogFormatter and puts the message in a HTML widget.
HTML html = new HTML();
// add the html widget somewhere in your code.
Logger.getLogger("").addHandler(new Handler() {
{
// set the formatter, in this case HtmlLogFormatter
setFormatter(new HtmlLogFormatter(true));
setLevel(Level.ALL);
}
#Override
public void publish(LogRecord record) {
if (!isLoggable(record)) {
Formatter formatter = getFormatter();
String msg = formatter.format(record);
html.setHTML(msg);
}
}
});
Also have a look at HasWidgetsLogHandler, which basically does what the handler in the example above does.
Here are the two classes I ended up using:
import java.util.Date;
import java.util.logging.LogRecord;
import com.google.gwt.logging.impl.FormatterImpl;
public class LogFormatter extends FormatterImpl {
private static final StringBuilder sb = new StringBuilder();
#Override
public String format(LogRecord rec) {
synchronized (sb) {
sb.setLength(0);
sb.append(new Date(rec.getMillis()).toString());
sb.append(": ");
sb.append(rec.getMessage());
sb.append("\n");
return sb.toString();
}
}
}
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
public class ALog {
/* IMPORTANT: User blank string (root logger) here or else it WILL NOT have the formatter being used */
private static final Logger logger = Logger.getLogger("");
static {
for (Handler handler : logger.getHandlers()) {
handler.setFormatter(new LogFormatter());
handler.setLevel(Level.ALL);
}
}
public static void log(String msg) {
logger.log(Level.INFO, msg);
}
public static void log(String msg, Throwable e) {
logger.log(Level.INFO, msg, e);
}
}