While working on a recent project in GWT, I needed to embed a full HTML document inside an IFRAME. And I didn't want to specify a remote URL for the IFRAME - I actually wanted to shove the HTML content directly into the IFRAME.
Initially I thought it was trivial: create an IFrameElement and call setInnerHTML.
[geshifilter-code lang="java"] IFrameElement iframe = Document.get().createIFrameElement(); iframe.setInnerHTML(htmlContent); [/geshifilter-code]
Unfortunately, that doesn't work. It doesn't cause any errors, but it doesn't actually fill in the iframe. Instead, you have to use native javascript to write into the document object for the iframe:
[geshifilter-code lang="java"] private final native void fillIframe(IFrameElement iframe, String content) /*-{ var doc = iframe.document; if(iframe.contentDocument) doc = iframe.contentDocument; // For NS6 else if(iframe.contentWindow) doc = iframe.contentWindow.document; // For IE5.5 and IE6 // Put the content in the iframe doc.open(); doc.writeln(content); doc.close(); }-*/; [/geshifilter-code]
Voila! However, one of the side effects is that the iframe doesn't include any CSS unless your embedded HTML references a stylesheet. If you want to manually add a reference to a specific stylesheet, you can do that through native javascript as well:
[geshifilter-code lang="java"] private final native void addHeadElement(IFrameElement iframe, String cssUrl) /*-{ setTimeout(function() { var body; if ( iframe.contentDocument ) { // FF iframe.contentDocument.designMode= "On"; iframe.contentDocument.execCommand('styleWithCSS',false,'false'); body= iframe.contentDocument.body; } else if ( iframe.contentWindow ) { // IE body = iframe.contentWindow.document.body; } if (body == null) { return; } body.className = "custom-body-classname"; var head = body.previousSibling; if(head == null) { head = iframe.contentWindow.document.createElement("head"); iframe.contentWindow.document.childNodes[0].insertBefore(head, body); } var fileref = iframe.contentWindow.document.createElement("link"); fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", cssUrl); head.appendChild(fileref); }, 50); }-*/;} [/geshifilter-code]
There's still one more problem. You can't use either of native methods until the IFRAME element has been attached to the DOM. The easiest way around this is to add the IFRAME element to a panel and over the onLoad() method for the panel:
[geshifilter-code lang="java"] final IFrameElement iframe = Document.get().createIFrameElement(); FlowPanel innerBox = new FlowPanel() { @Override protected void onLoad() { super.onLoad(); // Fill the IFrame with the content html fillIframe(iframe, contentHtml); // Add a HEAD element to the IFrame with the appropriate CSS addHeadElement(iframe, cssUrl); } }; innerBox.getElement().appendChild(iframe); [/geshifilter-code]
I got the idea and the important code from an article titled Inject HTML into an IFrame from Software As She's Developed.
I recently started encountering a strange problem with Subversion on one of my machines. In larger commits, I would suddenly get an error:
[geshifilter-code lang="bash"] $ svn ci -m "My commit message." Sending src/Foo.java svn: Commit failed (details follow): svn: File or directory 'src/Foo.java' is out of date; try updating svn: resource out of date; try updating [/geshifilter-code]
Although I was positive the file(s) were up to date, I ran an svn up just to be safe:
[geshifilter-code lang="bash"] $ svn up At revision 10803. [/geshifilter-code]
Nothing changed. If I tried to commit again, I would get the same out of date error. Eventually I figured out that if I delete the folder containing the problematic file, ran svn up to restore the working copy and re-edited (or restored from a backup) the modified file, the problem went away. This suggested an issue with the Subversion metadata, but this blog post from Pageworthy describes a much easier work around:
Delete the all-wcprops file from the .svn metadata folder for the offending file.
In other words, if Subversion complains about src/com/mycompany/Foo.java, then delete src/com/mycompany/.svn/all-wcprops.
OS: Mac 10.6
IDE: Eclipse 20090920-1017
Subversive Team Provider: 0.7.8
Subversive Connectors: 2.2.1
SVNKit 1.3.0: 2.2.1
Subversion: 1.6.6
This website runs on a pair of drives in a RAID-1 configuration, as do several pairs of drives in my home that I use for storing media (music, movies, television, etc.). On all servers, I run software raid in Linux using mdadm. For some reason, I can never remember the simple syntax for checking the status of an array:
[geshifilter-code lang="bash"] $ sudo /sbin/mdadm -QD /dev/md0 /dev/md0: Version : 00.90.03 Creation Time : Fri Jun 19 06:16:37 2009 Raid Level : raid1 Array Size : 104320 (101.89 MiB 106.82 MB) Used Dev Size : 104320 (101.89 MiB 106.82 MB) Raid Devices : 2 Total Devices : 2 Preferred Minor : 0 Persistence : Superblock is persistent Update Time : Wed Sep 16 00:22:58 2009 State : clean Active Devices : 2 Working Devices : 2 Failed Devices : 0 Spare Devices : 0 UUID : b185a678:1789acb9:327678ee:0f02177d Events : 0.14 Number Major Minor RaidDevice State 0 3 1 0 active sync /dev/hda1 1 3 65 1 active sync /dev/hdb1 [/geshifilter-code]
The State line and Working Devices are the most important for me. In this case, they indicate the array is just fine and both drives are working.
A few months back I got a new 12.1" System76 Darter laptop and I finally decided to setup dual monitors on Kubuntu 9.10 (Karmic Koala).What I wanted was to have my laptop LCD on the left at 1280x800 and my ViewSonic LCD panel on the right running at 1680x1050. Apparently I'm old-skool, because I'm used to hacking away at my xorg.conf just to get dual monitor support to work under Linux. Somehow I never knew about xrandr, KRandR, etc.
ThinkWiki has a great article using XRandR (http://www.thinkwiki.org/wiki/Xorg_RandR_1.2) that really helped me out. When I first launched Kubuntu the two screens were mirrored. So, I tried to use KRandR to set the screens side by side. Unfortunately, it seemed to be confused - it saw there were two outputs, but it thought they were the same screen. This is where the ThinkWiki article came in handy.
With the later versions of Xorg, Ubuntu doesn't even include an xorg.conf. Instead of even monkeying around with Xorg, I just used xrandr. There were three key steps:
[geshifilter-code lang="bash"]$ xrandr -q Screen 0: minimum 320 x 200, current 2960 x 1050, maximum 8192 x 8192 VGA1 connected 1680x1050+1280+0 (normal left inverted right x axis y axis) 474mm x 296mm 1680x1050 60.0*+ 1280x1024 75.0 1152x864 75.0 1024x768 75.1 70.1 60.0 832x624 74.6 800x600 72.2 75.0 60.3 56.2 640x480 72.8 75.0 66.7 60.0 720x400 70.1 LVDS1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 261mm x 163mm 1280x800 60.0*+ 1024x768 60.0 800x600 60.3 640x480 59.9 DP1 disconnected (normal left inverted right x axis y axis) [/geshifilter-code]
This shows I have two main outputs connected right now: VGA1 and LVDS1. Under Ubuntu 9.04 (Jaunty), my outputs were labeled VGA and LVDS.
Once we know the name of the outputs, we can disable the secondary output. This is the key step to getting a large virtual desktop working without something like Xinerama. If you don't disable the secondary output, Xorg never seems to be able to successfully distinguish between the two outputs.
[geshifilter-code lang="bash"]$ xrandr --output VGA1 --off[/geshifilter-code]
When we re-enable the outputs we can specify the location of the secondary display, relative to the primary. We can also let xrandr figure out the best resolution for each:
[geshifilter-code lang="bash"]$ xrandr --output LVDS --auto --output VGA --auto --right-of LVDS[/geshifilter-code]
Voila. Finally, if you want to automate this, the ThinkWiki article has a great little script you can use. However, I did have to modify it slightly ... I had to force the VGA1 output off before setting them both to auto. Without that, the secondary screen remained blank.
[geshifilter-code lang="bash"] # If an external monitor is connected, place it with xrandr # External output may be "VGA" or "VGA-0" or "DVI-0" or "TMDS-1" EXTERNAL_OUTPUT="VGA1" INTERNAL_OUTPUT="LVDS1" # EXTERNAL_LOCATION may be one of: left, right, above, or below EXTERNAL_LOCATION="right" case "$EXTERNAL_LOCATION" in left|LEFT) EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT" ;; right|RIGHT) EXTERNAL_LOCATION="--right-of $INTERNAL_OUTPUT" ;; top|TOP|above|ABOVE) EXTERNAL_LOCATION="--above $INTERNAL_OUTPUT" ;; bottom|BOTTOM|below|BELOW) EXTERNAL_LOCATION="--below $INTERNAL_OUTPUT" ;; *) EXTERNAL_LOCATION="--left-of $INTERNAL_OUTPUT" ;; esac xrandr |grep $EXTERNAL_OUTPUT | grep " connected " if [ $? -eq 0 ]; then xrandr --output $EXTERNAL_OUTPUT --off xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION # Alternative command in case of trouble: # (sleep 2; xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --auto $EXTERNAL_LOCATION) & else xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off fi [/geshifilter-code]
Place this /etc/X11/Xsession.d as 45custom_xrandr-settings and it will automatically run.
I found a great article on creating a visualization for audio in Flash on the CommunityMX site. Unfortunately, I'm trying to accomplish with audio streaming over RMTP from a Red5 server and that seems to be causing me problems. No matter what I do, the spectrum data return from SoundMixer.computeSpectrum() is empty (all zeros). Meanwhile, I'm seeing conflicting reports across the web and even conflicting information from Adobe.
In one location, Adobe writes that SoundMixer.computeSpectrum() does not work with RTMP data:
For media loaded from RTMP sources, you cannot use the [geshifilter-code]BitmapData.draw()[/geshifilter-code] and [geshifilter-code]SoundMixer.computeSpectrum() [/geshifilter-code]methods to extract run-time graphics and sound data.1
Then there is the actual documentation for SoundMixer.computeSpectrum():
Note: This method is subject to local file security restrictions and restrictions on cross-domain loading. If you are working with local files or sounds loaded from a server in a different domain than the calling content, you might need to address sandbox restrictions through a cross-domain policy file. For more information, see the Sound class description. In addition, this method cannot be used to extract data from RTMP streams, even when it is called by content that reside in the same domain as the RTMP server.
This method is supported over RTMP in Flash Player 9.0.115.0 and later and in Adobe AIR.2
And finally there's this thread over at the forums for Wowza:
It's official! computeSpectrum does work with Netstream and RTMP served by Wowza
3
Of course, there's no explanation as to how this was actually accomplished using a NetStream/NetConnection and content streamed via RTMP.
Now I'm just horribly confused. Does it work? Or doesn't it? If it's supposed to work, what am I doing wrong?
Footnotes: