public String getChannelTitle(String instanceId) {
   OrganizationController orga = new OrganizationController();
   ComponentInstLight instance = orga.getComponentInstLight(instanceId);
   if (instance != null) {
     return instance.getLabel();
   }
   return "";
 }
 private boolean isTemplateVisibleAccordingToApplication(
     PublicationTemplate template, GlobalContext context, OrganisationController oc) {
   List<String> restrictedApplications = template.getApplications();
   String componentName = context.getComponentName();
   if (StringUtil.isDefined(context.getComponentId())) {
     ComponentInstLight component = oc.getComponentInstLight(context.getComponentId());
     componentName = component.getName();
   }
   return restrictedApplications.contains(componentName);
 }
 @Test
 public void getComponentIdForMainURL() {
   MockHttpServletRequest request =
       new MockHttpServletRequest(
           "GET", "http://localhost:8000/silverpeas/Rtoolbox/toolbox8/Main");
   request.setPathInfo("/toolbox8/Main");
   OrganizationController controller = getOrganisationController();
   ComponentInstLight component = mock(ComponentInstLight.class);
   String spaceId = "12";
   when(component.getDomainFatherId()).thenReturn(spaceId);
   when(controller.getComponentInstLight("toolbox8")).thenReturn(component);
   SilverpeasWebUtil util = new SilverpeasWebUtil();
   String[] result = util.getComponentId(request);
   String[] expResult = new String[] {"12", "toolbox8", "Main"};
   assertArrayEquals(expResult, result);
 }
  public String getContextualDiv() {
    String spaceIds = "";
    String componentId = gef.getComponentId();
    OrganizationController oc = gef.getMainSessionController().getOrganizationController();
    if (StringUtil.isDefined(componentId)) {
      List<SpaceInst> spaces = oc.getSpacePathToComponent(componentId);

      for (SpaceInst spaceInst : spaces) {
        String spaceId = spaceInst.getId();
        if (!spaceId.startsWith("WA")) {
          spaceId = "WA" + spaceId;
        }
        spaceIds += spaceId + " ";
      }
    }

    if (StringUtil.isDefined(spaceIds)) {
      ComponentInstLight component = oc.getComponentInstLight(componentId);
      return "<div class=\"" + spaceIds + component.getName() + " " + componentId + "\">";
    }
    return null;
  }
  private void indexForm(RecordSet recordSet) throws WebPagesException {
    try {
      if (recordSet == null) {
        PublicationTemplate pub = getXMLTemplate();
        recordSet = pub.getRecordSet();
      }
    } catch (Exception e) {
      throw new WebPagesException(
          "WebPagesSessionController.indexForm()",
          SilverpeasException.ERROR,
          "webPages.EX_CANT_GET_FORM",
          e);
    }
    // index data
    try {
      FullIndexEntry indexEntry =
          new FullIndexEntry(getComponentId(), "Component", getComponentId());
      indexEntry.setCreationDate(new Date());
      indexEntry.setCreationUser(getUserId());
      indexEntry.setTitle(getComponentLabel());
      ComponentInstLight component =
          getOrganizationController().getComponentInstLight(getComponentId());
      if (component != null) {
        indexEntry.setPreView(component.getDescription());
      }

      recordSet.indexRecord("0", getUsedXMLTemplateShortname(), indexEntry);

      IndexEngineProxy.addIndexEntry(indexEntry);
    } catch (FormException e) {
      throw new WebPagesException(
          "WebPagesSessionController.indexForm()",
          SilverpeasException.ERROR,
          "webPages.EX_CANT_INDEX_DATA",
          e);
    }
  }
 String getPackage(ComponentInstLight compoInst) {
   String packageName = firstLetterToLowerCase(compoInst.getName());
   if ("toolbox".equalsIgnoreCase(packageName)) {
     return "kmelia";
   }
   if ("bookmark".equalsIgnoreCase(packageName)) {
     return "webSites";
   }
   if ("pollingStation".equalsIgnoreCase(packageName)) {
     return "survey";
   }
   if ("webPages".equalsIgnoreCase(packageName)
       || "resourcesManager".equalsIgnoreCase(packageName)
       || "mydb".equalsIgnoreCase(packageName)
       || "formsOnline".equalsIgnoreCase(packageName)
       || "suggestionBox".equalsIgnoreCase(packageName)) {
     return packageName.toLowerCase();
   }
   return packageName;
 }
 String getClassName(ComponentInstLight compoInst) {
   String name = compoInst.getName();
   String className = firstLetterToUpperCase(name);
   if ("toolbox".equalsIgnoreCase(name)) {
     return "Kmelia";
   }
   if ("bookmark".equalsIgnoreCase(name)) {
     return "WebSites";
   }
   if ("pollingStation".equalsIgnoreCase(name)) {
     return "Survey";
   }
   if ("webPages".equalsIgnoreCase(name)) {
     return "WebPages";
   }
   if ("mydb".equalsIgnoreCase(name)) {
     return "MyDB";
   }
   return className;
 }
  public void indexComponent(String spaceId, ComponentInstLight compoInst) {
    SilverTrace.info(
        silvertraceModule,
        "ApplicationIndexer.indexComponent()",
        "applicationIndexer.MSG_START_INDEXING_COMPONENT",
        "component = " + compoInst.getLabel());

    // index component info
    admin.indexComponent(compoInst.getId());

    // index component content
    ComponentIndexerInterface componentIndexer = getIndexer(compoInst);
    if (componentIndexer != null) {
      try {
        ComponentContext componentContext =
            mainSessionController.createComponentContext(spaceId, compoInst.getId());
        componentIndexer.index(mainSessionController, componentContext);
      } catch (Exception e) {
        SilverTrace.error(
            silvertraceModule,
            "ApplicationIndexer.indexComponent()",
            "applicationIndexer.EX_INDEXING_COMPONENT_FAILED",
            "component = " + compoInst.getLabel(),
            e);
      }
      SilverTrace.info(
          silvertraceModule,
          "ApplicationIndexer.indexComponent()",
          "applicationIndexer.MSG_END_INDEXING_COMPONENT",
          "component = " + compoInst.getLabel());
    } else {
      SilverTrace.info(
          silvertraceModule,
          "ApplicationIndexer.indexComponent()",
          "applicationIndexer.MSG_COMPONENT_INDEXER_NOT_FOUND",
          "component = " + compoInst.getLabel());
    }
  }
 ComponentIndexerInterface getIndexer(ComponentInstLight compoInst) {
   ComponentIndexerInterface componentIndexer;
   String compoName = firstLetterToUpperCase(compoInst.getName());
   String className = getClassName(compoInst);
   String packageName = getPackage(compoInst);
   try {
     componentIndexer =
         loadIndexer("com.stratelia.webactiv." + packageName + '.' + className + "Indexer");
     if (componentIndexer == null) {
       componentIndexer =
           loadIndexer("com.silverpeas." + packageName + '.' + className + "Indexer");
     }
     if (componentIndexer == null) {
       componentIndexer =
           loadIndexer("com.silverpeas.components." + packageName + '.' + className + "Indexer");
     }
     if (componentIndexer == null) {
       componentIndexer =
           loadIndexer("org.silverpeas." + packageName + '.' + className + "Indexer");
     }
     if (componentIndexer == null) {
       componentIndexer =
           loadIndexer("org.silverpeas.components." + packageName + '.' + className + "Indexer");
     }
   } catch (InstantiationException e) {
     SilverTrace.warn(
         silvertraceModule,
         "ApplicationIndexer.getIndexer()",
         "applicationIndexer.EX_INDEXING_PERSONAL_COMPONENT_FAILED",
         "component = " + compoName,
         e);
     componentIndexer = new ComponentIndexerAdapter();
   } catch (IllegalAccessException e) {
     SilverTrace.warn(
         silvertraceModule,
         "ApplicationIndexer.getIndexer()",
         "applicationIndexer.EX_INDEXING_PERSONAL_COMPONENT_FAILED",
         "component = " + compoName,
         e);
     componentIndexer = new ComponentIndexerAdapter();
   }
   if (componentIndexer == null) {
     SilverTrace.warn(
         silvertraceModule,
         "ApplicationIndexer.getIndexer()",
         "applicationIndexer.EX_INDEXER_COMPONENT_NOT_FOUND",
         "component = "
             + compoName
             + " with classes com.stratelia.webactiv."
             + packageName
             + "."
             + className
             + "Indexer and com.silverpeas."
             + packageName
             + "."
             + className
             + "Indexer");
     return new ComponentIndexerAdapter();
   }
   return componentIndexer;
 }