Exemple #1
0
 /**
  * <work-area id="tree-edit"> <caption>Tree editor</caption> <link>tree-editor.jsp</link>
  * <icon>tree.gif</icon> <modules> <module name="tree"/> <module name="grid"/> <module
  * name="editor"/> </modules> </work-area>
  *
  * @param el
  */
 public WorkAreaImpl(Element el, Core core)
     throws CMCConfigurationException, NoSuchModuleException {
   if (!"work-area".equals(el.getNodeName()))
     throw new CMCConfigurationException("Node name must be 'work-area'!");
   id = el.getAttribute("id");
   for (int i = 0; i < el.getChildNodes().getLength(); i++) {
     if (el.getChildNodes().item(i).getNodeType() != Node.ELEMENT_NODE) continue;
     Element e = (Element) el.getChildNodes().item(i);
     if ("caption".equals(e.getNodeName())) {
       if (e.getFirstChild() == null) throw new CMCConfigurationException("Caption must be set");
       this.caption = e.getFirstChild().getNodeValue();
       //				log.debug("Caption is: " + this.caption);
     } else if ("link".equals(e.getNodeName())) {
       if (e.getFirstChild() == null) throw new CMCConfigurationException("Link must be set");
       setUrl(e.getFirstChild().getNodeValue());
       //				log.debug("URL is: " + this.url);
     } else if ("icon".equals(e.getNodeName())) {
       if (e.getFirstChild() == null) throw new CMCConfigurationException("Icon must be set");
       this.icon = e.getFirstChild().getNodeValue();
       if (icon.endsWith("gif")) {
         icon = icon.replaceAll(".gif", ".png");
       }
       //				log.debug("Icon is: " + this.icon);
     } else if ("modules".equals(e.getNodeName())) {
       log.debug("we are loading modules...");
       log.debug("e.getChildNodes().getLength() = " + e.getChildNodes().getLength());
       for (int k = 0; k < e.getChildNodes().getLength(); k++) {
         Node n = e.getChildNodes().item(k);
         if (n.getNodeType() != Node.ELEMENT_NODE) continue;
         if (!"module".equals(n.getNodeName())) continue;
         Element m = (Element) n;
         String modulename = m.getAttribute("name");
         modulesList.add(core.getModule(modulename));
         modulesMap.put(modulename, core.getModule(modulename));
       }
     }
   }
   if (url == null) {
     throw new CMCConfigurationException("Url is not set!");
   } else {
     if (url.startsWith("http://") || url.startsWith("/")) {
       log.debug("url is an external link! URL= " + url);
     } else {
       if (url.indexOf("?") > -1) {
         url += "&workarea=" + id;
       } else {
         url += "?workarea=" + id;
       }
     }
     log.debug("url = " + url);
   }
   log.debug("modulesList = " + modulesList);
 }
Exemple #2
0
  public String getTransformedURL(Core core) {
    String result = getUrl();
    log.debug("URL before transformation: " + url);
    // index.jsp?param=${type}&param2=${id}&param3=${fieldname}
    Pattern p = Pattern.compile("(?!\\$\\{)([A-Za-z0-9]+?)(?:\\})", Pattern.CASE_INSENSITIVE);

    List<String> list = new ArrayList<String>();
    Matcher m = p.matcher(url);
    while (m.find()) {
      String tokenpart = m.group(1);
      log.debug("tokenpart = " + tokenpart);
      list.add(tokenpart);
    }
    log.debug("We found parameters: " + list);

    for (String param : list) {
      if ("user".equalsIgnoreCase(param)) {
        result = result.replaceAll("\\$\\{user\\}", core.getLoggedInUser().getUserName());
      }
    }

    log.debug("Returning URL: " + result);

    return result;
  }