Skip to main content

Posts

Showing posts from March, 2011

replace relative URLs with absolute URLs

Like heading sais, our task is to replace relative URLs in HTML string with absolute URLs. We are using Java and regular expressions to solve this task. First we create a regular expression to find URLs we want to update (href=)("|')([^http].*?)("|') What it does? It tries to match all "href" attributes which are not starting with "http". It groups a match into groups. First part is attribute name with equal sign ("href="), then quotes (both single and double quotes could be used), then value of attribute and then again quotes. Next we have to create Java code to use given reg. expression. String replaceRelativeLinksWithAbsolute(String html, String url) {     Pattern p = Pattern.compile("(href=)(\"|')([^http].*?)(\"|')");     Matcher m = p.matcher(html);     StringBuffer sb = new StringBuffer();     boolean result = m.find();     while (result) {         m.appendReplacement(sb, createReplacement(ur

how to ignore files and folders in subversion?

I always forget how to ignore files and folder if I'm adding subversion support to a project. Why do I need it? For example, I do not want to add log files or customer related content (uploaded files etc.) into repository. It's quite simple. In command line type following command: svn propedit svn:ignore ./path/to/folder It's not end of process. With this command you set up ignore property for given path / folder. It will open a text editor, where you can specify what exactly should be ignored. With a * it will ignore all files and subfolder under specified folder. It is possible to describe multiple patterns, just like that.. *.log *.class tmp_files.* Go ahead and try it out!