public void processImports5Test() { String locale_ = "LOCALE"; String folder_ = "messages"; String relative_ = "sample/file"; String content_ = "one=Description one\ntwo=Description <a href=\"\">two</a>\nthree=desc <{0}>\nfour=''asp''"; String html_ = "<html bean=\"bean_one\"><body><c.import page=\"page2.html\"><a/><c.package name=\"FormatHtmlTests\"><a/><c.class name=\"BeanTwo\"><a/><c.field name=\"typedString\" value=\"message\"><a/></c.field></c.class></c.package></c.import></body></html>"; String htmlTwo_ = "<html bean=\"bean_two\"><body><a href=\"DELETE\" command=\"go\">{typedString}</a></body></html>"; Map <String, String> files_ = new Map <String, String>(); files_.put(folder_ + "/" + locale_ + "/" + relative_ + ".properties", content_); files_.put("page1.html", html_); files_.put("page2.html", htmlTwo_); BeanOne bean_ = new BeanOne(); bean_.getComposite().getStrings().Add("FIRST"); bean_.getComposite().getStrings().Add("SECOND"); bean_.getComposite().setInteger(5); bean_.getTree().put("ONE", 1); bean_.getTree().put("TWO", 2); bean_.setForms(new Map <String, Object>()); bean_.getForms().put("key", "sample_value"); BeanTwo beanTwo_ = new BeanTwo(); beanTwo_.setTypedString("TITLE"); beanTwo_.setForms(new Map <String, Object>()); Configuration conf_ = new Configuration(); conf_.setAssembly("FormatHtmlTests"); conf_.setBeans(new Map <String, Bean>()); conf_.getBeans().put("bean_one", bean_); conf_.getBeans().put("bean_two", beanTwo_); conf_.setMessagesFolder(folder_); conf_.setProperties(new Map <String, String>()); conf_.getProperties().put("msg_example", relative_); conf_.setTranslators(new Map <String, Translator>()); conf_.getTranslators().put("trans", new MyTranslator()); String render_ = FormatHtml.processImports(html_, conf_, locale_, files_); Assert.AreEqual("<html><body><a href=\"\" command=\"go\">Test {0}2</a></body></html>", render_); Assert.AreEqual(1, beanTwo_.getForms().size()); Assert.AreEqual("key", beanTwo_.getForms().getKeys().get(0)); Assert.AreEqual("sample_value", beanTwo_.getForms().values().get(0)); }
public void initializeSession() { foreach (String b in session.getBeans().getKeys()) { Bean bean_ = newBean(session.getBeans().getVal(b)); bean_.setForms(new Map <String, Object>()); bean_.setDataBase(dataBase); bean_.setLanguage(language); //bean_.setNavigation(this); session.getBeans().put(b, bean_); } String currentUrl_ = session.getFirstUrl(); String text_ = FormatHtml.loadPage(assembly, files, currentUrl_, resourcesFolder); String currentBeanName_ = FormatHtml.getCurrentBean(text_); htmlText = FormatHtml.processImports(text_, session, language, files, resourcesFolder); //For title currentBeanName = currentBeanName_; currentUrl = currentUrl_; setupText(htmlText); }
public void processAnchorRequest(String _anchorRef) { String textToBeChanged_; Bean bean_; Map <String, Object> forms_; String currentUrl_; String currentBeanName_; if (_anchorRef.Contains(CALL_METHOD)) { Regex pattern_ = new Regex(REG_EXP_ARGS); int indexPoint_ = _anchorRef.IndexOf(DOT); String action_ = _anchorRef .Substring(indexPoint_ + 1); String key_ = action_.replaceAll(REG_EXP_INT, EMPTY_STRING); Match match_ = pattern_.Match(action_); String argsString_ = EMPTY_STRING; if (match_.Success) { argsString_ = match_.Groups[1].Value; //argsString_ = match_.Value; } MyList <long> args_ = new MyList <long>(); foreach (String l in StringList.splitStrings(argsString_, COMMA)) { if (l.isEmpty()) { continue; } args_.Add(long.Parse(l)); } String command_ = StringList.getFirstToken(action_, BEGIN_ARGS); int begin_ = _anchorRef.IndexOf(CALL_METHOD) + 1; String beanName_ = _anchorRef .Substring(begin_, indexPoint_ - begin_); bean_ = session.getBeans().getVal(beanName_); Object return_ = FormatHtml.invokeMethodWithNumbers( bean_, command_, args_.ToArray()); forms_ = bean_.getForms(); String urlDest_ = currentUrl; if (return_ != null) { urlDest_ = session.getNavigation() .getVal(beanName_ + DOT + key_) .getVal(return_.ToString()); if (urlDest_ == null) { urlDest_ = currentUrl; } } foreach (String b in session.getBeans().getKeys()) { if (!reinitBean(urlDest_, beanName_, b)) { continue; } bean_ = session.getBeans().getVal(b); bean_ = newBean(bean_); bean_.setForms(forms_); session.getBeans().put(b, bean_); } currentUrl_ = urlDest_; textToBeChanged_ = FormatHtml.loadPage(assembly, files, StringList.getFirstToken(urlDest_, REF_TAG), resourcesFolder); currentBeanName_ = FormatHtml .getCurrentBean(textToBeChanged_); bean_ = session.getBeans().getVal(currentBeanName_); bean_.setForms(forms_); textToBeChanged_ = FormatHtml.processImports( textToBeChanged_, session, language, files, resourcesFolder); currentBeanName = currentBeanName_; currentUrl = currentUrl_; setupText(textToBeChanged_); return; } if (_anchorRef.isEmpty()) { return; } bean_ = session.getBeans().getVal(currentBeanName); forms_ = bean_.getForms(); foreach (String b in session.getBeans().getKeys()) { if (!reinitBean(_anchorRef, currentBeanName, b)) { continue; } bean_ = session.getBeans().getVal(b); bean_ = newBean(bean_); bean_.setForms(forms_); session.getBeans().put(b, bean_); } currentUrl_ = _anchorRef; textToBeChanged_ = FormatHtml.loadPage(assembly, files, StringList.getFirstToken(_anchorRef, REF_TAG), resourcesFolder); currentBeanName_ = FormatHtml .getCurrentBean(textToBeChanged_); bean_ = session.getBeans().getVal(currentBeanName_); bean_.setForms(forms_); textToBeChanged_ = FormatHtml.processImports( textToBeChanged_, session, language, files, resourcesFolder); currentBeanName = currentBeanName_; currentUrl = currentUrl_; setupText(textToBeChanged_); }