krpano 功能化 -- linux 部署測試轉載
<div class="markdown_views"> <!-- flowchart 箭頭圖示 勿刪 --> <svg xmlns="http://www.w3.org/2000/svg" style="display: none;"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path></svg> <p>本文僅供技術交流。 <br> <br></p>
<h4 id="在前面的文章中基於java後端的-krpano-功能化-已經實現在win平臺將krpano功能化這次我將krpano遷移至伺服器ubuntu-1604-server"><strong>在前面的文章中:<a href="http://blog.csdn.net/change_on/article/details/77373644" rel="nofollow" target="_blank">基於java後端的 krpano 功能化</a> 已經實現在win平臺將krpano功能化,這次我將krpano遷移至伺服器:ubuntu 16.04 server。</strong></h4>
<p><br></p>
<h4 id="以win的經驗為基礎這裡只需解決2個問題"><strong>以win的經驗為基礎,這裡只需解決2個問題:</strong></h4>
<ul> <li><p><strong>linux上krpano的安裝與註冊</strong></p></li> <li><p><strong>在linux上,用java執行krpano命令</strong> <br> <br></p></li> </ul>
<h4 id="1linux上krpano的安裝與註冊"><strong>(1)linux上krpano的安裝與註冊</strong></h4>
<p>我以krpano-1.19-pr10為例,不必無官網下載,在這裡下: <a href="http://pan.baidu.com/s/1bppkEbd" rel="nofollow" target="_blank">http://pan.baidu.com/s/1bppkEbd</a> 上傳到伺服器解壓就可以了(裡面有註冊碼)。可是,在生成全景圖時,會有水印,怎麼解決呢?在解壓的資料夾裡,有個叫Serial.txt檔案,是一個註冊碼。只需要在伺服器註冊這個註冊碼就行了,每個使用者都註冊一遍。</p>
<p>我先把krpano-1.19-pr10上傳到/opt目錄下,unrar 解壓,然後執行krpanotools register命令註冊機器:</p>
<pre class="prettyprint" name="code"><code class="hljs ruby has-numbering">root<span class="hljs-variable">@S189919</span><span class="hljs-symbol">:/opt/krpano-</span><span class="hljs-number">1.19</span>-pr1<span class="hljs-number">0</span><span class="hljs-comment"># /opt/krpano-1.19-pr10/krpanotools register FXsqTqaGNSZER5dSETEm+VzQEh9sWSa5DZMFsSmMxYV9GcXs8W3R8A/mWXrGNUceXvrihmh28hfRF1ivrW0HMzEychPvNiD8B/4/ZzDaUE9Rh6Ig22aKJGDbja1/kYIqmc/VKfItRE2RTSOIbIroxOtsz626NIpxWksAAifwhpNwuPXqDQpz2sRUMBzoPqZktpkItoSenN2mKd8Klfx7pOuB6CIK3e1CDXgyndqOt2mWybLZcU/wfJVAecfxk15ghiqrzaDsbqrdABDowg==</span>
<span class="hljs-constant">Code</span> registered. root<span class="hljs-variable">@S189919</span><span class="hljs-symbol">:/opt/krpano-</span><span class="hljs-number">1.19</span>-pr1<span class="hljs-number">0</span><span class="hljs-comment"># exit</span> exit wen<span class="hljs-variable">@S189919</span><span class="hljs-symbol">:~</span><span class="hljs-variable">$ </span>cd /opt/krpano-<span class="hljs-number">1.19</span>-pr1<span class="hljs-number">0</span>/ wen<span class="hljs-variable">@S189919</span><span class="hljs-symbol">:/opt/krpano-</span><span class="hljs-number">1.19</span>-pr1<span class="hljs-number">0</span><span class="hljs-variable">$ </span>/opt/krpano-<span class="hljs-number">1.19</span>-pr1<span class="hljs-number">0</span>/krpanotools register <span class="hljs-constant">FXsqTqaGNSZER5dSETEm</span>+<span class="hljs-constant">VzQEh9sWSa5DZMFsSmMxYV9GcXs8W3R8A</span>/mWXrGNUceXvrihmh28hfRF1ivrW0HMzEychPvNiD8B/<span class="hljs-number">4</span>/<span class="hljs-constant">ZzDaUE9Rh6Ig22aKJGDbja1</span>/kYIqmc/<span class="hljs-constant">VKfItRE2RTSOIbIroxOtsz626NIpxWksAAifwhpNwuPXqDQpz2sRUMBzoPqZktpkItoSenN2mKd8Klfx7pOuB6CIK3e1CDXgyndqOt2mWybLZcU</span>/wfJVAecfxk15ghiqrzaDsbqrdABDowg==
<span class="hljs-constant">Code</span> registered. </code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li></ul></pre>
<h4 id="這樣就會在使用者的下生成一個krpanolicense檔案"><strong>這樣,就會在使用者的~/下生成一個.krpanolicense檔案</strong></h4>
<p><br></p>
<p><img src="https://img-blog.csdn.net/20170907111150471?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hhbmdlX29u/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="這裡寫圖片描述" title=""></p>
<p><br></p>
<h4 id="有了krpanolicense就不用擔心會有水印和版權資訊了"><strong>有了krpanolicense,就不用擔心會有水印和版權資訊了。</strong></h4>
<p><br></p>
<h4 id="2在linux上用java執行krpano命令"><strong>(2)在linux上,用java執行krpano命令</strong></h4>
<p>因為java本身是跨平臺的第一語言,所以選擇java,就等於成功了一半。但在linux上,用java的runtime.exec與在win上的呼叫命令不同,檔案路徑也不同,這是最需要注意的! </p>
<p>以/opt/test/test.jpg的圖片為例</p>
<p>krpano在linux執行的命令是:</p>
<pre class="prettyprint" name="code"><code class="hljs lasso has-numbering"> /opt/krpano<span class="hljs-subst">-</span><span class="hljs-number">1.19</span><span class="hljs-attribute">-pr10</span>/krpanotools makepano <span class="hljs-attribute">-config</span><span class="hljs-subst">=</span>templates/vtour<span class="hljs-attribute">-normal</span><span class="hljs-built_in">.</span>config /opt/test/test<span class="hljs-built_in">.</span>jpg</code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
<p>而win是:</p>
<pre class="prettyprint" name="code"><code class="hljs tex has-numbering">cmd /c start f:<span class="hljs-command">\\</span>krpano<span class="hljs-command">\\</span>krpano-1.19-pr10-postable<span class="hljs-command">\\</span>krpanotools32.exe makepano -config=<span class="hljs-command">\\</span>templates<span class="hljs-command">\\</span>vtour-normal.config f:<span class="hljs-command">\\</span>test<span class="hljs-command">\\</span>test.jpg</code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li></ul></pre>
<p><strong>linux的檔案目錄是”/ “,win是”\\”。</strong></p>
<p>這是完整的krpano工具類:CmdBat</p>
<pre class="prettyprint" name="code"><code class="hljs java has-numbering"><span class="hljs-keyword">package</span> com.xforce.krpano.util;
<span class="hljs-keyword">import</span> java.io.BufferedReader; <span class="hljs-keyword">import</span> java.io.File; <span class="hljs-keyword">import</span> java.io.FileInputStream; <span class="hljs-keyword">import</span> java.io.FileOutputStream; <span class="hljs-keyword">import</span> java.io.IOException; <span class="hljs-keyword">import</span> java.io.InputStream; <span class="hljs-keyword">import</span> java.io.InputStreamReader;
<span class="hljs-keyword">import</span> javax.xml.parsers.DocumentBuilder; <span class="hljs-keyword">import</span> javax.xml.parsers.DocumentBuilderFactory; <span class="hljs-keyword">import</span> javax.xml.parsers.ParserConfigurationException; <span class="hljs-keyword">import</span> javax.xml.transform.OutputKeys; <span class="hljs-keyword">import</span> javax.xml.transform.Transformer; <span class="hljs-keyword">import</span> javax.xml.transform.TransformerException; <span class="hljs-keyword">import</span> javax.xml.transform.TransformerFactory; <span class="hljs-keyword">import</span> javax.xml.transform.dom.DOMSource; <span class="hljs-keyword">import</span> javax.xml.transform.stream.StreamResult;
<span class="hljs-keyword">import</span> org.w3c.dom.Document; <span class="hljs-keyword">import</span> org.w3c.dom.Element; <span class="hljs-keyword">import</span> org.w3c.dom.Node; <span class="hljs-keyword">import</span> org.w3c.dom.NodeList; <span class="hljs-keyword">import</span> org.xml.sax.SAXException;
<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CmdBat</span> {</span>
<span class="hljs-comment">/*public static void main(String[] args) { String dpath = "D:\\apache-tomcat-8.0.33\\webapps\\krpano\\vshow"; String file = "353"; String[] fn1 = {}; String[] fn2 = {}; String title = "yyyyyyyy"; String temppath = "f:\\temp-room\\"; String music = "vshow/backgroundmusic/default.mp3"; try { setKrpano(dpath, file,temppath, fn1, fn2, title,music); } catch (InterruptedException e) { e.printStackTrace(); System.out.println("上傳失敗"); }
}*/</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">setKrpano</span>(<span class="hljs-keyword">final</span> String dpath, <span class="hljs-keyword">final</span> String file,<span class="hljs-keyword">final</span> String temppath, <span class="hljs-keyword">final</span> String[] fn1, <span class="hljs-keyword">final</span> String[] fn2, <span class="hljs-keyword">final</span> String title,<span class="hljs-keyword">final</span> String music) <span class="hljs-keyword">throws</span> InterruptedException { String path = temppath + file; File targetFile = <span class="hljs-keyword">new</span> File(path); <span class="hljs-keyword">if</span>(!targetFile.exists()){ targetFile.mkdirs(); } String ex = <span class="hljs-string">"/opt/krpano-1.19-pr10/krpanotools makepano -config=templates/vtour-normal.config "</span> + path + <span class="hljs-string">"/*.jpg"</span>; Runtime runtime = Runtime.getRuntime(); String[] cmd = <span class="hljs-keyword">new</span> String[]{<span class="hljs-string">"/bin/sh"</span>,<span class="hljs-string">"-c"</span>, ex }; <span class="hljs-keyword">boolean</span> b = <span class="hljs-keyword">true</span>; Process p = <span class="hljs-keyword">null</span>; <span class="hljs-keyword">try</span> { p = runtime.exec(cmd); } <span class="hljs-keyword">catch</span> (Exception e) { b = <span class="hljs-keyword">false</span>; } <span class="hljs-keyword">if</span> (b) { <span class="hljs-keyword">final</span> InputStream is1 = p.getInputStream(); <span class="hljs-keyword">final</span> InputStream is2 = p.getErrorStream(); <span class="hljs-keyword">new</span> Thread() { <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span>() { BufferedReader br1 = <span class="hljs-keyword">new</span> BufferedReader( <span class="hljs-keyword">new</span> InputStreamReader(is1)); <span class="hljs-keyword">try</span> { String line1 = <span class="hljs-keyword">null</span>; <span class="hljs-keyword">while</span> ((line1 = br1.readLine()) != <span class="hljs-keyword">null</span>) { <span class="hljs-keyword">if</span> (line1 != <span class="hljs-keyword">null</span>) { System.out.println(<span class="hljs-string">"=AA==========line1======"</span> + line1); } } } <span class="hljs-keyword">catch</span> (IOException e) { e.printStackTrace(); } <span class="hljs-keyword">finally</span> { <span class="hljs-keyword">try</span> { is1.close(); <span class="hljs-comment">// 執行檔案複製</span> File f = <span class="hljs-keyword">new</span> File(dpath + <span class="hljs-string">"/"</span> + file); f.mkdirs();<span class="hljs-comment">// 建立目錄</span> <span class="hljs-comment">// 複製檔案</span> <span class="hljs-keyword">boolean</span> b1 = copyFile(temppath + file + <span class="hljs-string">"/vtour/tour.js"</span>, dpath + <span class="hljs-string">"/"</span> + file + <span class="hljs-string">"/tour.js"</span>); <span class="hljs-keyword">if</span> (b1) { <span class="hljs-keyword">boolean</span> b2 = copyFile(temppath + file + <span class="hljs-string">"/vtour/tour.swf"</span>, dpath + <span class="hljs-string">"/"</span> + file + <span class="hljs-string">"/tour.swf"</span>); <span class="hljs-keyword">if</span> (b2) { <span class="hljs-keyword">boolean</span> b3 = copyFile(temppath + file + <span class="hljs-string">"/vtour/tour.xml"</span>, dpath + <span class="hljs-string">"/"</span> + file + <span class="hljs-string">"/tour.xml"</span>); <span class="hljs-keyword">if</span> (b3) { <span class="hljs-comment">// 複製資料夾</span> <span class="hljs-keyword">boolean</span> b4 = copyFolder( temppath + file + <span class="hljs-string">"/vtour/panos"</span>, dpath + <span class="hljs-string">"/"</span> + file + <span class="hljs-string">"/panos"</span>); <span class="hljs-keyword">if</span> (b4) { <span class="hljs-comment">// 刪除臨時生成檔案</span> delFolder(temppath + file); <span class="hljs-comment">// 修改krpano檔案內容</span> String xmlPath = dpath + <span class="hljs-string">"/"</span> + file + <span class="hljs-string">"/tour.xml"</span>; File xmlFile = <span class="hljs-keyword">new</span> File(xmlPath); DocumentBuilderFactory dbFactory = DocumentBuilderFactory .newInstance(); DocumentBuilder dBuilder; <span class="hljs-keyword">try</span> { dBuilder = dbFactory .newDocumentBuilder(); Document doc = dBuilder .parse(xmlFile); doc.getDocumentElement() .normalize(); <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < fn1.length; i++) { updateAttributeValue(doc, fn1[i], fn2[i]); }
<span class="hljs-comment">// update Element value</span> updateElementValue(doc, title);
<span class="hljs-comment">// delete element</span> deleteElement(doc);
<span class="hljs-comment">// add new element</span> addElement(doc);
updateAttributeColorValue(doc, <span class="hljs-string">"0x000000"</span>); addMusicElement(doc,music); <span class="hljs-comment">// write the updated document to</span> <span class="hljs-comment">// file or console</span> doc.getDocumentElement() .normalize(); TransformerFactory transformerFactory = TransformerFactory .newInstance(); Transformer transformer = transformerFactory .newTransformer(); DOMSource source = <span class="hljs-keyword">new</span> DOMSource( doc); StreamResult result = <span class="hljs-keyword">new</span> StreamResult( <span class="hljs-keyword">new</span> File(xmlPath)); transformer.setOutputProperty( OutputKeys.INDENT, <span class="hljs-string">"yes"</span>); transformer.transform(source, result); <span class="hljs-comment">//生成成功</span> <span class="hljs-comment">/*System.out .println("XML file updated successfully");*/</span>
} <span class="hljs-keyword">catch</span> (Exception e1) { e1.printStackTrace(); <span class="hljs-comment">//生成失敗</span> }
} } } } } <span class="hljs-keyword">catch</span> (IOException e) { e.printStackTrace(); } } } }.start(); <span class="hljs-keyword">new</span> Thread() { <span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">run</span>() { BufferedReader br2 = <span class="hljs-keyword">new</span> BufferedReader( <span class="hljs-keyword">new</span> InputStreamReader(is2)); <span class="hljs-keyword">try</span> { String line2 = <span class="hljs-keyword">null</span>; <span class="hljs-keyword">while</span> ((line2 = br2.readLine()) != <span class="hljs-keyword">null</span>) { <span class="hljs-keyword">if</span> (line2 != <span class="hljs-keyword">null</span>) { System.out.println(<span class="hljs-string">"=AA==========line2======"</span> + line2); } } } <span class="hljs-keyword">catch</span> (IOException e) { e.printStackTrace(); } <span class="hljs-keyword">finally</span> { <span class="hljs-keyword">try</span> { is2.close(); } <span class="hljs-keyword">catch</span> (IOException e) { e.printStackTrace(); } } } }.start(); p.waitFor(); p.destroy(); } <span class="hljs-keyword">else</span> { System.out.println(<span class="hljs-string">"上傳失敗"</span>); }
}
<span class="hljs-javadoc">/** * 複製單個檔案 * *<span class="hljs-javadoctag"> @param</span> oldPath * String 原檔案路徑 如:c:/fqf.txt *<span class="hljs-javadoctag"> @param</span> newPath * String 複製後路徑 如:f:/fqf.txt *<span class="hljs-javadoctag"> @return</span> boolean */</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">copyFile</span>(String oldPath, String newPath) { <span class="hljs-keyword">try</span> { <span class="hljs-keyword">int</span> bytesum = <span class="hljs-number">0</span>; <span class="hljs-keyword">int</span> byteread = <span class="hljs-number">0</span>; File oldfile = <span class="hljs-keyword">new</span> File(oldPath); <span class="hljs-keyword">if</span> (oldfile.exists()) { <span class="hljs-comment">// 檔案存在時</span> InputStream inStream = <span class="hljs-keyword">new</span> FileInputStream(oldPath); <span class="hljs-comment">// 讀入原檔案</span> FileOutputStream fs = <span class="hljs-keyword">new</span> FileOutputStream(newPath); <span class="hljs-keyword">byte</span>[] buffer = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1444</span>]; <span class="hljs-keyword">int</span> length; <span class="hljs-keyword">while</span> ((byteread = inStream.read(buffer)) != -<span class="hljs-number">1</span>) { bytesum += byteread; <span class="hljs-comment">// 位元組數 檔案大小</span> <span class="hljs-comment">// System.out.println(bytesum);</span> fs.write(buffer, <span class="hljs-number">0</span>, byteread); } inStream.close(); } } <span class="hljs-keyword">catch</span> (Exception e) { <span class="hljs-comment">// System.out.println("複製單個檔案操作出錯");</span> e.printStackTrace(); <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>; } <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>; }
<span class="hljs-javadoc">/** * 複製整個資料夾內容 * *<span class="hljs-javadoctag"> @param</span> oldPath * String 原檔案路徑 如:c:/fqf *<span class="hljs-javadoctag"> @param</span> newPath * String 複製後路徑 如:f:/fqf/ff *<span class="hljs-javadoctag"> @return</span> boolean */</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">copyFolder</span>(String oldPath, String newPath) { <span class="hljs-keyword">try</span> { (<span class="hljs-keyword">new</span> File(newPath)).mkdirs(); <span class="hljs-comment">// 如果資料夾不存在 則建立新資料夾</span> File a = <span class="hljs-keyword">new</span> File(oldPath); String[] file = a.list(); File temp = <span class="hljs-keyword">null</span>; <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < file.length; i++) { <span class="hljs-keyword">if</span> (oldPath.endsWith(File.separator)) { temp = <span class="hljs-keyword">new</span> File(oldPath + file[i]); } <span class="hljs-keyword">else</span> { temp = <span class="hljs-keyword">new</span> File(oldPath + File.separator + file[i]); }
<span class="hljs-keyword">if</span> (temp.isFile()) { FileInputStream input = <span class="hljs-keyword">new</span> FileInputStream(temp); FileOutputStream output = <span class="hljs-keyword">new</span> FileOutputStream(newPath + <span class="hljs-string">"/"</span> + (temp.getName()).toString()); <span class="hljs-keyword">byte</span>[] b = <span class="hljs-keyword">new</span> <span class="hljs-keyword">byte</span>[<span class="hljs-number">1024</span> * <span class="hljs-number">5</span>]; <span class="hljs-keyword">int</span> len; <span class="hljs-keyword">while</span> ((len = input.read(b)) != -<span class="hljs-number">1</span>) { output.write(b, <span class="hljs-number">0</span>, len); } output.flush(); output.close(); input.close(); } <span class="hljs-keyword">if</span> (temp.isDirectory()) {<span class="hljs-comment">// 如果是子資料夾</span> copyFolder(oldPath + <span class="hljs-string">"/"</span> + file[i], newPath + <span class="hljs-string">"/"</span> + file[i]); } } } <span class="hljs-keyword">catch</span> (Exception e) { <span class="hljs-comment">// System.out.println("複製整個資料夾內容操作出錯");</span> e.printStackTrace(); <span class="hljs-keyword">return</span> <span class="hljs-keyword">false</span>; } <span class="hljs-keyword">return</span> <span class="hljs-keyword">true</span>; }
<span class="hljs-comment">// 刪除資料夾</span> <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">delFolder</span>(String folderPath) { <span class="hljs-keyword">try</span> { delAllFile(folderPath); <span class="hljs-comment">// 刪除完裡面所有內容</span> String filePath = folderPath; filePath = filePath.toString(); java.io.File myFilePath = <span class="hljs-keyword">new</span> java.io.File(filePath); myFilePath.delete(); <span class="hljs-comment">// 刪除空資料夾</span> } <span class="hljs-keyword">catch</span> (Exception e) { e.printStackTrace(); } }
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">boolean</span> <span class="hljs-title">delAllFile</span>(String path) { <span class="hljs-keyword">boolean</span> flag = <span class="hljs-keyword">false</span>; File file = <span class="hljs-keyword">new</span> File(path); <span class="hljs-keyword">if</span> (!file.exists()) { <span class="hljs-keyword">return</span> flag; } <span class="hljs-keyword">if</span> (!file.isDirectory()) { <span class="hljs-keyword">return</span> flag; } String[] tempList = file.list(); File temp = <span class="hljs-keyword">null</span>; <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < tempList.length; i++) { <span class="hljs-keyword">if</span> (path.endsWith(File.separator)) { temp = <span class="hljs-keyword">new</span> File(path + tempList[i]); } <span class="hljs-keyword">else</span> { temp = <span class="hljs-keyword">new</span> File(path + File.separator + tempList[i]); } <span class="hljs-keyword">if</span> (temp.isFile()) { temp.delete(); } <span class="hljs-keyword">if</span> (temp.isDirectory()) { delAllFile(path + <span class="hljs-string">"/"</span> + tempList[i]);<span class="hljs-comment">// 先刪除資料夾裡面的檔案</span> delFolder(path + <span class="hljs-string">"/"</span> + tempList[i]);<span class="hljs-comment">// 再刪除空資料夾</span> flag = <span class="hljs-keyword">true</span>; } } <span class="hljs-keyword">return</span> flag; }
<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">addElement</span>(Document doc) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"krpano"</span>); Element emp = <span class="hljs-keyword">null</span>;
<span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); Element vtourskin = doc.createElement(<span class="hljs-string">"include"</span>); vtourskin.setAttribute(<span class="hljs-string">"url"</span>, <span class="hljs-string">"../skin/vtourskin.xml"</span>); emp.appendChild(vtourskin); Element skinselect = doc.createElement(<span class="hljs-string">"include"</span>); skinselect.setAttribute(<span class="hljs-string">"url"</span>, <span class="hljs-string">"../skinselect.xml"</span>); emp.appendChild(skinselect); } } <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">addMusicElement</span>(Document doc,String music) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"krpano"</span>); Element emp = <span class="hljs-keyword">null</span>;
<span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); Element musicEl = doc.createElement(<span class="hljs-string">"action"</span>); musicEl.setAttribute(<span class="hljs-string">"name"</span>, <span class="hljs-string">"bgsnd_action"</span>); musicEl.setAttribute(<span class="hljs-string">"autorun"</span>, <span class="hljs-string">"onstart"</span>); musicEl.appendChild(doc.createTextNode(<span class="hljs-string">"playsound(bgsnd, '"</span>+music+<span class="hljs-string">"', 0);"</span>)); emp.appendChild(musicEl); } } <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">deleteElement</span>(Document doc) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"krpano"</span>); Element emp = <span class="hljs-keyword">null</span>; <span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); Node genderNode = emp.getElementsByTagName(<span class="hljs-string">"include"</span>).item(<span class="hljs-number">0</span>); emp.removeChild(genderNode); }
}
<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">updateElementValue</span>(Document doc, String title) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"krpano"</span>); Element emp = <span class="hljs-keyword">null</span>; <span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); emp.setAttribute(<span class="hljs-string">"title"</span>, title); } }
<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">updateAttributeValue</span>(Document doc, String oldname, String newname) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"scene"</span>); Element emp = <span class="hljs-keyword">null</span>; <span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); <span class="hljs-keyword">if</span> (emp.getAttribute(<span class="hljs-string">"title"</span>).equals(oldname)) { emp.setAttribute(<span class="hljs-string">"title"</span>, newname); <span class="hljs-keyword">break</span>; } } }
<span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">updateAttributeColorValue</span>(Document doc, String newname) { NodeList employees = doc.getElementsByTagName(<span class="hljs-string">"skin_settings"</span>); Element emp = <span class="hljs-keyword">null</span>; <span class="hljs-comment">// loop for each employee</span> <span class="hljs-keyword">for</span> (<span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; i < employees.getLength(); i++) { emp = (Element) employees.item(i); emp.setAttribute(<span class="hljs-string">"design_bgcolor"</span>, newname); emp.setAttribute(<span class="hljs-string">"design_bgalpha"</span>, <span class="hljs-string">"0.8"</span>); } } }</code><ul class="pre-numbering" style=""><li style="color: rgb(153, 153, 153);">1</li><li style="color: rgb(153, 153, 153);">2</li><li style="color: rgb(153, 153, 153);">3</li><li style="color: rgb(153, 153, 153);">4</li><li style="color: rgb(153, 153, 153);">5</li><li style="color: rgb(153, 153, 153);">6</li><li style="color: rgb(153, 153, 153);">7</li><li style="color: rgb(153, 153, 153);">8</li><li style="color: rgb(153, 153, 153);">9</li><li style="color: rgb(153, 153, 153);">10</li><li style="color: rgb(153, 153, 153);">11</li><li style="color: rgb(153, 153, 153);">12</li><li style="color: rgb(153, 153, 153);">13</li><li style="color: rgb(153, 153, 153);">14</li><li style="color: rgb(153, 153, 153);">15</li><li style="color: rgb(153, 153, 153);">16</li><li style="color: rgb(153, 153, 153);">17</li><li style="color: rgb(153, 153, 153);">18</li><li style="color: rgb(153, 153, 153);">19</li><li style="color: rgb(153, 153, 153);">20</li><li style="color: rgb(153, 153, 153);">21</li><li style="color: rgb(153, 153, 153);">22</li><li style="color: rgb(153, 153, 153);">23</li><li style="color: rgb(153, 153, 153);">24</li><li style="color: rgb(153, 153, 153);">25</li><li style="color: rgb(153, 153, 153);">26</li><li style="color: rgb(153, 153, 153);">27</li><li style="color: rgb(153, 153, 153);">28</li><li style="color: rgb(153, 153, 153);">29</li><li style="color: rgb(153, 153, 153);">30</li><li style="color: rgb(153, 153, 153);">31</li><li style="color: rgb(153, 153, 153);">32</li><li style="color: rgb(153, 153, 153);">33</li><li style="color: rgb(153, 153, 153);">34</li><li style="color: rgb(153, 153, 153);">35</li><li style="color: rgb(153, 153, 153);">36</li><li style="color: rgb(153, 153, 153);">37</li><li style="color: rgb(153, 153, 153);">38</li><li style="color: rgb(153, 153, 153);">39</li><li style="color: rgb(153, 153, 153);">40</li><li style="color: rgb(153, 153, 153);">41</li><li style="color: rgb(153, 153, 153);">42</li><li style="color: rgb(153, 153, 153);">43</li><li style="color: rgb(153, 153, 153);">44</li><li style="color: rgb(153, 153, 153);">45</li><li style="color: rgb(153, 153, 153);">46</li><li style="color: rgb(153, 153, 153);">47</li><li style="color: rgb(153, 153, 153);">48</li><li style="color: rgb(153, 153, 153);">49</li><li style="color: rgb(153, 153, 153);">50</li><li style="color: rgb(153, 153, 153);">51</li><li style="color: rgb(153, 153, 153);">52</li><li style="color: rgb(153, 153, 153);">53</li><li style="color: rgb(153, 153, 153);">54</li><li style="color: rgb(153, 153, 153);">55</li><li style="color: rgb(153, 153, 153);">56</li><li style="color: rgb(153, 153, 153);">57</li><li style="color: rgb(153, 153, 153);">58</li><li style="color: rgb(153, 153, 153);">59</li><li style="color: rgb(153, 153, 153);">60</li><li style="color: rgb(153, 153, 153);">61</li><li style="color: rgb(153, 153, 153);">62</li><li style="color: rgb(153, 153, 153);">63</li><li style="color: rgb(153, 153, 153);">64</li><li style="color: rgb(153, 153, 153);">65</li><li style="color: rgb(153, 153, 153);">66</li><li style="color: rgb(153, 153, 153);">67</li><li style="color: rgb(153, 153, 153);">68</li><li style="color: rgb(153, 153, 153);">69</li><li style="color: rgb(153, 153, 153);">70</li><li style="color: rgb(153, 153, 153);">71</li><li style="color: rgb(153, 153, 153);">72</li><li style="color: rgb(153, 153, 153);">73</li><li style="color: rgb(153, 153, 153);">74</li><li style="color: rgb(153, 153, 153);">75</li><li style="color: rgb(153, 153, 153);">76</li><li style="color: rgb(153, 153, 153);">77</li><li style="color: rgb(153, 153, 153);">78</li><li style="color: rgb(153, 153, 153);">79</li><li style="color: rgb(153, 153, 153);">80</li><li style="color: rgb(153, 153, 153);">81</li><li style="color: rgb(153, 153, 153);">82</li><li style="color: rgb(153, 153, 153);">83</li><li style="color: rgb(153, 153, 153);">84</li><li style="color: rgb(153, 153, 153);">85</li><li style="color: rgb(153, 153, 153);">86</li><li style="color: rgb(153, 153, 153);">87</li><li style="color: rgb(153, 153, 153);">88</li><li style="color: rgb(153, 153, 153);">89</li><li style="color: rgb(153, 153, 153);">90</li><li style="color: rgb(153, 153, 153);">91</li><li style="color: rgb(153, 153, 153);">92</li><li style="color: rgb(153, 153, 153);">93</li><li style="color: rgb(153, 153, 153);">94</li><li style="color: rgb(153, 153, 153);">95</li><li style="color: rgb(153, 153, 153);">96</li><li style="color: rgb(153, 153, 153);">97</li><li style="color: rgb(153, 153, 153);">98</li><li style="color: rgb(153, 153, 153);">99</li><li style="color: rgb(153, 153, 153);">100</li><li style="color: rgb(153, 153, 153);">101</li><li style="color: rgb(153, 153, 153);">102</li><li style="color: rgb(153, 153, 153);">103</li><li style="color: rgb(153, 153, 153);">104</li><li style="color: rgb(153, 153, 153);">105</li><li style="color: rgb(153, 153, 153);">106</li><li style="color: rgb(153, 153, 153);">107</li><li style="color: rgb(153, 153, 153);">108</li><li style="color: rgb(153, 153, 153);">109</li><li style="color: rgb(153, 153, 153);">110</li><li style="color: rgb(153, 153, 153);">111</li><li style="color: rgb(153, 153, 153);">112</li><li style="color: rgb(153, 153, 153);">113</li><li style="color: rgb(153, 153, 153);">114</li><li style="color: rgb(153, 153, 153);">115</li><li style="color: rgb(153, 153, 153);">116</li><li style="color: rgb(153, 153, 153);">117</li><li style="color: rgb(153, 153, 153);">118</li><li style="color: rgb(153, 153, 153);">119</li><li style="color: rgb(153, 153, 153);">120</li><li style="color: rgb(153, 153, 153);">121</li><li style="color: rgb(153, 153, 153);">122</li><li style="color: rgb(153, 153, 153);">123</li><li style="color: rgb(153, 153, 153);">124</li><li style="color: rgb(153, 153, 153);">125</li><li style="color: rgb(153, 153, 153);">126</li><li style="color: rgb(153, 153, 153);">127</li><li style="color: rgb(153, 153, 153);">128</li><li style="color: rgb(153, 153, 153);">129</li><li style="color: rgb(153, 153, 153);">130</li><li style="color: rgb(153, 153, 153);">131</li><li style="color: rgb(153, 153, 153);">132</li><li style="color: rgb(153, 153, 153);">133</li><li style="color: rgb(153, 153, 153);">134</li><li style="color: rgb(153, 153, 153);">135</li><li style="color: rgb(153, 153, 153);">136</li><li style="color: rgb(153, 153, 153);">137</li><li style="color: rgb(153, 153, 153);">138</li><li style="color: rgb(153, 153, 153);">139</li><li style="color: rgb(153, 153, 153);">140</li><li style="color: rgb(153, 153, 153);">141</li><li style="color: rgb(153, 153, 153);">142</li><li style="color: rgb(153, 153, 153);">143</li><li style="color: rgb(153, 153, 153);">144</li><li style="color: rgb(153, 153, 153);">145</li><li style="color: rgb(153, 153, 153);">146</li><li style="color: rgb(153, 153, 153);">147</li><li style="color: rgb(153, 153, 153);">148</li><li style="color: rgb(153, 153, 153);">149</li><li style="color: rgb(153, 153, 153);">150</li><li style="color: rgb(153, 153, 153);">151</li><li style="color: rgb(153, 153, 153);">152</li><li style="color: rgb(153, 153, 153);">153</li><li style="color: rgb(153, 153, 153);">154</li><li style="color: rgb(153, 153, 153);">155</li><li style="color: rgb(153, 153, 153);">156</li><li style="color: rgb(153, 153, 153);">157</li><li style="color: rgb(153, 153, 153);">158</li><li style="color: rgb(153, 153, 153);">159</li><li style="color: rgb(153, 153, 153);">160</li><li style="color: rgb(153, 153, 153);">161</li><li style="color: rgb(153, 153, 153);">162</li><li style="color: rgb(153, 153, 153);">163</li><li style="color: rgb(153, 153, 153);">164</li><li style="color: rgb(153, 153, 153);">165</li><li style="color: rgb(153, 153, 153);">166</li><li style="color: rgb(153, 153, 153);">167</li><li style="color: rgb(153, 153, 153);">168</li><li style="color: rgb(153, 153, 153);">169</li><li style="color: rgb(153, 153, 153);">170</li><li style="color: rgb(153, 153, 153);">171</li><li style="color: rgb(153, 153, 153);">172</li><li style="color: rgb(153, 153, 153);">173</li><li style="color: rgb(153, 153, 153);">174</li><li style="color: rgb(153, 153, 153);">175</li><li style="color: rgb(153, 153, 153);">176</li><li style="color: rgb(153, 153, 153);">177</li><li style="color: rgb(153, 153, 153);">178</li><li style="color: rgb(153, 153, 153);">179</li><li style="color: rgb(153, 153, 153);">180</li><li style="color: rgb(153, 153, 153);">181</li><li style="color: rgb(153, 153, 153);">182</li><li style="color: rgb(153, 153, 153);">183</li><li style="color: rgb(153, 153, 153);">184</li><li style="color: rgb(153, 153, 153);">185</li><li style="color: rgb(153, 153, 153);">186</li><li style="color: rgb(153, 153, 153);">187</li><li style="color: rgb(153, 153, 153);">188</li><li style="color: rgb(153, 153, 153);">189</li><li style="color: rgb(153, 153, 153);">190</li><li style="color: rgb(153, 153, 153);">191</li><li style="color: rgb(153, 153, 153);">192</li><li style="color: rgb(153, 153, 153);">193</li><li style="color: rgb(153, 153, 153);">194</li><li style="color: rgb(153, 153, 153);">195</li><li style="color: rgb(153, 153, 153);">196</li><li style="color: rgb(153, 153, 153);">197</li><li style="color: rgb(153, 153, 153);">198</li><li style="color: rgb(153, 153, 153);">199</li><li style="color: rgb(153, 153, 153);">200</li><li style="color: rgb(153, 153, 153);">201</li><li style="color: rgb(153, 153, 153);">202</li><li style="color: rgb(153, 153, 153);">203</li><li style="color: rgb(153, 153, 153);">204</li><li style="color: rgb(153, 153, 153);">205</li><li style="color: rgb(153, 153, 153);">206</li><li style="color: rgb(153, 153, 153);">207</li><li style="color: rgb(153, 153, 153);">208</li><li style="color: rgb(153, 153, 153);">209</li><li style="color: rgb(153, 153, 153);">210</li><li style="color: rgb(153, 153, 153);">211</li><li style="color: rgb(153, 153, 153);">212</li><li style="color: rgb(153, 153, 153);">213</li><li style="color: rgb(153, 153, 153);">214</li><li style="color: rgb(153, 153, 153);">215</li><li style="color: rgb(153, 153, 153);">216</li><li style="color: rgb(153, 153, 153);">217</li><li style="color: rgb(153, 153, 153);">218</li><li style="color: rgb(153, 153, 153);">219</li><li style="color: rgb(153, 153, 153);">220</li><li style="color: rgb(153, 153, 153);">221</li><li style="color: rgb(153, 153, 153);">222</li><li style="color: rgb(153, 153, 153);">223</li><li style="color: rgb(153, 153, 153);">224</li><li style="color: rgb(153, 153, 153);">225</li><li style="color: rgb(153, 153, 153);">226</li><li style="color: rgb(153, 153, 153);">227</li><li style="color: rgb(153, 153, 153);">228</li><li style="color: rgb(153, 153, 153);">229</li><li style="color: rgb(153, 153, 153);">230</li><li style="color: rgb(153, 153, 153);">231</li><li style="color: rgb(153, 153, 153);">232</li><li style="color: rgb(153, 153, 153);">233</li><li style="color: rgb(153, 153, 153);">234</li><li style="color: rgb(153, 153, 153);">235</li><li style="color: rgb(153, 153, 153);">236</li><li style="color: rgb(153, 153, 153);">237</li><li style="color: rgb(153, 153, 153);">238</li><li style="color: rgb(153, 153, 153);">239</li><li style="color: rgb(153, 153, 153);">240</li><li style="color: rgb(153, 153, 153);">241</li><li style="color: rgb(153, 153, 153);">242</li><li style="color: rgb(153, 153, 153);">243</li><li style="color: rgb(153, 153, 153);">244</li><li style="color: rgb(153, 153, 153);">245</li><li style="color: rgb(153, 153, 153);">246</li><li style="color: rgb(153, 153, 153);">247</li><li style="color: rgb(153, 153, 153);">248</li><li style="color: rgb(153, 153, 153);">249</li><li style="color: rgb(153, 153, 153);">250</li><li style="color: rgb(153, 153, 153);">251</li><li style="color: rgb(153, 153, 153);">252</li><li style="color: rgb(153, 153, 153);">253</li><li style="color: rgb(153, 153, 153);">254</li><li style="color: rgb(153, 153, 153);">255</li><li style="color: rgb(153, 153, 153);">256</li><li style="color: rgb(153, 153, 153);">257</li><li style="color: rgb(153, 153, 153);">258</li><li style="color: rgb(153, 153, 153);">259</li><li style="color: rgb(153, 153, 153);">260</li><li style="color: rgb(153, 153, 153);">261</li><li style="color: rgb(153, 153, 153);">262</li><li style="color: rgb(153, 153, 153);">263</li><li style="color: rgb(153, 153, 153);">264</li><li style="color: rgb(153, 153, 153);">265</li><li style="color: rgb(153, 153, 153);">266</li><li style="color: rgb(153, 153, 153);">267</li><li style="color: rgb(153, 153, 153);">268</li><li style="color: rgb(153, 153, 153);">269</li><li style="color: rgb(153, 153, 153);">270</li><li style="color: rgb(153, 153, 153);">271</li><li style="color: rgb(153, 153, 153);">272</li><li style="color: rgb(153, 153, 153);">273</li><li style="color: rgb(153, 153, 153);">274</li><li style="color: rgb(153, 153, 153);">275</li><li style="color: rgb(153, 153, 153);">276</li><li style="color: rgb(153, 153, 153);">277</li><li style="color: rgb(153, 153, 153);">278</li><li style="color: rgb(153, 153, 153);">279</li><li style="color: rgb(153, 153, 153);">280</li><li style="color: rgb(153, 153, 153);">281</li><li style="color: rgb(153, 153, 153);">282</li><li style="color: rgb(153, 153, 153);">283</li><li style="color: rgb(153, 153, 153);">284</li><li style="color: rgb(153, 153, 153);">285</li><li style="color: rgb(153, 153, 153);">286</li><li style="color: rgb(153, 153, 153);">287</li><li style="color: rgb(153, 153, 153);">288</li><li style="color: rgb(153, 153, 153);">289</li><li style="color: rgb(153, 153, 153);">290</li><li style="color: rgb(153, 153, 153);">291</li><li style="color: rgb(153, 153, 153);">292</li><li style="color: rgb(153, 153, 153);">293</li><li style="color: rgb(153, 153, 153);">294</li><li style="color: rgb(153, 153, 153);">295</li><li style="color: rgb(153, 153, 153);">296</li><li style="color: rgb(153, 153, 153);">297</li><li style="color: rgb(153, 153, 153);">298</li><li style="color: rgb(153, 153, 153);">299</li><li style="color: rgb(153, 153, 153);">300</li><li style="color: rgb(153, 153, 153);">301</li><li style="color: rgb(153, 153, 153);">302</li><li style="color: rgb(153, 153, 153);">303</li><li style="color: rgb(153, 153, 153);">304</li><li style="color: rgb(153, 153, 153);">305</li><li style="color: rgb(153, 153, 153);">306</li><li style="color: rgb(153, 153, 153);">307</li><li style="color: rgb(153, 153, 153);">308</li><li style="color: rgb(153, 153, 153);">309</li><li style="color: rgb(153, 153, 153);">310</li><li style="color: rgb(153, 153, 153);">311</li><li style="color: rgb(153, 153, 153);">312</li><li style="color: rgb(153, 153, 153);">313</li><li style="color: rgb(153, 153, 153);">314</li><li style="color: rgb(153, 153, 153);">315</li><li style="color: rgb(153, 153, 153);">316</li><li style="color: rgb(153, 153, 153);">317</li><li style="color: rgb(153, 153, 153);">318</li><li style="color: rgb(153, 153, 153);">319</li><li style="color: rgb(153, 153, 153);">320</li><li style="color: rgb(153, 153, 153);">321</li><li style="color: rgb(153, 153, 153);">322</li><li style="color: rgb(153, 153, 153);">323</li><li style="color: rgb(153, 153, 153);">324</li><li style="color: rgb(153, 153, 153);">325</li><li style="color: rgb(153, 153, 153);">326</li><li style="color: rgb(153, 153, 153);">327</li><li style="color: rgb(153, 153, 153);">328</li><li style="color: rgb(153, 153, 153);">329</li><li style="color: rgb(153, 153, 153);">330</li><li style="color: rgb(153, 153, 153);">331</li><li style="color: rgb(153, 153, 153);">332</li><li style="color: rgb(153, 153, 153);">333</li><li style="color: rgb(153, 153, 153);">334</li><li style="color: rgb(153, 153, 153);">335</li><li style="color: rgb(153, 153, 153);">336</li><li style="color: rgb(153, 153, 153);">337</li><li style="color: rgb(153, 153, 153);">338</li><li style="color: rgb(153, 153, 153);">339</li><li style="color: rgb(153, 153, 153);">340</li><li style="color: rgb(153, 153, 153);">341</li><li style="color: rgb(153, 153, 153);">342</li><li style="color: rgb(153, 153, 153);">343</li><li style="color: rgb(153, 153, 153);">344</li><li style="color: rgb(153, 153, 153);">345</li><li style="color: rgb(153, 153, 153);">346</li><li style="color: rgb(153, 153, 153);">347</li><li style="color: rgb(153, 153, 153);">348</li><li style="color: rgb(153, 153, 153);">349</li><li style="color: rgb(153, 153, 153);">350</li><li style="color: rgb(153, 153, 153);">351</li><li style="color: rgb(153, 153, 153);">352</li><li style="color: rgb(153, 153, 153);">353</li><li style="color: rgb(153, 153, 153);">354</li><li style="color: rgb(153, 153, 153);">355</li><li style="color: rgb(153, 153, 153);"&