/** * Gets the resource string for the given command command-ID and command property name. */ protected String getConfigString(ConfigurationElement config, String elementName) { String value = null; ConfigurationElement child = config.getChild(elementName); if (child != null) { value = child.getValue(); } return value; }
@Override public void configure(ConfigurationElement config) throws CoreException { super.configure(config); ConfigurationElement itemsElement = config.getChild(ELEMENT_NAME_ITEMS); if (itemsElement == null) { return; } ConfigurationElement[] children = itemsElement.getChildren(); String[] groupItems = new String[children.length]; for (int i = 0; i < children.length; i++) { ConfigurationElement child = children[i]; String childName = child.getName(); switch (childName) { case ELEMENT_NAME_ACTION_ID: case ELEMENT_NAME_ACTION_GROUP_ID: groupItems[i] = child.getValue().trim(); break; case ELEMENT_NAME_SEPARATOR: groupItems[i] = null; break; default: Module declaringModule = config.getDeclaringExtension().getDeclaringModule(); throw new CoreException(String.format("Module [%s]: '%s' is an unknown 'groupItems' element", declaringModule.getName(), childName)); } } setProperty(ACTION_KEY_GROUP_ITEMS, groupItems); }
protected String getValue(ConfigurationElement config, String elementName, String defaultValue) { String value = null; ConfigurationElement child = config.getChild(elementName); if (child != null) { value = child.getValue(); } return value != null ? value : defaultValue; }
private static String getChildValue(ConfigurationElement config, String childName) throws CoreException { ConfigurationElement child = config.getChild(childName); if (child != null) { return child.getValue(); } else { throw new CoreException("Configuration element [" + childName + "] does not exist"); } } }
rgbaExpressions[B] = getChildValue(config, "blue"); ConfigurationElement child = config.getChild("alpha"); String alpha = null; if (child != null) { ConfigurationElement patternConfig = config.getChild("pattern"); if (patternConfig != null) { pattern = new String[3]; ConfigurationElement productType = patternConfig.getChild("productType"); ConfigurationElement productName = patternConfig.getChild("productName"); ConfigurationElement productDesc = patternConfig.getChild("productDesc"); if (productType != null) { pattern[0] = productType.getValue();
@Override public void configure(ConfigurationElement config) throws CoreException { super.configure(config); module = config.getDeclaringExtension().getDeclaringModule(); ConfigurationElement script = config.getChild("script"); if (script != null) { String scriptType = script.getAttribute("type"); if (StringUtils.isNotNullAndNotEmpty(scriptType)) { type = scriptType; } String scriptSrc = script.getAttribute("src"); if (StringUtils.isNotNullAndNotEmpty(scriptSrc)) { src = scriptSrc; } String scriptCode = script.getValue(); if (StringUtils.isNotNullAndNotEmpty(scriptCode)) { code = scriptCode; } System.out.printf("ScriptAction [%s] of module [%s]:%n", getText(), module.getSymbolicName()); System.out.printf(" type = [%s]%n", this.type); System.out.printf(" src = [%s]%n", this.src); System.out.printf(" code = [%s]%n", this.code); } }
when(productDescConfig.getValue()).thenReturn(""); when(config.getChild("name")).thenReturn(nameConfig); when(config.getChild("red")).thenReturn(redConfig); when(config.getChild("green")).thenReturn(greenConfig); when(config.getChild("blue")).thenReturn(blueConfig); when(config.getChild("alpha")).thenReturn(null); when(config.getChild("pattern")).thenReturn(patternConfig); when(patternConfig.getChild("productType")).thenReturn(productTypeConfig); when(patternConfig.getChild("productName")).thenReturn(productNameConfig); when(patternConfig.getChild("productDesc")).thenReturn(productDescConfig);
@Test public void testConfigure_withoutPattern() throws Exception { RGBImageProfile profile = new RGBImageProfile(); ConfigurationElement config = mock(ConfigurationElement.class); ConfigurationElement nameConfig = mock(ConfigurationElement.class); ConfigurationElement redConfig = mock(ConfigurationElement.class); ConfigurationElement greenConfig = mock(ConfigurationElement.class); ConfigurationElement blueConfig = mock(ConfigurationElement.class); when(nameConfig.getValue()).thenReturn("test_name"); when(redConfig.getValue()).thenReturn("radiance_12"); when(greenConfig.getValue()).thenReturn("radiance_6"); when(blueConfig.getValue()).thenReturn("radiance_2"); when(config.getChild("name")).thenReturn(nameConfig); when(config.getChild("red")).thenReturn(redConfig); when(config.getChild("green")).thenReturn(greenConfig); when(config.getChild("blue")).thenReturn(blueConfig); when(config.getChild("alpha")).thenReturn(null); profile.configure(config); assertEquals("test_name", profile.getName()); assertEquals("", profile.getAlphaExpression()); assertEquals("radiance_2", profile.getBlueExpression()); assertEquals("radiance_12", profile.getRedExpression()); assertEquals("radiance_6", profile.getGreenExpression()); assertNull(profile.getPattern()); }
private void registerHelpSet(ConfigurationElement helpSetElement, Module declaringModule) { String helpSetPath = null; ConfigurationElement pathElem = helpSetElement.getChild("path"); if (pathElem != null) { helpSetPath = pathElem.getValue(); ConfigurationElement idElem = helpSetElement.getChild("id"); if (idElem != null) { helpSetId = idElem.getValue(); ConfigurationElement parentElem = helpSetElement.getChild("parent"); if (parentElem != null) { helpSetParent = parentElem.getValue();