We've launched mockup of social media company that we started. Check the following url:
Bless the Broken Road
2 years ago
Blog about my personal life and programming life which includes technologies such as Java, Python, PHP, C++ and many many more.
public String convertToHumanReadableSize(long sizeInBytes) {Download it here: http://dl.dropbox.com/u/1262817/blog/FilesizeConverter.java
final FilesizeConverter fc = new FilesizeConverter(FilesizeConverter.UNIT_BYTES);
return fc.convertToHumanReadable(sizeInBytes);
}
ImageThumbnail > Image > ObjectThatUsesImageImageThumbnail was embedded within Image since I believe it is logically correct for the Image to know about its thumbnail (not ObjectThatUsesImage) and for re-usability reasons.
@Embeddable
public class ImageThumbnail {
private String url;
private Integer height;
private Integer width;
}
@Embeddable
public class Image {
private String url;
private Integer height;
private Integer width;
@Embedded
private ImageThumbnail thumbnail;
}
public class ObjectThatUsesImage {Running the application will give you an error that you are trying to generate a column with duplicate name. In this case, you are trying to generate column names url, width and height for both ImageThumbnail and Thumbnail on the same table. To fix this, you need to override the attributes:
@Embedded
private Image image;
}
public class ObjectThatUsesImage implements Serializable {Using overrides, you can customize the column names with whatever name you want.
@Embedded
@AttributeOverrides({
@AttributeOverride(name="url", column = @Column(name="imageUrl")),
@AttributeOverride(name="width", column = @Column(name="imageWidth")),
@AttributeOverride(name="height", column = @Column(name="imageHeight")),
@AttributeOverride(name="thumbnail.url", column = @Column(name="thumbnailImageUrl")),
@AttributeOverride(name="thumbnail.width", column = @Column(name="thumbnailImageWidth")),
@AttributeOverride(name="thumbnail.height", column = @Column(name="thumbnailImageHeight")),
})
private Image image;
// ...
}
<pluginRepositories>
<pluginRepository>
<id>zt-repo</id>
<name>Zero turnaround repo</name>
<url>http://repos.zeroturnaround.com/maven2</url>
</pluginRepository>
</pluginRepositories>
2. Add the JavaRebel maven plugin. This will automatically generate the rebel.xml file:
<plugin>
<groupId>org.zeroturnaround</groupId>
<artifactId>javarebel-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-rebel-xml</id>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
3. Generate rebel.xml using the following command:
mvn javarebel:generate -4. Download JavaRebel and place the rebel.jar file on your project directory.Drebel.xml.dir=src/main/resources/
mvn jetty:run -noverify -javaagent:jrebel.jar6. Try adding a new method and visiting the same page and updates will immediately take effect without restarting.
public class ItemInCollectionTag extends BodyTagSupport {Taglib Declaration (.tld file)
private static final long serialVersionUID = -3130145552400188745L;
private Collection collection;
private Object item;
@Override
public int doAfterBody() throws JspException {
if(collection == null) {
return SKIP_BODY;
}
final HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
final JspWriter out = pageContext.getOut();
if(collection.contains(item)) {
final BodyContent bodyContent = getBodyContent();
try {
out.print(bodyContent.getString());
}
catch(IOException ioe) {
ioe.printStackTrace();
}
}
return SKIP_BODY;
}
// getters and setters here
}
<?xml version="1.0" encoding="UTF-8"?>Using in JSP
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.2</jspversion>
<shortname>util</shortname>
<info>util tag library</info>
<uri></uri>
<tag>
<name>itemInCollection</name>
<tagclass>com.reyjexter.core.taglib.util.ItemInCollectionTag</tagclass>
<body-content>JSP</body-content>
<info>Check whether an item exist within the collection given</info>
<attribute>
<name>collection</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>item</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
<%@ taglib prefix="util" uri="/WEB-INF/util.tld"%>
<util:itemInCollection collection="${someCollection}" item="${someItem}">prints when true</util:itemInCollection>
Copyright © 2009 Rey Bumalay - Personal Life, Quick Programming Tips and More...
Design by Design Disease for Smashing Magazine | Blogger Templates by Blog and Web