summaryrefslogtreecommitdiff
path: root/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java
diff options
context:
space:
mode:
Diffstat (limited to 'scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java')
-rw-r--r--scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java87
1 files changed, 47 insertions, 40 deletions
diff --git a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java
index 2d44ff55944e..77b2f9fb3810 100644
--- a/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java
+++ b/scripting/java/com/sun/star/script/framework/container/ParcelDescriptor.java
@@ -38,10 +38,11 @@ public class ParcelDescriptor {
// File name to be used for parcel descriptor files
public static final String
- PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml";
+ PARCEL_DESCRIPTOR_NAME = "parcel-descriptor.xml";
// Collection of all ParcelDescriptor created for files
- private static final Map<File,ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new HashMap<File,ParcelDescriptor>(5);
+ private static final Map<File, ParcelDescriptor> PARCEL_DESCRIPTOR_MAP = new
+ HashMap<File, ParcelDescriptor>(5);
// This is the default contents of a parcel descriptor to be used when
// creating empty descriptors
@@ -53,7 +54,7 @@ public class ParcelDescriptor {
private File file = null;
private Document document = null;
private String language = null;
- private Map<String,String> languagedepprops = new HashMap<String,String>(3);
+ private Map<String, String> languagedepprops = new HashMap<String, String>(3);
@@ -61,11 +62,11 @@ public class ParcelDescriptor {
public ParcelDescriptor() throws IOException {
ByteArrayInputStream bis = null;
+
try {
bis = new ByteArrayInputStream(EMPTY_DOCUMENT);
this.document = XMLParserFactory.getParser().parse(bis);
- }
- finally {
+ } finally {
if (bis != null)
bis.close();
}
@@ -89,27 +90,28 @@ public class ParcelDescriptor {
if (file.exists()) {
FileInputStream fis = null;
+
try {
fis = new FileInputStream(file);
this.document = XMLParserFactory.getParser().parse(fis);
- }
- finally {
+ } finally {
if (fis != null)
fis.close();
}
- }
- else {
+ } else {
ByteArrayInputStream bis = null;
+
try {
bis = new ByteArrayInputStream(EMPTY_DOCUMENT);
this.document = XMLParserFactory.getParser().parse(bis);
- }
- finally {
+ } finally {
if (bis != null)
bis.close();
}
+
setLanguage(language);
}
+
initLanguageProperties();
}
@@ -128,6 +130,7 @@ public class ParcelDescriptor {
language = e.getAttribute("language");
}
}
+
return language;
}
@@ -138,8 +141,7 @@ public class ParcelDescriptor {
try {
Element e = document.getDocumentElement();
e.setAttribute("language", language);
- }
- catch (DOMException de) {
+ } catch (DOMException de) {
}
}
}
@@ -156,7 +158,7 @@ public class ParcelDescriptor {
for (int i = 0; i < len; i++) {
String language, languagename, logicalname, description = "";
- Map<String,String> langProps = new HashMap<String,String>();
+ Map<String, String> langProps = new HashMap<String, String>();
NodeList nl;
Element tmp;
@@ -164,6 +166,7 @@ public class ParcelDescriptor {
language = scriptElement.getAttribute("language");
nl = scriptElement.getElementsByTagName("logicalname");
+
if (nl == null)
logicalname = "";
else {
@@ -173,15 +176,13 @@ public class ParcelDescriptor {
// get the text of the description element
nl = scriptElement.getElementsByTagName("locale");
- if (nl != null)
- {
+
+ if (nl != null) {
nl = nl.item(0).getChildNodes();
- if (nl != null)
- {
- for (int j = 0 ; j < nl.getLength(); j++)
- {
- if (nl.item(j).getNodeName().equals("description"))
- {
+
+ if (nl != null) {
+ for (int j = 0 ; j < nl.getLength(); j++) {
+ if (nl.item(j).getNodeName().equals("description")) {
CharacterData cd =
(CharacterData)nl.item(j).getFirstChild();
description = cd.getData().trim();
@@ -191,36 +192,41 @@ public class ParcelDescriptor {
}
nl = scriptElement.getElementsByTagName("functionname");
+
if (nl == null) {
languagename = "";
} else {
tmp = (Element)nl.item(0);
languagename = tmp.getAttribute("value");
}
+
nl = scriptElement.getElementsByTagName("languagedepprops");
- if ( nl != null && nl.getLength() > 0 )
- {
+
+ if (nl != null && nl.getLength() > 0) {
NodeList props = ((Element)nl.item(0)).getElementsByTagName("prop");
- if ( props != null )
- {
- for ( int j=0; j < props.getLength(); j++ )
- {
+
+ if (props != null) {
+ for (int j = 0; j < props.getLength(); j++) {
tmp = (Element)props.item(j);
String key = tmp.getAttribute("name");
String val = tmp.getAttribute("value");
- langProps.put( key,val );
+ langProps.put(key, val);
}
}
}
- ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,description);
+
+ ScriptEntry entry = new ScriptEntry(language, languagename, "", langProps,
+ description);
scripts.add(entry);
}
+
return scripts.toArray(new ScriptEntry[scripts.size()]);
}
public void setScriptEntries(ScriptEntry[] scripts) {
clearEntries();
+
for (ScriptEntry script : scripts) {
addScriptEntry(script);
}
@@ -228,6 +234,7 @@ public class ParcelDescriptor {
public void setScriptEntries(Iterator<ScriptEntry> scripts) {
clearEntries();
+
while (scripts.hasNext())
addScriptEntry(scripts.next());
}
@@ -271,13 +278,11 @@ public class ParcelDescriptor {
int len;
if ((scriptNodes = document.getElementsByTagName("script")) != null &&
- (len = scriptNodes.getLength()) != 0)
- {
+ (len = scriptNodes.getLength()) != 0) {
for (int i = len - 1; i >= 0; i--) {
try {
main.removeChild(scriptNodes.item(i));
- }
- catch (DOMException de) {
+ } catch (DOMException de) {
// ignore
}
}
@@ -290,8 +295,7 @@ public class ParcelDescriptor {
int len;
if ((scriptNodes = document.getElementsByTagName("script")) != null &&
- (len = scriptNodes.getLength()) != 0)
- {
+ (len = scriptNodes.getLength()) != 0) {
for (int i = len - 1; i >= 0; i--) {
try {
Element scriptElement = (Element)scriptNodes.item(i);
@@ -299,6 +303,7 @@ public class ParcelDescriptor {
NodeList nl =
scriptElement.getElementsByTagName("functionname");
+
if (nl == null) {
continue;
} else {
@@ -309,8 +314,7 @@ public class ParcelDescriptor {
if (languagename.equals(script.getLanguageName())) {
main.removeChild(scriptElement);
}
- }
- catch (DOMException de) {
+ } catch (DOMException de) {
// ignore
}
}
@@ -332,10 +336,11 @@ public class ParcelDescriptor {
tempitem = document.createElement("description");
String description = script.getDescription();
- if (description == null || description.length() == 0)
- {
+
+ if (description == null || description.length() == 0) {
description = script.getLogicalName();
}
+
tempitem.appendChild(document.createTextNode(description));
item.appendChild(tempitem);
@@ -354,6 +359,7 @@ public class ParcelDescriptor {
item = document.createElement("languagedepprops");
Iterator<String> iter = languagedepprops.keySet().iterator();
+
while (iter.hasNext()) {
tempitem = document.createElement("prop");
key = iter.next();
@@ -361,6 +367,7 @@ public class ParcelDescriptor {
tempitem.setAttribute("value", languagedepprops.get(key));
item.appendChild(tempitem);
}
+
root.appendChild(item);
}