當前位置: 首頁>>代碼示例>>Java>>正文


Java Builder類代碼示例

本文整理匯總了Java中nu.xom.Builder的典型用法代碼示例。如果您正苦於以下問題:Java Builder類的具體用法?Java Builder怎麽用?Java Builder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Builder類屬於nu.xom包,在下文中一共展示了Builder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: update

import nu.xom.Builder; //導入依賴的package包/類
@Test
public void update()
    throws ValidityException, ParsingException, IOException, MojoExecutionException {
  Document pom = new Builder().build(new File(new File("src/it/reflector"), "pom.xml"));
  Artifact artifact = new DefaultArtifact(
      "net.stickycode",
      "sticky-coercion",
      "jar",
      "",
      "[3.1,4)");

  new StickyBoundsMojo().updateDependency(pom, artifact, "[3.6,4)");
  XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");

  Nodes versions = pom.query("//mvn:version", context);
  assertThat(versions.size()).isEqualTo(3);
  Nodes nodes = pom.query("//mvn:version[text()='[3.6,4)']", context);
  assertThat(nodes.size()).isEqualTo(1);
  Node node = nodes.get(0);
  assertThat(node.getValue()).isEqualTo("[3.6,4)");
}
 
開發者ID:stickycode,項目名稱:bounds-maven-plugin,代碼行數:22,代碼來源:StickyBoundsMojoIntegrationTest.java

示例2: updateWithClassifier

import nu.xom.Builder; //導入依賴的package包/類
@Test
public void updateWithClassifier()
    throws ValidityException, ParsingException, IOException, MojoExecutionException {
  Document pom = new Builder().build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml"))));
  Artifact artifact = new DefaultArtifact(
      "net.stickycode",
      "sticky-coercion",
      "jar",
      "",
      "[2.1,4)");
  
  new StickyBoundsMojo().updateDependency(pom, artifact, "[2.6,3)");
  XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");
  
  Nodes versions = pom.query("//mvn:version", context);
  assertThat(versions.size()).isEqualTo(4);
  Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context);
  assertThat(nodes.size()).isEqualTo(1);
  Node node = nodes.get(0);
  assertThat(node.getValue()).isEqualTo("[2.6,3)");
}
 
開發者ID:stickycode,項目名稱:bounds-maven-plugin,代碼行數:22,代碼來源:StickyBoundsMojoIntegrationTest.java

示例3: test

import nu.xom.Builder; //導入依賴的package包/類
/**
 * Tests that the schema registers a iso639 field and that the needed jar
 * file has been successfully loaded into Solr.
 */
@Test
public void test() {
    try {
        InputStream source = new URL(QUERY).openStream();
        Document doc = new Builder().build(source);
        Nodes nodes = doc.query(FACET_PATH);

        if (nodes.size() != 1) {
            fail("Didn't find the facet.field facet in the response XML");
        }

        assertEquals("iso639", nodes.get(0).getValue().trim());
    } catch (Exception details) {
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Error connecting to integration server", details);
        }

        fail(details.getMessage());
    }
}
 
開發者ID:ksclarke,項目名稱:solr-iso639-filter,代碼行數:25,代碼來源:ISO639SolrIntegrationTest.java

示例4: getTagList

import nu.xom.Builder; //導入依賴的package包/類
public static String getTagList(Project pjr){
	try {
	  String filepath = FileStorage.JN_DOCPATH + ".projects";
	  Builder builder = new Builder();
    Document projects = builder.build(new InputStreamReader(new FileInputStream(filepath)), "UTF-8");
 	String taglist="";
 	Elements prjs = projects.getRootElement().getChildElements("project");
 	  for (int i = 0; i < prjs.size(); i++) {
 		  String pid = ((Element) prjs.get(i)).getAttribute("id").getValue();
 		  if (pid.equals(pjr.getID())){
 			  Element tags=prjs.get(i).getFirstChildElement("tags");
 			  Elements tagli=tags.getChildElements("tag");
 			  if (tagli.size()<=0) return "no";
 			  for (int j = 0; j < tagli.size(); j++) {
 				  taglist+=tagli.get(j).getAttributeValue("name")+" - ";
 			  }
 			break;  
 		  }
 	  }
 	  return taglist;
	} catch (Exception e) {
		Util.error(e);
		return "no";
	}
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:26,代碼來源:ProjectImpl.java

示例5: loadXmlDefinition

import nu.xom.Builder; //導入依賴的package包/類
/**
 * Use the CacheXmlGenerator to create XML from the entity associated with
 * the current cache.
 * 
 * @param element Name of the XML element to search for.
 * @param attributes
 *          Attributes of the element that should match, for example "name" or
 *          "id" and the value they should equal.
 * 
 * @return XML string representation of the entity.
 */
private final String loadXmlDefinition(final String element, final Map<String, String> attributes) {
  final Cache cache = CacheFactory.getAnyInstance();
  Document document = null;

  try {
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    CacheXmlGenerator.generate(cache, printWriter, false, false, false);
    printWriter.close();

    // Remove the DOCTYPE line when getting the string to prevent
    // errors when trying to locate the DTD.
    String xml = stringWriter.toString().replaceFirst("<!DOCTYPE.*>", "");
    document = new Builder(false).build(xml, null);

  } catch (ValidityException vex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", vex);

  } catch (ParsingException pex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", pex);
    
  } catch (IOException ioex) {
    cache.getLogger().error("Could not parse XML when creating XMLEntity", ioex);
  }
  
  Nodes nodes = document.query(createQueryString(element, attributes));
  if (nodes.size() != 0) {
    return nodes.get(0).toXML();
  }
  
  cache.getLogger().warning("No XML definition could be found with name=" + element + " and attributes=" + attributes);
  return null;
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:45,代碼來源:XmlEntity.java

示例6: prettyXml

import nu.xom.Builder; //導入依賴的package包/類
public static String prettyXml(String xml, String firstLine){
      try {
         
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         Serializer serializer = new Serializer(out);
         serializer.setIndent(2);
         if(firstLine != null){
            serializer.write(new Builder().build(firstLine + xml, ""));            
         } else {
            serializer.write(new Builder().build(xml, ""));
         }
         String ret =  out.toString("UTF-8");
         if(firstLine != null){
            return ret.substring(firstLine.length() , ret.length()).trim();
         } else {
            return ret;            
         }
      } catch (Exception e) {
//         ExceptionHandler.handle(e);
         return xml;
      }
   }
 
開發者ID:nextinterfaces,項目名稱:http4e,代碼行數:23,代碼來源:JunkUtils.java

示例7: setXmlRootAttrToArray

import nu.xom.Builder; //導入依賴的package包/類
/**
 * 設置xml的根節點元素為Array結構 例如<datas class="array"></datas>
 * 
 * @param xml
 * @return
 */
private static String setXmlRootAttrToArray(String xml) {
	Element root;
	Document doc;
	try {
		doc = (new Builder()).build(new StringReader(xml));
		root = doc.getRootElement();
		Attribute attr = root.getAttribute("class");
		root.addAttribute(new Attribute("class", "array"));
		xml = root.toXML();
	} catch (Exception e) {
		e.printStackTrace();
	}
	return xml;

}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:22,代碼來源:JSONXOperUtils.java

示例8: initialize

import nu.xom.Builder; //導入依賴的package包/類
@Override
public void initialize(final UimaContext context) throws ResourceInitializationException {
	super.initialize(context);
	dlinaDirectory = new File(dlinaDirectoryName);
	if (!dlinaDirectory.isDirectory())
		throw new ResourceInitializationException();

	for (File f : dlinaDirectory.listFiles(new FilenameFilter() {
		@Override
		public boolean accept(File dir, String name) {
			return name.endsWith(".xml");
		}
	})) {
		try {
			Builder parser = new Builder();
			Document doc = parser.build(new FileInputStream(f));
			String sourceUrl = doc.getRootElement().getFirstChildElement("header", namespaceUri)
					.getFirstChildElement("source", namespaceUri).getValue();
			String sourceId = sourceUrl.substring(56).replace("/data", "");
			fileIndex.put(sourceId, doc);
		} catch (Exception e) {
			throw new ResourceInitializationException(e);
		}
	}
}
 
開發者ID:quadrama,項目名稱:DramaNLP,代碼行數:26,代碼來源:ReadDlinaMetadata.java

示例9: testCanReadFromElementOfLargerDocument

import nu.xom.Builder; //導入依賴的package包/類
public void testCanReadFromElementOfLargerDocument() throws Exception {
    final String xml = ""
        + "<big>"
        + "  <small>"
        + "    <tiny/>"
        + "  </small>"
        + "  <small-two>"
        + "  </small-two>"
        + "</big>";
    final Document document = new Builder().build(new StringReader(xml));
    final Element element = document.getRootElement().getFirstChildElement("small");

    final HierarchicalStreamReader xmlReader = new XomReader(element);
    assertEquals("small", xmlReader.getNodeName());
    xmlReader.moveDown();
    assertEquals("tiny", xmlReader.getNodeName());
}
 
開發者ID:x-stream,項目名稱:xstream,代碼行數:18,代碼來源:XomReaderTest.java

示例10: main

import nu.xom.Builder; //導入依賴的package包/類
public static void main(String[] args) {
    
    try {
        Document doc = new Builder().build("http://www.ibiblio.org/xml/examples/shakespeare/much_ado.xml");
        XOMXPath xpath = new XOMXPath("PLAY/ACT/SCENE/SPEECH/SPEAKER");
        
        long start = System.currentTimeMillis();
        
        int count = 0;
        for (int i = 0; i < 1000; i++) {
            Element speaker = (Element) xpath.selectSingleNode(doc);
            count += (speaker == null ? 0 : 1);
        }
        
        long end = System.currentTimeMillis();
        System.out.println((end - start));
        System.out.println(count);
        
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
 
開發者ID:jaxen-xpath,項目名稱:jaxen,代碼行數:23,代碼來源:XOMPerformance.java

示例11: updateTheClassifier

import nu.xom.Builder; //導入依賴的package包/類
@Test
public void updateTheClassifier()
    throws ValidityException, ParsingException, IOException, MojoExecutionException {
  Document pom = new Builder().build(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("classifiers.xml"))));
  Artifact artifact = new DefaultArtifact(
      "net.stickycode",
      "sticky-coercion",
      "jar",
      "test-jar",
      "[2.1,4)");

  new StickyBoundsMojo().updateDependency(pom, artifact, "[2.6,3)");
  XPathContext context = new XPathContext("mvn", "http://maven.apache.org/POM/4.0.0");

  Nodes versions = pom.query("//mvn:version", context);
  assertThat(versions.size()).isEqualTo(4);
  Nodes nodes = pom.query("//mvn:version[text()='[2.6,3)']", context);
  assertThat(nodes.size()).isEqualTo(1);
  Node node = nodes.get(0);
  assertThat(node.getValue()).isEqualTo("[2.6,3)");
}
 
開發者ID:stickycode,項目名稱:bounds-maven-plugin,代碼行數:22,代碼來源:StickyBoundsMojoIntegrationTest.java

示例12: SettingsManager

import nu.xom.Builder; //導入依賴的package包/類
/**
 * Constructs the class. Requires settings.xml to be present to run
 */
public SettingsManager() {
    String currentDir = System.getProperty("user.dir");
    String settingDir = currentDir + "/settings/";
    File f = new File(settingDir + "settings.xml");
    if (f.exists() && !f.isDirectory()) {
        try {
            Builder parser = new Builder();
            Document doc   = parser.build(f);
            Element root   = doc.getRootElement();

            Element eUsername = root.getFirstChildElement("Username");
            username = eUsername.getValue();

            Element ePassword = root.getFirstChildElement("Password");
            password = ePassword.getValue();

            requiresAuth = true;
        } catch (ParsingException|IOException e) {
            e.printStackTrace();
        }
    }
    else {
        requiresAuth = false;
    }
}
 
開發者ID:ajohnston9,項目名稱:ciscorouter,代碼行數:29,代碼來源:SettingsManager.java

示例13: getDocument

import nu.xom.Builder; //導入依賴的package包/類
/**
 * @param path the path of the requested document
 * @return the document that lives under the given path in the ZIP fs.
 * @throws IOException in case of any failure
 */
public Document getDocument(String path) throws IOException {
	Builder builder = new Builder();
	try {
		byte[] documentData = content.get(path);
		if (documentData == null) {
			throw new IOException(
				Messages.getString(
						"ZipFs.invalidDocument",//$NON-NLS-1$
						path)); 
		}
		return builder.build(new ByteArrayInputStream(content.get(path)));
	} catch (ParsingException e) {
		throw new IOException(e);
	}		
}
 
開發者ID:ADHO,項目名稱:dhconvalidator,代碼行數:21,代碼來源:ZipFs.java

示例14: makePublicationStmt

import nu.xom.Builder; //導入依賴的package包/類
/**
 * Make a &lt;publicationStmt&gt;
 * @param document
 * @throws IOException
 */
private void makePublicationStmt(Document document) throws IOException {
	
	Element publicationStmtElement = DocumentUtil.getFirstMatch(
			document, 
			"/tei:TEI/tei:teiHeader/tei:fileDesc/tei:publicationStmt",  //$NON-NLS-1$
			xPathContext);
	
	publicationStmtElement.removeChildren();
	try {
		Document publicationStmtDoc = 
			new Builder().build(
				PropertyKey.publicationStmt.getValue(), TeiNamespace.TEI.toUri());
		publicationStmtElement.getParent().replaceChild(
				publicationStmtElement, publicationStmtDoc.getRootElement().copy());
	}
	catch (ParsingException pe) {
		throw new IOException(pe);
	}
}
 
開發者ID:ADHO,項目名稱:dhconvalidator,代碼行數:25,代碼來源:CommonOutputConverter.java

示例15: getInputDataTypes

import nu.xom.Builder; //導入依賴的package包/類
/**
 * @return available input data types as offered by OxGarage
 * @throws IOException in case of any failure
 */
Document getInputDataTypes() throws IOException {
	String uri = baseURL + CONVERSION_OPERATION;
	ClientResource client = new ClientResource(Context.getCurrent(), Method.GET, uri);

	Representation result = client.get();
	Builder builder = new Builder();
	try {
		Document inputDataTypes = builder.build(result.getStream());
		
		return inputDataTypes;
	}
	catch (ParsingException e) {
		throw new IOException(e);
	}
}
 
開發者ID:ADHO,項目名稱:dhconvalidator,代碼行數:20,代碼來源:OxGarageConversionClient.java


注:本文中的nu.xom.Builder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。