| 557 | | |
| | 584 | |
| | 585 | private TargetRW createTargetForComponent(String componentKey) { |
| | 586 | |
| | 587 | String[] comps = splitComponentKey(componentKey); |
| | 588 | String href = comps[0]; |
| | 589 | String part = comps[1]; |
| | 590 | String module = ""; |
| | 591 | if(comps.length>2) module = comps[2]; |
| | 592 | String search = ""; |
| | 593 | if(comps.length>3) search = comps[3]; |
| | 594 | |
| | 595 | System.out.println("NNNNNNNNNNNNNNNNNN: " + componentKey); |
| | 596 | //sample1_txt_pages_main_foo@content::foo:bar:baz.xml |
| | 597 | Themes themes = global_themes; |
| | 598 | |
| | 599 | if(getTargetRW(name) != null) throw new RuntimeException("Target already exists"); |
| | 600 | |
| | 601 | String tgParam = config_path.toString(); |
| | 602 | |
| | 603 | XMLVirtualTarget xmlTarget = (XMLVirtualTarget)createTarget(TargetType.XML_VIRTUAL, componentKey + ".xml", themes); |
| | 604 | Target xmlSource = createTarget(TargetType.XML_LEAF, "core/xml/component.xml", null); |
| | 605 | Target xslSource = createTarget(TargetType.XSL_VIRTUAL, "metatags.xsl", null); |
| | 606 | xmlTarget.setXMLSource(xmlSource); |
| | 607 | xmlTarget.setXSLSource(xslSource); |
| | 608 | xmlTarget.addParam(XSLPARAM_TG, tgParam); |
| | 609 | xmlTarget.addParam(XSLPARAM_TKEY, componentKey + ".xml"); |
| | 610 | xmlTarget.addParam("component_href", href); |
| | 611 | xmlTarget.addParam("component_part", part); |
| | 612 | xmlTarget.addParam("component_module", module); |
| | 613 | xmlTarget.addParam("component_search", search); |
| | 614 | |
| | 615 | XSLVirtualTarget xslTarget = (XSLVirtualTarget)createTarget(TargetType.XSL_VIRTUAL, componentKey + ".xsl", themes); |
| | 616 | xmlSource = xmlTarget; |
| | 617 | xslSource = createTarget(TargetType.XSL_VIRTUAL, "master.xsl", null); |
| | 618 | xslTarget.setXMLSource(xmlSource); |
| | 619 | xslTarget.setXSLSource(xslSource); |
| | 620 | xslTarget.addParam(XSLPARAM_TG, tgParam); |
| | 621 | xslTarget.addParam(XSLPARAM_TKEY, componentKey + ".xsl"); |
| | 622 | |
| | 623 | return xslTarget; |
| | 624 | } |
| | 625 | |
| | 626 | |
| | 627 | |
| | 628 | |
| | 629 | |
| | 953 | |
| | 954 | public static String createComponentKey(String href, String part, String module, String search) { |
| | 955 | if(href == null || href.equals("")) throw new IllegalArgumentException("Argument 'href' must not be empty"); |
| | 956 | if(part == null || part.equals("")) throw new IllegalArgumentException("Argument 'part' must not be empty"); |
| | 957 | if(module == null) module = ""; |
| | 958 | if(search == null) search = ""; |
| | 959 | String targetKey = encode(href) + "$" + encode(part) + "$" + encode(module) + "$" + encode(search); |
| | 960 | return targetKey; |
| | 961 | } |
| | 962 | |
| | 963 | public static String encode(String str) { |
| | 964 | str = str.replace("%", "%" + Integer.toHexString('%')); |
| | 965 | str = str.replace("$", "%" + Integer.toHexString('$')); |
| | 966 | str = str.replace("+", "%" + Integer.toHexString('+')); |
| | 967 | str = str.replace("/", "+"); |
| | 968 | return str; |
| | 969 | } |
| | 970 | |
| | 971 | public static String decode(String str) { |
| | 972 | str = str.replace("+", "/"); |
| | 973 | str = str.replace("%" + Integer.toHexString('+'), "+"); |
| | 974 | str = str.replace("%" + Integer.toHexString('$'), "$"); |
| | 975 | str = str.replace("%" + Integer.toHexString('%'), "%"); |
| | 976 | return str; |
| | 977 | } |
| | 978 | |
| | 979 | public static String[] splitComponentKey(String componentKey) { |
| | 980 | String[] comps = componentKey.split("\\$"); |
| | 981 | for(int i=0; i<comps.length; i++) { |
| | 982 | comps[i] = decode(comps[i]); |
| | 983 | } |
| | 984 | return comps; |
| | 985 | } |