当前位置: 首页>>代码示例>>Java>>正文


Java Text类代码示例

本文整理汇总了Java中nu.xom.Text的典型用法代码示例。如果您正苦于以下问题:Java Text类的具体用法?Java Text怎么用?Java Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Text类属于nu.xom包,在下文中一共展示了Text类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMakeText

import nu.xom.Text; //导入依赖的package包/类
@Test
public void testMakeText() throws Exception {
    Assert.assertEquals(whiteSpaceEliminator.makeText("a b").size(), 1);
    Assert.assertTrue(whiteSpaceEliminator.makeText("a b").get(0) instanceof Text);
    Assert.assertEquals(whiteSpaceEliminator.makeText("a b").get(0).toString(), "[nu.xom.Text: a b]");

    Assert.assertEquals(whiteSpaceEliminator.makeText("\ta \t \r \n b ").size(), 1);
    Assert.assertTrue(whiteSpaceEliminator.makeText("\ta \t \r \n b ").get(0) instanceof Text);
    Assert.assertEquals(whiteSpaceEliminator.makeText("\ta \t \r \n b ").get(0).getValue(), "a b");

    Assert.assertEquals(whiteSpaceEliminator.makeText(" \t \r \n ").size(), 0);
}
 
开发者ID:vnebelung,项目名称:ProDisFuzz-Main,代码行数:13,代码来源:XmlWhiteSpaceEliminatorTest.java

示例2: value

import nu.xom.Text; //导入依赖的package包/类
/**
 * Gets the concatenated text nodes of pNode. If pNode is a complex element and pDeep is true, recurses
 * down into pNode and concatenates all text nodes at all levels below and including pNode.
 * @param pNode The target Node.
 * @param pDeep If true, recurse into child nodes to find text nodes.
 * @return The concatenated text nodes as a String, or empty string if none exist.
 */
public String value(Node pNode, boolean pDeep) {
  //Note: previous version had more complicated logic here to short-circuit if this node was an element with
  //a single child text node. Removed for code simplicity: performance should be monitored but is unlikely to be
  //affected.

  // Attribute or Text value
  if(pNode instanceof Attribute) {
    return ((Attribute) pNode).getValue();
  } else if(pNode instanceof Text){
    return ((Text) pNode).getValue();
  }

  // Standard recursive processing to construct text value
  StringBuffer sb = new StringBuffer();
  _value(pNode, sb, pDeep);
  return sb.toString();
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:25,代码来源:ActuateReadOnly.java

示例3: childTextNodesAsDOMList

import nu.xom.Text; //导入依赖的package包/类
/**
 * Generate a DOMList of all the text nodes of pNode, in document order.
 * @param pNode The target node.
 * @param pDeep If true, recurse through child nodes adding their text nodes too.
 * @return A DOMList of text nodes.
 */
@Override
public final DOMList childTextNodesAsDOMList(Node pNode, boolean pDeep){
  DOMList lList = new DOMList();
  for(int i=0; i < pNode.getChildCount(); i++){
    if(pNode.getChild(i) instanceof Text){
      //Wrap text nodes in DOMs
      lList.add(new DOM(pNode.getChild(i)));
    }
    else if (pDeep) {
      //Recurse through non-text children
      lList.addAll(childTextNodesAsDOMList(pNode.getChild(i), true));
    }
  }
  return lList;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:22,代码来源:ActuateReadOnly.java

示例4: NodeWrapper

import nu.xom.Text; //导入依赖的package包/类
/**
 * This constructor is protected: nodes should be created using the wrap
 * factory method on the DocumentWrapper class
 *
 * @param node
 *            The XOM node to be wrapped
 * @param parent
 *            The NodeWrapper that wraps the parent of this node
 * @param index
 *            Position of this node among its siblings
 */
protected NodeWrapper(Node node, NodeWrapper parent, int index) {
	short kind;
	if (node instanceof Element) {
		kind = Type.ELEMENT;
	} else if (node instanceof Text) {
		kind = Type.TEXT;
	} else if (node instanceof Attribute) {
		kind = Type.ATTRIBUTE;
	} else if (node instanceof Comment) {
		kind = Type.COMMENT;
	} else if (node instanceof ProcessingInstruction) {
		kind = Type.PROCESSING_INSTRUCTION;
	} else if (node instanceof Document) {
		kind = Type.DOCUMENT;
	} else {
		throwIllegalNode(node); // moved out of fast path to enable better inlining
		return; // keep compiler happy
	}
	this.nodeKind = kind;
	this.node = node;
	this.parent = parent;
	this.index = index;
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:35,代码来源:NodeWrapper.java

示例5: makeFigureHead

import nu.xom.Text; //导入依赖的package包/类
/**
 * Puts all image descriptions in a head element.
 * @param document
 */
private void makeFigureHead(Document document) {
	Nodes searchResult = document.query("//tei:figure", xPathContext); //$NON-NLS-1$
	for (int i=0; i<searchResult.size(); i++) {
		Element figureElement = (Element)searchResult.get(i);
		StringBuilder descBuilder = new StringBuilder();
		String conc = "";
		for (int j=0; j<figureElement.getChildCount(); j++) {
			Node child = figureElement.getChild(j);
			if (child instanceof Text) {
				descBuilder.append(conc);
				descBuilder.append(((Text)child).getValue());
				conc = " ";
				child.getParent().removeChild(child);
			}
		}
		
		if (descBuilder.length() > 0) {
			Element headElement = figureElement.getFirstChildElement("head", TeiNamespace.TEI.toUri());
			if (headElement == null) {
				headElement = new Element("head", TeiNamespace.TEI.toUri());
				figureElement.appendChild(headElement);
			}
			headElement.appendChild(descBuilder.toString());
		}
	}
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:31,代码来源:CommonOutputConverter.java

示例6: cut

import nu.xom.Text; //导入依赖的package包/类
public static void cut(Element elem) {
	for (Element s : descendants(elem, "salary")) {
		double value = Double.valueOf(s.getValue());
		value /= 2;
		s.removeChildren();
		s.appendChild(new Text(Double.toString(value)));
	}
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:9,代码来源:Cut.java

示例7: getValue

import nu.xom.Text; //导入依赖的package包/类
@Override
public String getValue() {
    // currentElement.getValue() not used as this includes text of child elements, which we don't want.
    final StringBuffer result = new StringBuffer();
    final int childCount = currentElement.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final Node child = currentElement.getChild(i);
        if (child instanceof Text) {
            final Text text = (Text)child;
            result.append(text.getValue());
        }
    }
    return result.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:XomReader.java

示例8: setText

import nu.xom.Text; //导入依赖的package包/类
@Override
public void setText(String text) throws XmlBuilderException {
    try {
        for (int i = 0; i < element.getChildCount(); i++) {
            final Node child = element.getChild(i);
            if (child instanceof Text) {
                ((Text) child).setValue(text);
                return;
            }
        }
        element.appendChild(text);
    } catch (IllegalAddException iae) {
        throw new XmlBuilderException("Unable to set value to " + element, iae);
    }
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:16,代码来源:XomElement.java

示例9: PlayerInit

import nu.xom.Text; //导入依赖的package包/类
/** This is to init the player, but it doesn't directly init the object. Rather, it reads from the file, and returns a player object
 * @param file the filename to read from
 * @throws FileNotFoundException if the file cannot be found
 * @throws FileFormatException when file is formatted wrongly
 * @return the Player red from the file
 */
public static Player PlayerInit (String file) throws FileNotFoundException, FileFormatException{
    File inputFile = new File (file);
    MonsterQuest.game.player.Player player = new MonsterQuest.game.player.Player();
    if (!inputFile.exists())
        throw new FileNotFoundException("The file, " + file + " cannot be found");
    try {
        Builder inputFileBuilder = new Builder();
    
        Document inputFileDoc = inputFileBuilder.build(inputFile);
        Element root = inputFileDoc.getRootElement();
        
        //Read name
        Element nameElement = root.getFirstChildElement("name");
        Text name = (Text) nameElement.getChild(0);
        player.name = name.getValue();
        
        Element gender = root.getFirstChildElement("gender");
        Text genderText = (Text) gender.getChild(0);
        if (genderText.getValue().equals("Boy")) {
            //The player is a boy
            player.setGender(GIRL);
        }
        else if (genderText.getValue().equals("Girl")) {
            //The gender is a girl
            player.setGender(GIRL);
        }
        else {
            throw new FileFormatException("The text is corrupted, when the text should have been either \"Boy\" or \"Girl\", it was" + genderText.getValue());
        }
    } catch (ParsingException pe) {
        //Throw a file format exception, because the file is formatted wrongly.
        throw new FileFormatException("OOPS! File parsed wrongly!" + pe.getMessage());
    } catch (IOException ioe ) {
        
    }
    return player;
}
 
开发者ID:EhWhoAmI,项目名称:Monster-Quest,代码行数:44,代码来源:Player.java

示例10: getNodeType

import nu.xom.Text; //导入依赖的package包/类
/**
 * Gets the generic NodeType of a XOM node.
 * @param pNode An arbitrary XOM node.
 * @return The NodeType of pNode.
 */
public static NodeType getNodeType(Node pNode){
  //Note: order of tests is in likelihood of occurrence
  if (pNode instanceof Element){
    return ELEMENT;
  }
  else if (pNode instanceof Text){
    return TEXT;
  }
  else if (pNode instanceof Attribute){
    return ATTRIBUTE;
  }
  else if (pNode instanceof Comment){
    return COMMENT;
  }
  else if (pNode instanceof Document){
    return DOCUMENT;
  }
  else if (pNode instanceof ProcessingInstruction){
    return PROCESSING_INSTRUCTION;
  }
  else if (pNode instanceof DocType){
    return DOCTYPE;
  }
  else {
    return null;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:33,代码来源:DOM.java

示例11: setText

import nu.xom.Text; //导入依赖的package包/类
public void setText(Node pNode, String pNewText) {

    mDocControl.setDocumentModifiedCount();

    // Cast to Element (checks is an element)
    Element lElement;
    try {
      lElement = (Element)pNode;
    }
    catch (ClassCastException x) {
      if(pNode instanceof Attribute) {
        Attribute lAttr = (Attribute) pNode;
        lAttr.setValue(XFUtil.nvl(pNewText, "")); // XOM cannot set attribute to null, must be empty string
        return;
      }
      else {
        throw new ExInternal("Cannot setText() on xml node of type "+pNode.getClass().getName(), x);
      }
    }

    // Remove all existing child text nodes
    for(int i = 0; i < pNode.getChildCount(); i++){
      Node lChild = pNode.getChild(i);
      if(lChild instanceof Text) {
        ((ParentNode) pNode).removeChild(lChild);
        i--;
      }
    }

    //Insert the new text node as the first child of the target
    if(!XFUtil.isNull(pNewText)) {
      lElement.insertChild(pNewText, 0);
    }
  }
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:35,代码来源:ActuateReadWrite.java

示例12: _value

import nu.xom.Text; //导入依赖的package包/类
/**
 * Concatenates the text nodes of pNode and appends them to pStringBuffer. If pNode is a complex element and pDeep
 * is true, recurses down into pNode and concatenates all text nodes at all levels below and including pNode.
 * @param pNode The target node.
 * @param pStringBuffer The StringBuffer to append the result to.
 * @param pDeep If true, recurse down tree.
 */
private void _value(Node pNode, StringBuffer pStringBuffer, boolean pDeep) {
  for(int i=0; i < pNode.getChildCount(); i++){
    Node c = pNode.getChild(i);
    if(c instanceof Text){
      pStringBuffer.append(((Text)c).getValue());
    } else if (c instanceof Element && pDeep){
      _value(c, pStringBuffer, pDeep);
    }
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:18,代码来源:ActuateReadOnly.java

示例13: childTextNodesAsStringList

import nu.xom.Text; //导入依赖的package包/类
/**
 * Generate a String List of all the text nodes of pNode, in document order.
 * @param pNode The target node.
 * @param pDeep If true, recurse through child nodes adding their text nodes too.
 * @return A List of Strings representing text nodes.
 */
@Override
public final List<String> childTextNodesAsStringList(Node pNode, boolean pDeep){
  List<String> lList = new ArrayList<String>();
  for(int i=0; i < pNode.getChildCount(); i++){
    if(pNode.getChild(i) instanceof Text){
      lList.add(((Text)pNode.getChild(i)).getValue());
    }
    else if (pDeep) {
      lList.addAll(childTextNodesAsStringList(pNode.getChild(i), true));
    }
  }
  return lList;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:20,代码来源:ActuateReadOnly.java

示例14: getValue

import nu.xom.Text; //导入依赖的package包/类
public String getValue()
{
  StringBuffer localStringBuffer = new StringBuffer();
  int i = this.currentElement.getChildCount();
  for (int j = 0; j < i; j++)
  {
    Node localNode = this.currentElement.getChild(j);
    if ((localNode instanceof Text))
      localStringBuffer.append(((Text)localNode).getValue());
  }
  return localStringBuffer.toString();
}
 
开发者ID:mmmsplay10,项目名称:QuizUpWinner,代码行数:13,代码来源:XomReader.java

示例15: validate

import nu.xom.Text; //导入依赖的package包/类
/**
 * @see AbstractBaseComponent#validate()
 */
protected void validate() throws InvalidDDMSException {
	requireAtLeastVersion("4.0.1");
	Util.requireDDMSQName(getXOMElement(), RevisionRecall.getName(getDDMSVersion()));

	boolean hasChildText = false;
	for (int i = 0; i < getXOMElement().getChildCount(); i++) {
		Node child = getXOMElement().getChild(i);
		hasChildText = (hasChildText || (child instanceof Text && !Util.isEmpty(child.getValue().trim())));
	}
	boolean hasNestedElements = (!getLinks().isEmpty() || !getDetails().isEmpty());
	if (hasChildText && hasNestedElements) {
		throw new InvalidDDMSException(
			"A ddms:revisionRecall element must not have both child text and nested elements.");
	}		
	for (Link link : getLinks()) {
		Util.requireDDMSValue("link security attributes", link.getSecurityAttributes());
		link.getSecurityAttributes().requireClassification();
	}
	
	Util.requireDDMSValue("revision ID", getRevisionID());
	if (!REVISION_TYPE_TYPES.contains(getRevisionType()))
		throw new InvalidDDMSException("The revisionType attribute must be one of " + REVISION_TYPE_TYPES);
	if (!Util.isEmpty(getXLinkAttributes().getType()) && !getXLinkAttributes().getType().equals(FIXED_TYPE))
		throw new InvalidDDMSException("The type attribute must have a fixed value of \"" + FIXED_TYPE + "\".");
	if (!Util.isEmpty(getNetwork()))
		ISMVocabulary.requireValidNetwork(getNetwork());
	if (getDDMSVersion().isAtLeast("5.0")) {
		// Check for network is implicit in schema validation.
		if (!Util.isEmpty(getOtherNetwork()))
			throw new InvalidDDMSException("The otherNetwork attribute must not be used after DDMS 4.1.");
	}
	getSecurityAttributes().requireClassification();
	super.validate();
}
 
开发者ID:imintel,项目名称:ddmsence,代码行数:38,代码来源:RevisionRecall.java


注:本文中的nu.xom.Text类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。