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


Java Format類代碼示例

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


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

示例1: doOutput

import org.jdom.output.Format; //導入依賴的package包/類
public void doOutput(List<StudentEntity> students){
	  	Element root = new Element("students");  
        Document document = new Document(root);  
        Iterator<StudentEntity> iter = students.iterator();
        while(iter.hasNext()){
        	StudentEntity student = iter.next();
        	Element studentEl = new Element("student");
        	studentEl.addContent(new Element("studentnumber").setText(student.getStudentNumber()));
        	studentEl.addContent(new Element("studentname").setText(student.getStudentName()));
        	studentEl.addContent(new Element("major").setText(student.getMajor()));
        	studentEl.addContent(new Element("grade").setText(student.getGrade()));
        	studentEl.addContent(new Element("classname").setText(student.getClassName()));
        	studentEl.addContent(new Element("gender").setText(student.getGender()));
        	root.addContent(studentEl);
        }
        try {
	        XMLOutputter out = new XMLOutputter();  
            Format f = Format.getPrettyFormat();  
            f.setEncoding("UTF-8");
            out.setFormat(f);  
            out.output(document, new FileOutputStream(outputFile)); 
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
}
 
開發者ID:ousheobin,項目名稱:My-Javaweb-Homework,代碼行數:26,代碼來源:XMLOutputUtil.java

示例2: writeToXml

import org.jdom.output.Format; //導入依賴的package包/類
/**
 * Writes the JDOM document to the outputstream specified
 * @param out	the outputstream to which the JDOM document should be writed
 * @param validate if true, validate the dom structure before writing. If there is a validation error,
 * 		or the xsd is not in the classpath, an exception will be thrown.
 * @throws ConverterException
 */
public void writeToXml(Pathway pwy, OutputStream out, boolean validate) throws ConverterException {
	Document doc = createJdom(pwy);
	
	//Validate the JDOM document
	if (validate) validateDocument(doc);
	//			Get the XML code
	XMLOutputter xmlcode = new XMLOutputter(Format.getPrettyFormat());
	Format f = xmlcode.getFormat();
	f.setEncoding("UTF-8");
	f.setTextMode(Format.TextMode.PRESERVE);
	xmlcode.setFormat(f);

	try
	{
		//Send XML code to the outputstream
		xmlcode.output(doc, out);
	}
	catch (IOException ie)
	{
		throw new ConverterException(ie);
	}
}
 
開發者ID:PathVisio,項目名稱:pathvisio,代碼行數:30,代碼來源:GpmlFormat2010a.java

示例3: export

import org.jdom.output.Format; //導入依賴的package包/類
/**
 * @param t_objdb
 * @param string
 * @throws IOException 
 * @throws SQLException 
 */
public void export(DBInterface a_objDB, String a_strFileName) throws IOException, SQLException 
{
    this.m_objDB = a_objDB;
    // Erzeugung eines XML-Dokuments
    Document t_objDocument = new Document();
    // Erzeugung des Root-XML-Elements 
    Element t_objRoot = new Element("defaults");
    Namespace xsiNS = Namespace.getNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");        
    t_objRoot.addNamespaceDeclaration(xsiNS);
    this.exportResidues(t_objRoot);
    this.exportPersubstitutions(t_objRoot);
    this.exportIons(t_objRoot);
    this.exportDericatisation(t_objRoot);
    this.exportMolecules(t_objRoot);
    // Und jetzt haengen wir noch das Root-Element an das Dokument
    t_objDocument.setRootElement(t_objRoot);
    // Damit das XML-Dokument schoen formattiert wird holen wir uns ein Format
    Format t_objFormat = Format.getPrettyFormat();
    t_objFormat.setEncoding("iso-8859-1");
    // Erzeugung eines XMLOutputters dem wir gleich unser Format mitgeben
    XMLOutputter t_objExportXML = new XMLOutputter(t_objFormat);
    // Schreiben der XML-Datei in einen String
    FileWriter t_objWriter = new FileWriter(a_strFileName);
    t_objExportXML.output(t_objDocument, t_objWriter );
}
 
開發者ID:glycoinfo,項目名稱:eurocarbdb,代碼行數:32,代碼來源:GeneratorDefault.java

示例4: writeXMLDocument

import org.jdom.output.Format; //導入依賴的package包/類
public static boolean writeXMLDocument(Document doc, String fName) throws FileNotFoundException {
	// Assert.assertNotNull(doc);
	if (doc == null)
	    _log.error("null document");
	else {
	    final long start = System.currentTimeMillis();
	    FileOutputStream fos = new FileOutputStream(fName);
	    try {
	        XMLOutputter outputter = new XMLOutputter();
	        outputter.setFormat(Format.getPrettyFormat());
	        outputter.output(doc, fos);
	        return true;
	    } catch (IOException ioe) {
	        _log.error(ioe);
	    }
	    _log.trace("Document written to " + fName + " in: " + TimeUtility.msToHumanReadableDelta(start));
	}
	return false;
}
 
開發者ID:brunyuriy,項目名稱:crystalvc,代碼行數:20,代碼來源:XMLTools.java

示例5: write

import org.jdom.output.Format; //導入依賴的package包/類
static void write(File file) throws FileNotFoundException, IOException{
	Document document = new Document();
	Element root = new Element("document");
	root.setAttribute("version", Main.VERSION_ID);
	for(Blueprint bp : Main.blueprints){
		
		Element blueprint = writeGraphEditor(bp);
		
		for(VFunction f : bp.getFunctions()){
			blueprint.addContent(writeGraphEditor(f.getEditor()));
		}
		
		root.addContent(blueprint);
	}
	document.setRootElement(root);
	XMLOutputter output = new XMLOutputter();
	Format format = Format.getPrettyFormat();//getRawFormat();
	format.setOmitDeclaration(true);
	format.setOmitEncoding(true);
	format.setTextMode(TextMode.PRESERVE);
	output.setFormat(format);
	output.output(document, new FileOutputStream(file));
}
 
開發者ID:QuinnFreedman,項目名稱:THINK-VPL,代碼行數:24,代碼來源:SaveFileIO.java

示例6: getListOfCollections

import org.jdom.output.Format; //導入依賴的package包/類
/**
 *
 * @param message
 *            the String to extract the list of collections from and assumes
 *            that you are passing in a single invocation message.
 * @return an array of Strings representing all of the fully 'wrapped'
 *         collections in the message.
 * @throws MobyException
 *             if the the element contains an invalid BioMOBY message
 */
public static String[] getListOfCollections(String message)
		throws MobyException {
	Element element = getDOMDocument(message).getRootElement();
	Element[] elements = getListOfCollections(element);
	String[] strings = new String[elements.length];
	XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
			.setOmitDeclaration(false));
	for (int count = 0; count < elements.length; count++) {
		try {
			strings[count] = outputter.outputString(elements[count]);
		} catch (Exception e) {
			throw new MobyException(newline
					+ "Unexpected error occured while creating String[]:"
					+ newline + Utils.format(e.getLocalizedMessage(), 3));
		}
	}
	return strings;
}
 
開發者ID:apache,項目名稱:incubator-taverna-plugin-bioinformatics,代碼行數:29,代碼來源:XMLUtilities.java

示例7: getSimple

import org.jdom.output.Format; //導入依賴的package包/類
/**
 * This method assumes a single invocation was passed to it
 * <p>
 *
 * @param name
 *            the article name of the simple that you are looking for
 * @param xml
 *            the xml that you want to query
 * @return a String object that represent the simple found.
 * @throws MobyException
 *             if no simple was found given the article name and/or data
 *             type or if the xml was not valid moby xml or if an unexpected
 *             error occurs.
 */
public static String getSimple(String name, String xml)
		throws MobyException {
	Element element = getDOMDocument(xml).getRootElement();
	XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()
			.setOmitDeclaration(false));
	Element simples = getSimple(name, element);
	if (simples != null) {
		try {
			return outputter.outputString(simples);
		} catch (Exception e) {
			throw new MobyException(newline
					+ "Unexpected error occured while creating String[]:"
					+ newline + Utils.format(e.getLocalizedMessage(), 3));
		}
	}
	throw new MobyException(newline + "The simple named '" + name
			+ "' was not found in the xml:" + newline + xml + newline);
}
 
開發者ID:apache,項目名稱:incubator-taverna-plugin-bioinformatics,代碼行數:33,代碼來源:XMLUtilities.java

示例8: getSimplesFromCollection

import org.jdom.output.Format; //導入依賴的package包/類
/**
 *
 * @param name
 *            the name of the collection to extract the simples from.
 * @param xml
 *            the XML to extract from
 * @return an array of String objects that represent the simples
 * @throws MobyException
 */
public static String[] getSimplesFromCollection(String name, String xml)
		throws MobyException {
	Element[] elements = getSimplesFromCollection(name, getDOMDocument(xml)
			.getRootElement());
	String[] strings = new String[elements.length];
	XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
			.setOmitDeclaration(false));
	for (int i = 0; i < elements.length; i++) {
		try {
			strings[i] = output.outputString(elements[i]);
		} catch (Exception e) {
			throw new MobyException(newline
					+ "Unknown error occured while creating String[]."
					+ newline + Utils.format(e.getLocalizedMessage(), 3));
		}
	}
	return strings;
}
 
開發者ID:apache,項目名稱:incubator-taverna-plugin-bioinformatics,代碼行數:28,代碼來源:XMLUtilities.java

示例9: getWrappedSimplesFromCollection

import org.jdom.output.Format; //導入依賴的package包/類
/**
 *
 * @param name
 *            the name of the collection to extract the simples from.
 * @param xml
 *            the XML to extract from
 * @return an array of String objects that represent the simples, with the
 *         name of the collection
 * @throws MobyException
 *             if the collection doesnt exist or the xml is invalid
 */
public static String[] getWrappedSimplesFromCollection(String name,
		String xml) throws MobyException {
	Element[] elements = getWrappedSimplesFromCollection(name,
			getDOMDocument(xml).getRootElement());
	String[] strings = new String[elements.length];
	XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()
			.setOmitDeclaration(false));
	for (int i = 0; i < elements.length; i++) {
		try {
			strings[i] = output.outputString(elements[i]);
		} catch (Exception e) {
			throw new MobyException(newline
					+ "Unknown error occured while creating String[]."
					+ newline + Utils.format(e.getLocalizedMessage(), 3));
		}
	}
	return strings;
}
 
開發者ID:apache,項目名稱:incubator-taverna-plugin-bioinformatics,代碼行數:30,代碼來源:XMLUtilities.java

示例10: printXML

import org.jdom.output.Format; //導入依賴的package包/類
public static void printXML(Element element){
	Format format = Format.getPrettyFormat();
	format.setIndent("\t");
	XMLOutputter op = new XMLOutputter(format);
	if(element == null){
		System.err.println("Null element");
	}
	else{
		try {
			op.output(element, System.out);
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println();
	}
}
 
開發者ID:tvaquero,項目名稱:itsimple,代碼行數:17,代碼來源:XMLUtilities.java

示例11: testInsertAtPreferredLocation

import org.jdom.output.Format; //導入依賴的package包/類
public void testInsertAtPreferredLocation() throws Exception {
    NetbeansBuildActionJDOMWriter writer = new NetbeansBuildActionJDOMWriter();
    XMLOutputter xmlout = new XMLOutputter();
    xmlout.setFormat(Format.getRawFormat().setLineSeparator("\n"));
    Element p = new Element("p");
    NetbeansBuildActionJDOMWriter.Counter c = writer.new Counter(1);
    writer.insertAtPreferredLocation(p, new Element("one"), c);
    assertEquals("<p>\n    <one />\n</p>", xmlout.outputString(p));
    c.increaseCount();
    writer.insertAtPreferredLocation(p, new Element("two"), c);
    assertEquals("<p>\n    <one />\n    <two />\n</p>", xmlout.outputString(p));
    c = writer.new Counter(1);
    writer.insertAtPreferredLocation(p, new Element("zero"), c);
    assertEquals("<p>\n    <zero />\n    <one />\n    <two />\n</p>", xmlout.outputString(p));
    c.increaseCount();
    writer.insertAtPreferredLocation(p, new Element("hemi"), c);
    assertEquals("<p>\n    <zero />\n    <hemi />\n    <one />\n    <two />\n</p>", xmlout.outputString(p));
    c.increaseCount();
    c.increaseCount();
    writer.insertAtPreferredLocation(p, new Element("sesqui"), c);
    assertEquals("<p>\n    <zero />\n    <hemi />\n    <one />\n    <sesqui />\n    <two />\n</p>", xmlout.outputString(p));
    c.increaseCount();
    c.increaseCount();
    writer.insertAtPreferredLocation(p, new Element("ultimate"), c);
    assertEquals("<p>\n    <zero />\n    <hemi />\n    <one />\n    <sesqui />\n    <two />\n    <ultimate />\n</p>", xmlout.outputString(p));
    c = writer.new Counter(1);
    writer.insertAtPreferredLocation(p, new Element("initial"), c);
    assertEquals("<p>\n    <initial />\n    <zero />\n    <hemi />\n    <one />\n    <sesqui />\n    <two />\n    <ultimate />\n</p>", xmlout.outputString(p));
    // XXX indentation still not right; better to black-box test write(ActionToGoalMapping...)
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:31,代碼來源:NetbeansBuildActionJDOMWriterTest.java

示例12: processFullCreoleXmlTree

import org.jdom.output.Format; //導入依賴的package包/類
private void processFullCreoleXmlTree(Plugin plugin,
    Document jdomDoc, CreoleAnnotationHandler annotationHandler)
    throws GateException, IOException, JDOMException {
  // now we can process any annotations on the new classes
  // and augment the XML definition
  annotationHandler.processAnnotations(jdomDoc);

  // debugging
  if(DEBUG) {
    XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());
    xmlOut.output(jdomDoc, System.out);
  }

  // finally, parse the augmented definition with the normal parser
  DefaultHandler handler =
      new CreoleXmlHandler(this, plugin);
  SAXOutputter outputter =
      new SAXOutputter(handler, handler, handler, handler);
  outputter.output(jdomDoc);
  if(DEBUG) {
    Out.prln("done parsing " + plugin);
  }
}
 
開發者ID:GateNLP,項目名稱:gate-core,代碼行數:24,代碼來源:CreoleRegisterImpl.java

示例13: write

import org.jdom.output.Format; //導入依賴的package包/類
public static void write( Writer w, Model newModel, boolean namespaceDeclaration )
    throws IOException
{
    Element root = new Element( "project" );

    if ( namespaceDeclaration )
    {
        String modelVersion = newModel.getModelVersion();

        Namespace pomNamespace = Namespace.getNamespace( "", "http://maven.apache.org/POM/" + modelVersion );

        root.setNamespace( pomNamespace );

        Namespace xsiNamespace = Namespace.getNamespace( "xsi", "http://www.w3.org/2001/XMLSchema-instance" );

        root.addNamespaceDeclaration( xsiNamespace );

        if ( root.getAttribute( "schemaLocation", xsiNamespace ) == null )
        {
            root.setAttribute( "schemaLocation",
                               "http://maven.apache.org/POM/" + modelVersion + " http://maven.apache.org/maven-v"
                                   + modelVersion.replace( '.', '_' ) + ".xsd", xsiNamespace );
        }
    }

    Document doc = new Document( root );

    MavenJDOMWriter writer = new MavenJDOMWriter();

    String encoding = newModel.getModelEncoding() != null ? newModel.getModelEncoding() : "UTF-8";

    Format format = Format.getPrettyFormat().setEncoding( encoding );

    writer.write( newModel, doc, w, format );
}
 
開發者ID:javiersigler,項目名稱:apache-maven-shade-plugin,代碼行數:36,代碼來源:PomWriter.java

示例14: write

import org.jdom.output.Format; //導入依賴的package包/類
/**
 * Method write
 *
 * @param project
 * @param stream
 * @param document
 * @deprecated
 */
public void write( Model project, Document document, OutputStream stream )
    throws java.io.IOException
{
    updateModel( project, "project", new Counter( 0 ), document.getRootElement() );
    XMLOutputter outputter = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent( "    " ).setLineSeparator( System.getProperty( "line.separator" ) );
    outputter.setFormat( format );
    outputter.output( document, stream );
}
 
開發者ID:javiersigler,項目名稱:apache-maven-shade-plugin,代碼行數:19,代碼來源:MavenJDOMWriter.java

示例15: writeXML

import org.jdom.output.Format; //導入依賴的package包/類
/**
 * Write the HMM parameters to a xml file.
 *
 * @param hmm the markovmodel of which should be written
 * @param file  the output file
 */
public static void writeXML(HMM hmm, String file)
{
    try
    {
        _LOGGER.info("Writing markovmodel to xml.");
        Element hmmxml = new Element("markovmodel");
        Document doc = new Document(hmmxml);
        doc.setRootElement(hmmxml);

        Element meta = new Element("meta");
        hmmxml.addContent(meta);
        addMeta(hmm, meta);
        if (hmm.isTrained())
        {
            Element ortho = new Element("ortho");
            hmmxml.addContent(ortho);
            addOrtho(hmm, ortho);
        }
        XMLOutputter xmlOutput = new XMLOutputter();
        xmlOutput.setFormat(Format.getPrettyFormat());
        xmlOutput.output(doc, new FileWriter(file));
    }
    catch (IOException e)
    {
        _LOGGER.error("Error when writing xmlFile: " + e.getMessage());
    }
}
 
開發者ID:dirmeier,項目名稱:lvm4j,代碼行數:34,代碼來源:File.java


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