Java Code Examples for org.apache.xpath.objects.XString#EMPTYSTRING

The following examples show how to use org.apache.xpath.objects.XString#EMPTYSTRING . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FuncGenerateId.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int which = getArg0AsNode(xctxt);

  if (DTM.NULL != which)
  {
    // Note that this is a different value than in previous releases
    // of Xalan. It's sensitive to the exact encoding of the node
    // handle anyway, so fighting to maintain backward compatability
    // really didn't make sense; it may change again as we continue
    // to experiment with balancing document and node numbers within
    // that value.
    return new XString("N" + Integer.toHexString(which).toUpperCase());
  }
  else
    return XString.EMPTYSTRING;
}
 
Example 2
Source File: FuncQname.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);
  XObject val;

  if (DTM.NULL != context)
  {
    DTM dtm = xctxt.getDTM(context);
    String qname = dtm.getNodeNameX(context);
    val = (null == qname) ? XString.EMPTYSTRING : new XString(qname);
  }
  else
  {
    val = XString.EMPTYSTRING;
  }

  return val;
}
 
Example 3
Source File: FunctionDef1Arg.java    From j2objc with Apache License 2.0 6 votes vote down vote up
/**
 * Execute the first argument expression that is expected to return a
 * string.  If the argument is null, then get the string value from the
 * current context node.
 *
 * @param xctxt Runtime XPath context.
 *
 * @return The string value of the first argument, or the string value of the
 *         current context node if the first argument is null.
 *
 * @throws javax.xml.transform.TransformerException if an error occurs while
 *                                   executing the argument expression.
 */
protected XMLString getArg0AsString(XPathContext xctxt)
        throws javax.xml.transform.TransformerException
{
  if(null == m_arg0)
  {
    int currentNode = xctxt.getCurrentNode();
    if(DTM.NULL == currentNode)
      return XString.EMPTYSTRING;
    else
    {
      DTM dtm = xctxt.getDTM(currentNode);
      return dtm.getStringValue(currentNode);
    }
    
  }
  else
    return m_arg0.execute(xctxt).xstr();   
}
 
Example 4
Source File: ElemWithParam.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Get the XObject representation of the variable.
 *
 * @param transformer non-null reference to the the current transform-time state.
 * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
 *
 * @return the XObject representation of the variable.
 *
 * @throws TransformerException
 */
public XObject getValue(TransformerImpl transformer, int sourceNode)
        throws TransformerException
{

  XObject var;
  XPathContext xctxt = transformer.getXPathContext();

  xctxt.pushCurrentNode(sourceNode);

  try
  {
    if (null != m_selectPattern)
    {
      var = m_selectPattern.execute(xctxt, sourceNode, this);

      var.allowDetachToRelease(false);
    }
    else if (null == getFirstChildElem())
    {
      var = XString.EMPTYSTRING;
    }
    else
    {

      // Use result tree fragment
      int df = transformer.transformToRTF(this);

      var = new XRTreeFrag(df, xctxt, this);
    }
  }
  finally
  {
    xctxt.popCurrentNode();
  }

  return var;
}
 
Example 5
Source File: FuncNamespace.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);
  
  String s;
  if(context != DTM.NULL)
  {
    DTM dtm = xctxt.getDTM(context);
    int t = dtm.getNodeType(context);
    if(t == DTM.ELEMENT_NODE)
    {
      s = dtm.getNamespaceURI(context);
    }
    else if(t == DTM.ATTRIBUTE_NODE)
    {

      // This function always returns an empty string for namespace nodes.
      // We check for those here.  Fix inspired by Davanum Srinivas.

      s = dtm.getNodeName(context);
      if(s.startsWith("xmlns:") || s.equals("xmlns"))
        return XString.EMPTYSTRING;

      s = dtm.getNamespaceURI(context);
    }
    else
      return XString.EMPTYSTRING;
  }
  else 
    return XString.EMPTYSTRING;
  
  return ((null == s) ? XString.EMPTYSTRING : new XString(s));
}
 
Example 6
Source File: FuncSubstringAfter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XMLString s1 = m_arg0.execute(xctxt).xstr();
  XMLString s2 = m_arg1.execute(xctxt).xstr();
  int index = s1.indexOf(s2);

  return (-1 == index)
         ? XString.EMPTYSTRING
         : (XString)s1.substring(index + s2.length());
}
 
Example 7
Source File: FuncLocalPart.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  int context = getArg0AsNode(xctxt);
  if(DTM.NULL == context)
    return XString.EMPTYSTRING;
  DTM dtm = xctxt.getDTM(context);
  String s = (context != DTM.NULL) ? dtm.getLocalName(context) : "";
  if(s.startsWith("#") || s.equals("xmlns"))
    return XString.EMPTYSTRING;

  return new XString(s);
}
 
Example 8
Source File: FuncSubstringBefore.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  String s1 = m_arg0.execute(xctxt).str();
  String s2 = m_arg1.execute(xctxt).str();
  int index = s1.indexOf(s2);

  return (-1 == index)
         ? XString.EMPTYSTRING : new XString(s1.substring(0, index));
}
 
Example 9
Source File: FuncFormatNumb.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  // A bit of an ugly hack to get our context.
  ElemTemplateElement templElem =
    (ElemTemplateElement) xctxt.getNamespaceContext();
  StylesheetRoot ss = templElem.getStylesheetRoot();
  java.text.DecimalFormat formatter = null;
  java.text.DecimalFormatSymbols dfs = null;
  double num = getArg0().execute(xctxt).num();
  String patternStr = getArg1().execute(xctxt).str();

  // TODO: what should be the behavior here??
  if (patternStr.indexOf(0x00A4) > 0)
    ss.error(XSLTErrorResources.ER_CURRENCY_SIGN_ILLEGAL);  // currency sign not allowed

  // this third argument is not a locale name. It is the name of a
  // decimal-format declared in the stylesheet!(xsl:decimal-format
  try
  {
    Expression arg2Expr = getArg2();

    if (null != arg2Expr)
    {
      String dfName = arg2Expr.execute(xctxt).str();
      QName qname = new QName(dfName, xctxt.getNamespaceContext());

      dfs = ss.getDecimalFormatComposed(qname);

      if (null == dfs)
      {
        warn(xctxt, XSLTErrorResources.WG_NO_DECIMALFORMAT_DECLARATION,
             new Object[]{ dfName });  //"not found!!!

        //formatter = new java.text.DecimalFormat(patternStr);
      }
      else
      {

        //formatter = new java.text.DecimalFormat(patternStr, dfs);
        formatter = new java.text.DecimalFormat();

        formatter.setDecimalFormatSymbols(dfs);
        formatter.applyLocalizedPattern(patternStr);
      }
    }

    //else
    if (null == formatter)
    {

      // look for a possible default decimal-format
      dfs = ss.getDecimalFormatComposed(new QName(""));

      if (dfs != null)
      {
        formatter = new java.text.DecimalFormat();

        formatter.setDecimalFormatSymbols(dfs);
        formatter.applyLocalizedPattern(patternStr);
      }
      else
      {
        dfs = new java.text.DecimalFormatSymbols(java.util.Locale.US);

        dfs.setInfinity(Constants.ATTRVAL_INFINITY);
        dfs.setNaN(Constants.ATTRVAL_NAN);

        formatter = new java.text.DecimalFormat();

        formatter.setDecimalFormatSymbols(dfs);

        if (null != patternStr)
          formatter.applyLocalizedPattern(patternStr);
      }
    }

    return new XString(formatter.format(num));
  }
  catch (Exception iae)
  {
    templElem.error(XSLTErrorResources.ER_MALFORMED_FORMAT_STRING,
                    new Object[]{ patternStr });

    return XString.EMPTYSTRING;

    //throw new XSLProcessorException(iae);
  }
}
 
Example 10
Source File: ElemVariable.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Get the XObject representation of the variable.
 *
 * @param transformer non-null reference to the the current transform-time state.
 * @param sourceNode non-null reference to the <a href="http://www.w3.org/TR/xslt#dt-current-node">current source node</a>.
 *
 * @return the XObject representation of the variable.
 *
 * @throws TransformerException
 */
public XObject getValue(TransformerImpl transformer, int sourceNode)
        throws TransformerException
{

  XObject var;
  XPathContext xctxt = transformer.getXPathContext();

  xctxt.pushCurrentNode(sourceNode);
 
  try
  {
    if (null != m_selectPattern)
    {
      var = m_selectPattern.execute(xctxt, sourceNode, this);

      var.allowDetachToRelease(false);
    }
    else if (null == getFirstChildElem())
    {
      var = XString.EMPTYSTRING;
    }
    else
    {

      // Use result tree fragment.
      // Global variables may be deferred (see XUnresolvedVariable) and hence
      // need to be assigned to a different set of DTMs than local variables
      // so they aren't popped off the stack on return from a template.
      int df;

// Bugzilla 7118: A variable set via an RTF may create local
// variables during that computation. To keep them from overwriting
// variables at this level, push a new variable stack.
////// PROBLEM: This is provoking a variable-used-before-set
////// problem in parameters. Needs more study.
try
{
	//////////xctxt.getVarStack().link(0);
	if(m_parentNode instanceof Stylesheet) // Global variable
		df = transformer.transformToGlobalRTF(this);
	else
		df = transformer.transformToRTF(this);
  	}
finally{ 
	//////////////xctxt.getVarStack().unlink(); 
	}

      var = new XRTreeFrag(df, xctxt, this);
    }
  }
  finally
  {      
    xctxt.popCurrentNode();
  }

  return var;
}
 
Example 11
Source File: FuncSubstring.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Execute the function.  The function must return
 * a valid object.
 * @param xctxt The current execution context.
 * @return A valid XObject.
 *
 * @throws javax.xml.transform.TransformerException
 */
public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException
{

  XMLString s1 = m_arg0.execute(xctxt).xstr();
  double start = m_arg1.execute(xctxt).num();
  int lenOfS1 = s1.length();
  XMLString substr;

  if (lenOfS1 <= 0)
    return XString.EMPTYSTRING;
  else
  {
    int startIndex;

    if (Double.isNaN(start))
    {

      // Double.MIN_VALUE doesn't work with math below 
      // so just use a big number and hope I never get caught.
      start = -1000000;
      startIndex = 0;
    }
    else
    {
      start = Math.round(start);
      startIndex = (start > 0) ? (int) start - 1 : 0;
    }

    if (null != m_arg2)
    {
      double len = m_arg2.num(xctxt);
      int end = (int) (Math.round(len) + start) - 1;

      // Normalize end index.
      if (end < 0)
        end = 0;
      else if (end > lenOfS1)
        end = lenOfS1;

      if (startIndex > lenOfS1)
        startIndex = lenOfS1;

      substr = s1.substring(startIndex, end);
    }
    else
    {
      if (startIndex > lenOfS1)
        startIndex = lenOfS1;
      substr = s1.substring(startIndex);
    }
  }

  return (XString)substr; // cast semi-safe
}