public String processSpecificationPost()

in connectors/documentum/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/DCTM/DCTM.java [3241:3599]


  public String processSpecificationPost(IPostParameters variableContext, Locale locale, Specification ds,
    int connectionSequenceNumber)
    throws ManifoldCFException
  {
    String x;
    String[] y;
    
    String seqPrefix = "s"+connectionSequenceNumber+"_";

    x = variableContext.getParameter(seqPrefix+"pathcount");
    if (x != null)
    {
      // Delete all path specs first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_LOCATION))
          ds.removeChild(i);
      	else
          i++;
      }

      // Find out how many children were sent
      int pathCount = Integer.parseInt(x);
      // Gather up these
      i = 0;
      while (i < pathCount)
      {
      	String pathDescription = "_"+Integer.toString(i);
      	String pathOpName = seqPrefix+"pathop"+pathDescription;
        String pathName = seqPrefix+"specpath"+pathDescription;
      	x = variableContext.getParameter(pathOpName);
      	if (x != null && x.equals("Delete"))
      	{
          // Skip to the next
          i++;
          continue;
      	}
      	// Path inserts won't happen until the very end
      	String path = variableContext.getParameter(pathName);
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_LOCATION);
      	node.setAttribute("path",path);
      	ds.addChild(ds.getChildCount(),node);
      	i++;
      }

      // See if there's a global add operation
      String op = variableContext.getParameter(seqPrefix+"pathop");
      if (op != null && op.equals("Add"))
      {
      	String path = variableContext.getParameter(seqPrefix+"specpath");
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_LOCATION);
      	node.setAttribute("path",path);
      	ds.addChild(ds.getChildCount(),node);
      }
      else if (op != null && op.equals("Up"))
      {
      	// Strip off end
      	String path = variableContext.getParameter(seqPrefix+"specpath");
      	int k = path.lastIndexOf("/");
      	if (k != -1)
          path = path.substring(0,k);
      	if (path.length() == 0)
          path = "/";
      	currentContext.save(seqPrefix+"specpath",path);
      }
      else if (op != null && op.equals("AddToPath"))
      {
      	String path = variableContext.getParameter(seqPrefix+"specpath");
      	String addon = variableContext.getParameter(seqPrefix+"pathaddon");
      	if (addon != null && addon.length() > 0)
      	{
          if (path.length() == 1)
            path = "/" + addon;
          else
            path += "/" + addon;
      	}
      	currentContext.save(seqPrefix+"specpath",path);
      }
    }

    x = variableContext.getParameter(seqPrefix+"specsecurity");
    if (x != null)
    {
      // Delete all security entries first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals("security"))
          ds.removeChild(i);
      	else
          i++;
      }

      SpecificationNode node = new SpecificationNode("security");
      node.setAttribute("value",x);
      ds.addChild(ds.getChildCount(),node);

    }

    x = variableContext.getParameter(seqPrefix+"tokencount");
    if (x != null)
    {
      // Delete all file specs first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals("access"))
          ds.removeChild(i);
      	else
          i++;
      }

      int accessCount = Integer.parseInt(x);
      i = 0;
      while (i < accessCount)
      {
      	String accessDescription = "_"+Integer.toString(i);
      	String accessOpName = seqPrefix+"accessop"+accessDescription;
      	x = variableContext.getParameter(accessOpName);
      	if (x != null && x.equals("Delete"))
      	{
          // Next row
          i++;
          continue;
      	}
      	// Get the stuff we need
      	String accessSpec = variableContext.getParameter(seqPrefix+"spectoken"+accessDescription);
      	SpecificationNode node = new SpecificationNode("access");
      	node.setAttribute("token",accessSpec);
      	ds.addChild(ds.getChildCount(),node);
      	i++;
      }

      String op = variableContext.getParameter(seqPrefix+"accessop");
      if (op != null && op.equals("Add"))
      {
      	String accessspec = variableContext.getParameter(seqPrefix+"spectoken");
      	SpecificationNode node = new SpecificationNode("access");
      	node.setAttribute("token",accessspec);
      	ds.addChild(ds.getChildCount(),node);
      }
    }

    x = variableContext.getParameter(seqPrefix+"datatype_count");
    if (x != null)
    {
      // Delete all file specs first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_OBJECTTYPE))
          ds.removeChild(i);
      	else
          i++;
      }

      int dataCount = Integer.parseInt(x);
      
      y = variableContext.getParameterValues(seqPrefix+"specfiletype");
      Set<String> checkedTypes = new HashSet<String>();
      if (y != null)
      {
        for (String s : y)
        {
          checkedTypes.add(s);
        }
      }
      
      // Loop through specs
      for (int k = 0; k < dataCount; k++)
      {
      	String fileType = variableContext.getParameter(seqPrefix+"datatype_"+k);
        if (checkedTypes.contains(fileType))
        {
          SpecificationNode node = new SpecificationNode(CONFIG_PARAM_OBJECTTYPE);
          node.setAttribute("token",fileType);
          String isAll = variableContext.getParameter(seqPrefix+"specfileallattrs_"+k);
          if (isAll != null)
            node.setAttribute("all",isAll);
          String[] z = variableContext.getParameterValues(seqPrefix+"specfileattrs_"+k);
          if (z != null)
          {
            for (int kk = 0; kk < z.length; kk++)
            {
              SpecificationNode attrNode = new SpecificationNode(CONFIG_PARAM_ATTRIBUTENAME);
              attrNode.setAttribute("attrname",z[kk]);
              node.addChild(node.getChildCount(),attrNode);
            }
          }
          x = variableContext.getParameter(seqPrefix+"filter_"+k+"_count");
          int filterCount = Integer.parseInt(x);
          for (int kk = 0; kk < filterCount; kk++)
          {
            String op = variableContext.getParameter(seqPrefix+"filter_"+k+"_"+kk+"_op");
            if (op == null || !op.equals("Delete"))
            {
              String attributeName = variableContext.getParameter(seqPrefix+"filter_"+k+"_"+kk+"_name");
              String operation = variableContext.getParameter(seqPrefix+"filter_"+k+"_"+kk+"_operation");
              String value = variableContext.getParameter(seqPrefix+"filter_"+k+"_"+kk+"_value");
              SpecificationNode filterNode = new SpecificationNode(CONFIG_PARAM_FILTER);
              filterNode.setAttribute("name",attributeName);
              filterNode.setAttribute("op",operation);
              filterNode.setAttribute("value",value);
              node.addChild(node.getChildCount(),filterNode);
            }
          }
          // Add at the end
          x = variableContext.getParameter(seqPrefix+"filter_"+k+"_op");
          if (x != null && x.equals("Add"))
          {
            String attributeName = variableContext.getParameter(seqPrefix+"filter_"+k+"_name");
            String operation = variableContext.getParameter(seqPrefix+"filter_"+k+"_operation");
            String value = variableContext.getParameter(seqPrefix+"filter_"+k+"_value");
            SpecificationNode filterNode = new SpecificationNode(CONFIG_PARAM_FILTER);
            filterNode.setAttribute("name",attributeName);
            filterNode.setAttribute("op",operation);
            filterNode.setAttribute("value",value);
            node.addChild(node.getChildCount(),filterNode);
          }
          ds.addChild(ds.getChildCount(),node);
        }
      }
    }

    if (variableContext.getParameter(seqPrefix+"specmimetype_posted") != null)
    {
      String all = variableContext.getParameter(seqPrefix+"specmimetypeall");
      y = variableContext.getParameterValues(seqPrefix+"specmimetype");
      // Delete all file specs first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_FORMAT) || sn.getType().equals(CONFIG_PARAM_FORMAT_ALL))
          ds.removeChild(i);
      	else
          i++;
      }
      
      SpecificationNode n2 = new SpecificationNode(CONFIG_PARAM_FORMAT_ALL);
      n2.setAttribute("value",(all!=null&&all.equals("true"))?"true":"false");
      ds.addChild(ds.getChildCount(),n2);

      // Loop through specs
      if (y != null)
      {
	i = 0;
	while (i < y.length)
	{
	  String fileType = y[i++];
	  SpecificationNode node = new SpecificationNode(CONFIG_PARAM_FORMAT);
	  node.setAttribute("value",fileType);
	  ds.addChild(ds.getChildCount(),node);
	}
      }
    }

    x = variableContext.getParameter(seqPrefix+"specmaxdoclength");
    if (x != null)
    {
      // Delete all security entries first
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_MAXLENGTH))
          ds.removeChild(i);
      	else
          i++;
      }

      if (x.length() > 0)
      {
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_MAXLENGTH);
      	node.setAttribute("value",x);
      	ds.addChild(ds.getChildCount(),node);
      }
    }

    String xc = variableContext.getParameter(seqPrefix+"specpathnameattribute");
    if (xc != null)
    {
      // Delete old one
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_PATHNAMEATTRIBUTE))
          ds.removeChild(i);
      	else
          i++;
      }
      if (xc.length() > 0)
      {
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_PATHNAMEATTRIBUTE);
      	node.setAttribute("value",xc);
      	ds.addChild(ds.getChildCount(),node);
      }
    }

    xc = variableContext.getParameter(seqPrefix+"specmappingcount");
    if (xc != null)
    {
      // Delete old spec
      int i = 0;
      while (i < ds.getChildCount())
      {
      	SpecificationNode sn = ds.getChild(i);
      	if (sn.getType().equals(CONFIG_PARAM_PATHMAP))
          ds.removeChild(i);
      	else
          i++;
      }

      // Now, go through the data and assemble a new list.
      int mappingCount = Integer.parseInt(xc);

      // Gather up these
      i = 0;
      while (i < mappingCount)
      {
      	String pathDescription = "_"+Integer.toString(i);
      	String pathOpName = seqPrefix+"specmappingop"+pathDescription;
      	xc = variableContext.getParameter(pathOpName);
      	if (xc != null && xc.equals("Delete"))
      	{
          // Skip to the next
          i++;
          continue;
      	}
      	// Inserts won't happen until the very end
      	String match = variableContext.getParameter(seqPrefix+"specmatch"+pathDescription);
      	String replace = variableContext.getParameter(seqPrefix+"specreplace"+pathDescription);
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_PATHMAP);
      	node.setAttribute("match",match);
      	node.setAttribute("replace",replace);
      	ds.addChild(ds.getChildCount(),node);
      	i++;
      }

      // Check for add
      xc = variableContext.getParameter(seqPrefix+"specmappingop");
      if (xc != null && xc.equals("Add"))
      {
      	String match = variableContext.getParameter(seqPrefix+"specmatch");
      	String replace = variableContext.getParameter(seqPrefix+"specreplace");
      	SpecificationNode node = new SpecificationNode(CONFIG_PARAM_PATHMAP);
      	node.setAttribute("match",match);
      	node.setAttribute("replace",replace);
      	ds.addChild(ds.getChildCount(),node);
      }
    }
    return null;
  }