1 package com.atlassian.plugin.web.descriptors;
2
3 import org.dom4j.Element;
4
5 /**
6 * This class contains the logic for reading the weight value from a module
7 * descriptor's XML element.
8 * Its functionality is used by both
9 * {@link com.atlassian.plugin.web.descriptors.AbstractWebFragmentModuleDescriptor}
10 * and {@link com.atlassian.plugin.web.descriptors.DefaultWebPanelModuleDescriptor}.
11 *
12 * @since 2.5.0
13 */
14 class WeightElementParser
15 {
16 public static final int DEFAULT_WEIGHT = 1000;
17
18 /**
19 * @param moduleDescriptorElement a module descriptor XML element.
20 * @return the value of the <code>weight</code> attribute of the
21 * specified module descriptor element, or the system's default weight
22 * value if no weight was specified.
23 */
24 public static int getWeight(Element moduleDescriptorElement)
25 {
26 try
27 {
28 return Integer.parseInt(moduleDescriptorElement.attributeValue("weight"));
29 }
30 catch (final NumberFormatException e)
31 {
32 return DEFAULT_WEIGHT;
33 }
34 }
35 }