java

More than one URIResolver on a TransformerFactory?

I have an XSLT Transformer in Java (actually its Apache FOP rendering to PDF) where I have already set a custom URIResolver (for 'servlet-context:' URIs). Now I need to use another URIResolver in addition (a CatalogResolver for caching DTDs). Do I need to write my own URIResolver now that calls either of the two or is there a better w...

Automatically catching the use of =+ rather than += in Java

I have this horrible habit of typing the below and not catching it until well into testing: int i = 1; int j = 2; i =+ j; //i equals 2, not 3 as intended; assign only, + is unary and works on the j The correct version, of course, would be int i = 1; int j = 2; i += j; //i equals 3, as intended with additive & assignment compound o...

How can I write large output to Process getOutputStream ?

Hi, I am trying to execute a command (eg. ps -ef | grep apache) using ProcessBuilder and Process. The code works as long as the output of 'ps -ef' is small. But if the output is too big, the program hangs. Is there a way to fix this? Here is my code based on [http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html] #### Progra...

Thumbnails

Is there an Api for creating a thumbnail from a JPEG ...

JPA and PostgreSQL Network Address Types

Is there a standard way to define a JPA entity that has columns with PostgreSQL network address data types? Im using OpenJPA ...

Can I pass parameters by reference in Java?

I'd like semantics similar to C#'s ref keyword. ...

Which BDD framework for Java do you use?

What's the best BDD framework to use with Java? Why? What are the pros and cons of each framework? I've found couple of them here, but I'm not sure which one to choose. Does it make sense to use a BDD framework if I already use a mocking library (e.g. Mockito)? ...

Stopping default behavior of events in Swing.

I have the following bit of code in a method called by clicking the send button, or pressing enter in the message text field in a piece of code. // In class ChatWindow private void messageTextAreaKeyPressed(java.awt.event.KeyEvent evt) { // Event handler created by Netbeans GUI designer to call this method. if(evt.getKeyC...

Can I use Scanner class in text file for getting information??

this code is correct?? String note = "text.txt"; FileWriter file = new FileWriter(note); Scanner sc = new Scanner(System.in); System.out.println("Enter your name:"); String name = sc.next(); file.close(); How can I pass this file to the program as a command line argument??? ...

Get current stack trace in Java

Something like Environment.StackTrace in .Net. BTW, Thread.dumpStack() is not what I want - I want to get the stacktrace back, not print it out. ...

How do you create a thumbnail image out of a JPEG in Java?

Can someone please help with some code for creating a thumbnail for a JPEG in Java. I'm new at this, so a step by step explanation would be appreciated. ...

How can I search for a user based on a Certificate in LDAP?

How do I search for a specific user object in LDAP that has an associated x509 certificate? Do I need to encode it in a certain way? It looks like the attribute is userCertificate based on looking at JXplorer. Note: Accessing Active Directory through LDAP ...

When to use @Override in java

Possible Duplicate: When do you use Javas @Override annotation and why? From the javadoc for the @Override annotation: Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, com...

How can I access lazy-loaded fields after the session has closed, using hibernate?

consider this scenario: I have loaded a Parent entity through hibernate Parent contains a collection of Children which is large and lazy loaded The hibernate session is closed after this initial load while the user views the Parent data The user may choose to view the contents of the lazy Children collection I now wish to load that col...

Static method in Java

Looking through some java code and this just does not seem right. To me, it looks like every time you call projects, you will get a new hashmap, so that this statement is always false projects.get(soapFileName) != null Seems like it should have a backing field public static HashMap<String,WsdlProject> projects = new HashMap<String,Ws...

How to make a curve to join two objects editable?

Hi, I'm involved in a project in which we're doing a visual editor (written in Java). Now, I'm trying to make curves that join two different objects that I'm painting in a class that extends JPanel (this class is what I'm using to paint, inside a JFrame, overriding the method paintComponent). I'm in troubles because I'm using the class Q...

RequestDispatcher.forward loop

I am using <url-pattern>/*</url-pattern> to map all the requests to one sevlet,where i do all the authentication work. but I want to skip some static content (like css files).so I tried fowrding them from that sevlet to where the resource file is if(isResourceFile){ RequestDispatcher dispatcher = getServletContext().getRequestDi...

How to obtain test case name in JUnit 4 at runtime?

I want to do some logging while executing my JUnit test. In JUnit 3.x it was always easy to obtain the name of the currently running test case, no matter how the test case was instantiated: public void testFoo() throws Exception() { String testName = this.getName(); // [...] do some stuff } In JUnit 4 things seem to be not so easy...

Method chaining + inheritance don’t play well together? (Java)

This question has been asked in a C++ context but I'm curious about Java. The concerns about virtual methods don't apply (I think), but if you have this situation: abstract class Pet { private String name; public Pet setName(String name) { this.name = name; return this; } } class Cat extends Pet { public Cat catchMi...

Grails: Error using liferay plugin

I'm having this problem with the grails liferay-plugin: localhost_liferay_portlet_WEB_INF_grails_app_views_test_view_gsp: 17: expecting anything but ''\n''; got it anyway @ line 17, column 170. 1 error Here's the gsp: <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <div> <h1>View Page</h1> The map returned by renderV...