java

Web templating (struts tiles) - best solution to indicate current page?

I would like to indicate the currently chosen page in a shared menu component of a web page in a Struts Tiles project. I can think of some possible solutions check current URL call some Javascript to indicate possibly hooked into the tiles or struts config files and read. I'm sure this problem has been faced many times before. What...

Spring and the scope attribute

Hi everyone, I am facing a problem in my Spring learning and would need some help, I don't think this require strong Spring skills as this is a beginner question. I was learning about the prototype scope of a bean, which basically mean that each time this bean will be required by someone or some other beans, Spring will create a new b...

What is the best List implementation for Large lists in java

Hi, I have to create a large list of n elements (could be up to 100,000). each element in the list is an integer equivalent to the index of the list. After this I have to call Collections.shuffle on this list. My question is, which list implementation (either java collections or apache collections) should be used. My gut feeling is Ar...

Reponse outputstream content length?

I am writing to output stream through various methods. How can I, before I close it, find out content length of the outputstream? ...

Spring Advice - submitting a form

Hi, I am having serious problems with code I have written with Spring so I have decided to start from scratch and ask for advice. Here are my requirements: When the page first loads I need a list of objects retrieved from the DB that I can access on the JSP. I use this list to populate a drop down. When the user selects an object...

Using Spring JUnit4 and JMock together

When I run my Junit4 tests now I use the @RunWith(SpringJUnit4ClassRunner.class) annotation which allows me to inject Spring Beans into my test class. I would like to use the JMock 2 framework (which I have no real experience of) but examples I see require the following @RunWith(JMock.class). So my question is can I use JMock and Sprin...

How to preload custom colors in SWT ColorDialog

Hi all, my application users the SWT Color Cell Editor to set a color property. This class in turn users the native color dialog - which offers preset and custom colors. My users are frustrated because whilst the color dialog allows them to enter custom colors, the application doesn't remember these custom colors (in either Win32 or OS...

Error reading log file with reg expression

I am trying to read a log file with the content look like this: 127.0.0.1 - - [17/OCT/2009:00:02:14 0000] GET xxxxxx xxxx xxx I tried the following reg exp and I am getting ERROR: Unclosed group near index 90 regex = (\d+\.\d+\.\d+\.\d+)\s-\s-\s\[(\d+)/(\w{3})/(\d{4}):(\d{2}):(\d{2}):(\d{2})\s(\d{4}\)].* Can someone help me? ...

Unmarshalling related XML elements within different subtrees

Good day to you, I use Castor to map network infrastructure into Java classes. My XML file looks like this: <SPECTRUM_Topology> <Topology> <!-- Device information --> <Device ip_dnsname="172.20.162.1" ... /> </Topology> <Update> <Device ip_dnsname="172.20.162.1"> <!-- Port information --> <Port ... /> ...

How to make swing components not resizable

Hi, I'm trying to make some components inside a JSrollPane unresizable, because content inside can grow dynamically and I must prevent it from growing over a predefined size. My approach so far is this one: scrollPane(constraints:BL.CENTER, size:[500,200], maximumSize:[500,200]){ panel(background:Color.WHITE, border:BF.createTitled...

How to sign a custom JCE security provider

Sun's PKCS11 JCE security provider is lacking some functionality we need. So I wrote an enhanced version of it using the original sources. Unfortunately the JCE infrastructure rejects the new provider "JCE cannot authenticate the provider" because it is not properly signed. javax.crypto.JceSecurity.verifyProviderJar(...) throws. (it ca...

eclipse build path

Is there a way I can keep the jars on my build path from showing up in the eclipse project? I have a libs folder they are all under which is fine, but when I add them to Eclipse's build path they get reproduced just below the project making a huge list of jars and making it generally hard to find things. I've tried filtering them and fin...

Can I do this Generic thing?

Hi there: It seems I'm missing something with Java Generics because something I think is simple, it appears to me that can´t be done. Maybe you can help... This is the scenario: I'm coding a generic abstract DAO with simple CRUD operation so every specific DAO of my application can have it for free: public abstract DefaultDAO<T,V> { ...

Creating daily logs with Log4j?

What configuration values are needed to setup Log4j to use the following pattern? MyApp-Mon.log MyApp-Tue.log MyApp-Wed.log Etc With each file containing the days log. This sounds easy enough to do with Log4j's DailyRollingFileAppender but I am having trouble. Here is my current config; <appender name="daily-file" class="org.apache.lo...

Java: splitting a comma-separated string but ignoring commas in quotes

I have a string vaguely like this: foo,bar,c;qual="baz,blurb",d;junk="quux,syzygy" that I want to split by commas -- but I need to ignore commas in quotes. How can I do this? Seems like a regexp approach fails; I suppose I can manually scan and enter a different mode when I see a quote, but it would be nice to use preexisting librarie...

Spring MVC Annotations with Global Context context:component-scan?

I have a spring dispatcher servlet with servlet-name "spring-mvc". The spring-mvc-servlet.xml appears as follows: <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" valu...

Using HTTPS with REST in Java

I have a REST server made in Grizzly that uses HTTPS and works wonderfully with Firefox. Here's the code: //Build a new Servlet Adapter. ServletAdapter adapter=new ServletAdapter(); adapter.addInitParameter( "com.sun.jersey.config.property.packages", "My.services"); adapter.addInitParameter( ResourceConfig.PROPERTY_CONTAINER_REQUE...

Java HashMap performance optimization / alternative

I want to create a large HashMap but the put() performance is not good enough. Any ideas? Other data structure suggestions are welcome but I need the lookup feature of a Java Map: map.get(key) In my case I want to create a map with 26 million entries. Using the standard Java HashMap the put rate becomes unbearably slow after 2-3 milli...

ensure runnig finally in spawned Thread, when spawner hits a RuntimeException?

Hi, Ran into a problem. I have a spawned thread that must call its finally block. Assuming code below, is it possible to ensure that finally in the runnable is called? import org.junit.Test; public class ThreadTest { @Test public void testThreadFinally() throws InterruptedException { Runnable r = new Runnable() { ...

"Alert Management System" in Java to support alerts from cross-technology applications

Where Alert Management System roughly fits into this definition: "A system designed to screen events, build profiles associated with the events, and send alerts based upon the profiles and events" So, the current setup is like this: There are multiple applications built in different technologies (Java, .Net, Perl, Python, VB) and they d...