public CombinedCondition(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); List<? extends Element> childElements = UtilXml.childElementList(element); if (MiniLangValidate.validationOn() && childElements.isEmpty()) { MiniLangValidate.handleError("No conditional elements.", simpleMethod, element); } List<Conditional> conditionalList = new ArrayList<Conditional>(childElements.size()); for (Element conditionalElement : UtilXml.childElementList(element)) { conditionalList.add(ConditionalFactory.makeConditional(conditionalElement, simpleMethod)); } this.subConditions = Collections.unmodifiableList(conditionalList); }
public MapProcessor(Element simpleMapProcessorElement) { name = simpleMapProcessorElement.getAttribute("name"); for (Element makeInStringElement : UtilXml.childElementList(simpleMapProcessorElement, "make-in-string")) { MakeInString makeInString = new MakeInString(makeInStringElement); makeInStrings.add(makeInString); } for (Element simpleMapProcessElement : UtilXml.childElementList(simpleMapProcessorElement, "process")) { SimpleMapProcess strProc = new SimpleMapProcess(simpleMapProcessElement); simpleMapProcesses.add(strProc); } }
public static List<ComponentDef> getComponentsFromConfig(URL configUrl) throws ComponentException { if (configUrl == null) { throw new ComponentException("Component config file does not exist: " + configUrl); } List<ComponentDef> componentsFromConfig = null; Document document = null; try { document = UtilXml.readXmlDocument(configUrl, true); } catch (SAXException e) { throw new ComponentException("Error reading the component config file: " + configUrl, e); } catch (ParserConfigurationException e) { throw new ComponentException("Error reading the component config file: " + configUrl, e); } catch (IOException e) { throw new ComponentException("Error reading the component config file: " + configUrl, e); } Element root = document.getDocumentElement(); List<? extends Element> toLoad = UtilXml.childElementList(root); if (UtilValidate.isNotEmpty(toLoad)) { componentsFromConfig = new LinkedList<ComponentDef>(); for (Element element : toLoad) { componentsFromConfig.add(new ComponentDef(element)); } } return componentsFromConfig; }
private void getLabelsFromOfbizComponents() throws IOException, SAXException, ParserConfigurationException { List<File> componentsFiles = FileUtil.findXmlFiles( null, null, "ofbiz-component", "http://ofbiz.apache.org/dtds/ofbiz-component.xsd"); for (File componentFile : componentsFiles) { String filePath = componentFile.getPath(); Document menuDocument = UtilXml.readXmlDocument(componentFile.toURI().toURL()); Element rootElem = menuDocument.getDocumentElement(); for (Element elem1 : UtilXml.childElementList(rootElem)) { checkOfbizComponentTag(elem1, filePath); for (Element elem2 : UtilXml.childElementList(elem1)) { checkOfbizComponentTag(elem2, filePath); } } } }
public HtmlTemplateDecoratorSection( ModelScreen modelScreen, Element htmlTemplateDecoratorSectionElement) { super(modelScreen, htmlTemplateDecoratorSectionElement); this.name = htmlTemplateDecoratorSectionElement.getAttribute("name"); // read sub-widgets List<? extends Element> subElementList = UtilXml.childElementList(htmlTemplateDecoratorSectionElement); this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList); }
public static List<ScreenCondition> readSubConditions( ModelScreen modelScreen, Element conditionElement) { List<ScreenCondition> condList = FastList.newInstance(); List<? extends Element> subElementList = UtilXml.childElementList(conditionElement); for (Element subElement : subElementList) { condList.add(readCondition(modelScreen, subElement)); } return condList; }
private void getLabelsFromFormWidgets(String inFile, File file) throws MalformedURLException, SAXException, ParserConfigurationException, IOException, GenericServiceException { Set<String> fieldNames = FastSet.newInstance(); findUiLabelMapInFile(inFile, file.getPath()); Document formDocument = UtilXml.readXmlDocument(file.toURI().toURL()); Element rootElem = formDocument.getDocumentElement(); for (Element formElement : UtilXml.childElementList(rootElem, "form")) { for (Element elem : UtilXml.childElementList(formElement, "auto-fields-service")) { getAutoFieldsServiceTag(elem, fieldNames); } for (Element elem : UtilXml.childElementList(formElement, "auto-fields-entity")) { getAutoFieldsEntityTag(elem, fieldNames); } for (String field : fieldNames) { String labelKey = formFieldTitle.concat(field); if (this.labelSet.contains(labelKey)) { setLabelReference(labelKey, file.getPath()); } } } }
public HtmlTemplateDecorator(ModelScreen modelScreen, Element htmlTemplateDecoratorElement) { super(modelScreen, htmlTemplateDecoratorElement); this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateDecoratorElement.getAttribute("location")); List<? extends Element> htmlTemplateDecoratorSectionElementList = UtilXml.childElementList(htmlTemplateDecoratorElement, "html-template-decorator-section"); for (Element htmlTemplateDecoratorSectionElement : htmlTemplateDecoratorSectionElementList) { String name = htmlTemplateDecoratorSectionElement.getAttribute("name"); this.sectionMap.put( name, new HtmlTemplateDecoratorSection(modelScreen, htmlTemplateDecoratorSectionElement)); } }
public static Map<String, ModelTree> readTreeDocument( Document treeFileDoc, Delegator delegator, LocalDispatcher dispatcher, String treeLocation) { Map<String, ModelTree> modelTreeMap = new HashMap<String, ModelTree>(); if (treeFileDoc != null) { // read document and construct ModelTree for each tree element Element rootElement = treeFileDoc.getDocumentElement(); for (Element treeElement : UtilXml.childElementList(rootElement, "tree")) { ModelTree modelTree = new ModelTree(treeElement, delegator, dispatcher); modelTree.setTreeLocation(treeLocation); modelTreeMap.put(modelTree.getName(), modelTree); } } return modelTreeMap; }
public HtmlWidget(ModelScreen modelScreen, Element htmlElement) { super(modelScreen, htmlElement); List<? extends Element> childElementList = UtilXml.childElementList(htmlElement); for (Element childElement : childElementList) { if ("html-template".equals(childElement.getNodeName())) { this.subWidgets.add(new HtmlTemplate(modelScreen, childElement)); } else if ("html-template-decorator".equals(childElement.getNodeName())) { this.subWidgets.add(new HtmlTemplateDecorator(modelScreen, childElement)); } else { throw new IllegalArgumentException( "Tag not supported under the platform-specific -> html tag with name: " + childElement.getNodeName()); } } }
public CallSimpleMethod(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); if (MiniLangValidate.validationOn()) { MiniLangValidate.attributeNames( simpleMethod, element, "method-name", "xml-resource", "scope"); MiniLangValidate.requiredAttributes(simpleMethod, element, "method-name"); MiniLangValidate.constantAttributes( simpleMethod, element, "method-name", "xml-resource", "scope"); MiniLangValidate.childElements(simpleMethod, element, "result-to-field"); } this.methodName = element.getAttribute("method-name"); String xmlResourceAttribute = element.getAttribute("xml-resource"); if (xmlResourceAttribute.isEmpty()) { xmlResourceAttribute = simpleMethod.getFromLocation(); } this.xmlResource = xmlResourceAttribute; URL xmlURL = null; try { xmlURL = FlexibleLocation.resolveLocation(this.xmlResource); } catch (MalformedURLException e) { MiniLangValidate.handleError( "Could not find SimpleMethod XML document in resource: " + this.xmlResource + "; error was: " + e.toString(), simpleMethod, element); } this.xmlURL = xmlURL; this.scope = element.getAttribute("scope"); List<? extends Element> resultToFieldElements = UtilXml.childElementList(element, "result-to-field"); if (UtilValidate.isNotEmpty(resultToFieldElements)) { if (!"function".equals(this.scope)) { MiniLangValidate.handleError( "Inline scope cannot include <result-to-field> elements.", simpleMethod, element); } List<ResultToField> resultToFieldList = new ArrayList<ResultToField>(resultToFieldElements.size()); for (Element resultToFieldElement : resultToFieldElements) { resultToFieldList.add(new ResultToField(resultToFieldElement, simpleMethod)); } this.resultToFieldList = resultToFieldList; } else { this.resultToFieldList = null; } }
protected static void addEcaDefinitions( ResourceHandler handler, Map<String, Map<String, List<EntityEcaRule>>> ecaCache) { Element rootElement = null; try { rootElement = handler.getDocument().getDocumentElement(); } catch (GenericConfigException e) { Debug.logError(e, module); return; } int numDefs = 0; for (Element e : UtilXml.childElementList(rootElement, "eca")) { String entityName = e.getAttribute("entity"); String eventName = e.getAttribute("event"); Map<String, List<EntityEcaRule>> eventMap = ecaCache.get(entityName); List<EntityEcaRule> rules = null; if (eventMap == null) { eventMap = FastMap.newInstance(); rules = FastList.newInstance(); ecaCache.put(entityName, eventMap); eventMap.put(eventName, rules); } else { rules = eventMap.get(eventName); if (rules == null) { rules = FastList.newInstance(); eventMap.put(eventName, rules); } } rules.add(new EntityEcaRule(e)); numDefs++; } try { Debug.logImportant( "Loaded [" + numDefs + "] Entity ECA definitions from " + handler.getFullLocation() + " in loader " + handler.getLoaderName(), module); } catch (GenericConfigException e) { Debug.logError(e, module); return; } }
// Load the JMS listeners private void loadListeners() { try { Element rootElement = ServiceConfigUtil.getXmlRootElement(); NodeList nodeList = rootElement.getElementsByTagName("jms-service"); if (Debug.verboseOn()) Debug.logVerbose("[ServiceDispatcher] : Loading JMS Listeners.", module); for (int i = 0; i < nodeList.getLength(); i++) { Element element = (Element) nodeList.item(i); StringBuilder serverKey = new StringBuilder(); for (Element server : UtilXml.childElementList(element, "server")) { try { String listenerEnabled = server.getAttribute("listen"); if (listenerEnabled.equalsIgnoreCase("true")) { // create a server key serverKey.append(server.getAttribute("jndi-server-name") + ":"); serverKey.append(server.getAttribute("jndi-name") + ":"); serverKey.append(server.getAttribute("topic-queue")); // store the server element servers.put(serverKey.toString(), server); // load the listener GenericMessageListener listener = loadListener(serverKey.toString(), server); // store the listener w/ the key if (serverKey.length() > 0 && listener != null) listeners.put(serverKey.toString(), listener); } } catch (GenericServiceException gse) { Debug.logInfo( "Cannot load message listener " + serverKey + " error: (" + gse.toString() + ").", module); } catch (Exception e) { Debug.logError(e, "Uncaught exception.", module); } } } } catch (org.ofbiz.base.config.GenericConfigException gce) { Debug.logError(gce, "Cannot get serviceengine.xml root element.", module); } catch (Exception e) { Debug.logError(e, "Uncaught exception.", module); } }
public IterateSectionWidget(ModelScreen modelScreen, Element iterateSectionElement) { super(modelScreen, iterateSectionElement); listNameExdr = FlexibleMapAccessor.getInstance(iterateSectionElement.getAttribute("list")); if (listNameExdr.isEmpty()) listNameExdr = FlexibleMapAccessor.getInstance(iterateSectionElement.getAttribute("list-name")); entryNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("entry")); if (entryNameExdr.isEmpty()) entryNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("entry-name")); keyNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("key")); if (keyNameExdr.isEmpty()) keyNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("key-name")); if (this.paginateTarget == null || iterateSectionElement.hasAttribute("paginate-target")) { this.paginateTarget = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate-target")); } if (this.paginate == null || iterateSectionElement.hasAttribute("paginate")) { this.paginate = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate")); } if (iterateSectionElement.hasAttribute("view-size")) { setViewSize(iterateSectionElement.getAttribute("view-size")); } sectionList = new ArrayList<ModelScreenWidget.Section>(); List<? extends Element> childElementList = UtilXml.childElementList(iterateSectionElement); for (Element sectionElement : childElementList) { ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement); sectionList.add(section); } }
/** * getXMLValue * * <p>From a XML element, get a values map * * @param fileFullPath File path to parse * @return Map contains asked attribute values by attribute name */ public static Map<String, Object> getXMLValue(String fileFullPath, Locale locale) throws IllegalStateException, IOException { /* VARIABLES */ Document document; Element rootElt; Map<String, Map<String, String>> valueMap = FastMap.newInstance(); Map<String, Object> result = FastMap.newInstance(); /* PARSING */ try { document = UtilXml.readXmlDocument(new FileInputStream(fileFullPath), fileFullPath); } catch (ParserConfigurationException e) { String errMsg = UtilProperties.getMessage( resource, "ImageTransform.errors_occured_during_parsing", locale) + " ImageProperties.xml " + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; } catch (SAXException e) { String errMsg = UtilProperties.getMessage( resource, "ImageTransform.errors_occured_during_parsing", locale) + " ImageProperties.xml " + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; } catch (IOException e) { String errMsg = UtilProperties.getMessage( resource, "ImageTransform.error_prevents_the document_from_being_fully_parsed", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; } // set Root Element try { rootElt = document.getDocumentElement(); } catch (IllegalStateException e) { String errMsg = UtilProperties.getMessage( resource, "ImageTransform.root_element_has_not_been_set", locale) + e.toString(); Debug.logError(errMsg, module); result.put("errorMessage", "error"); return result; } /* get NAME and VALUE */ List<? extends Element> children = UtilXml.childElementList( rootElt); // FIXME : despite upgrading to jdom 1.1, it seems that getChildren is pre 1.5 // java code (ie getChildren does not retun List<Element> but only List) for (Element currentElt : children) { Map<String, String> eltMap = FastMap.newInstance(); List<? extends Element> children2 = UtilXml.childElementList(currentElt); if (children2.size() > 0) { Map<String, String> childMap = FastMap.newInstance(); // loop over Children 1st level for (Element currentChild : children2) { childMap.put(currentChild.getAttribute("name"), currentChild.getAttribute("value")); } valueMap.put(currentElt.getAttribute("name"), childMap); } else { eltMap.put(currentElt.getAttribute("name"), currentElt.getAttribute("value")); valueMap.put(currentElt.getNodeName(), eltMap); } } result.put("responseMessage", "success"); result.put("xml", valueMap); return result; }