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


Java Format.getPrettyFormat方法代码示例

本文整理汇总了Java中org.jdom2.output.Format.getPrettyFormat方法的典型用法代码示例。如果您正苦于以下问题:Java Format.getPrettyFormat方法的具体用法?Java Format.getPrettyFormat怎么用?Java Format.getPrettyFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jdom2.output.Format的用法示例。


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

示例1: sloppyPrint

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * Creates an outputter and writes an XML tree.
 *
 * The encoding argument here only sets an attribute in the
 * XML declaration. It's up to the caller to ensure the writer
 * is encoding bytes to match. If encoding is null, the default
 * is "UTF-8".
 *
 * If XML character entity escaping is allowed, otherwise unmappable
 * characters may be written without errors. If disabled, an
 * UnmappableCharacterException will make their presence obvious and fatal.
 *
 * LineEndings will be CR-LF. Except for comments!?
 *
 * @param doc
 * @param writer
 * @param disableEscaping
 */
public static void sloppyPrint( Document doc, Writer writer, String encoding, boolean allowEscaping ) throws IOException {
	Format format = Format.getPrettyFormat();
	format.setTextMode( Format.TextMode.PRESERVE );  // Permit leading/trailing space.
	format.setExpandEmptyElements( false );
	format.setOmitDeclaration( false );
	format.setIndent( "\t" );
	format.setLineSeparator( LineSeparator.CRNL );

	if ( encoding != null ) {
		format.setEncoding( encoding );
	}

	if ( !allowEscaping ) {
		format.setEscapeStrategy(new EscapeStrategy() {
			@Override
			public boolean shouldEscape( char ch ) {
				return false;
			}
		});
	}

	XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
	outputter.output( doc, writer );
}
 
开发者ID:Vhati,项目名称:Slipstream-Mod-Manager,代码行数:43,代码来源:SloppyXMLOutputProcessor.java

示例2: toXML

import org.jdom2.output.Format; //导入方法依赖的package包/类
@Test
public void toXML() throws Exception {
    JAXBContext jc = JAXBContext.newInstance(MCRNavigationItem.class);
    Marshaller m = jc.createMarshaller();
    JDOMResult JDOMResult = new JDOMResult();
    m.marshal(this.item, JDOMResult);
    Element itemElement = JDOMResult.getDocument().getRootElement();

    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(itemElement, System.out);

    assertEquals("template_mysample", itemElement.getAttributeValue("template"));
    assertEquals("bold", itemElement.getAttributeValue("style"));
    assertEquals("_self", itemElement.getAttributeValue("target"));
    assertEquals("intern", itemElement.getAttributeValue("type"));
    assertEquals("true", itemElement.getAttributeValue("constrainPopUp"));
    assertEquals("false", itemElement.getAttributeValue("replaceMenu"));
    assertEquals("item.test.key", itemElement.getAttributeValue("i18nKey"));

    Element label1 = itemElement.getChildren().get(0);
    Element label2 = itemElement.getChildren().get(1);

    assertEquals("Deutschland", label1.getValue());
    assertEquals("England", label2.getValue());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:26,代码来源:ItemTest.java

示例3: toXML

import org.jdom2.output.Format; //导入方法依赖的package包/类
@Test
public void toXML() throws Exception {
    JAXBContext jc = JAXBContext.newInstance(MCRNavigation.class);
    Marshaller m = jc.createMarshaller();
    JDOMResult JDOMResult = new JDOMResult();
    m.marshal(this.navigation, JDOMResult);
    Element navigationElement = JDOMResult.getDocument().getRootElement();

    XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    out.output(navigationElement, System.out);

    // test attributes
    assertEquals("template_mysample", navigationElement.getAttributeValue("template"));
    assertEquals("/content", navigationElement.getAttributeValue("dir"));
    assertEquals("History Title", navigationElement.getAttributeValue("historyTitle"));
    assertEquals("/content/below/index.xml", navigationElement.getAttributeValue("hrefStartingPage"));
    assertEquals("Main Title", navigationElement.getAttributeValue("mainTitle"));
    // test children
    assertEquals(2, navigationElement.getChildren("menu").size());
    assertEquals(1, navigationElement.getChildren("insert").size());
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:22,代码来源:NavigationTest.java

示例4: toXML

import org.jdom2.output.Format; //导入方法依赖的package包/类
@Test
public final void toXML() throws IOException {
    MCRUserManager.updatePasswordHashToSHA256(this.user, this.user.getPassword());
    this.user.setEMail("[email protected]");
    this.user.setHint("JUnit Test");
    this.user.getSystemRoleIDs().add("admin");
    this.user.getSystemRoleIDs().add("editor");
    this.user.setLastLogin(new Date());
    this.user.setRealName("Test Case");
    this.user.getAttributes().put("tel", "555 4812");
    this.user.getAttributes().put("street", "Heidestraße 12");
    this.user.setOwner(this.user);
    MCRUserManager.updateUser(this.user);
    startNewTransaction();
    assertEquals("Too many users", 1, MCRUserManager.countUsers(null, null, null));
    assertEquals("Too many users", 1, MCRUserManager.listUsers(this.user).size());
    Document exportableXML = MCRUserTransformer.buildExportableXML(this.user);
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    xout.output(exportableXML, System.out);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:21,代码来源:MCRUserManagerTest.java

示例5: writeXML

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * Output xml
 * @param eRoot - the root element
 * @param lang - the language which should be filtered or null for no filter
 * @return a string representation of the XML
 * @throws IOException
 */
private static String writeXML(Element eRoot, String lang) throws IOException {
    StringWriter sw = new StringWriter();
    if (lang != null) {
        // <label xml:lang="en" text="part" />
        XPathExpression<Element> xpE = XPathFactory.instance().compile("//label[@xml:lang!='" + lang + "']",
            Filters.element(), null, Namespace.XML_NAMESPACE);
        for (Element e : xpE.evaluate(eRoot)) {
            e.getParentElement().removeContent(e);
        }
    }
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    Document docOut = new Document(eRoot.detach());
    xout.output(docOut, sw);
    return sw.toString();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:23,代码来源:MCRRestAPIClassifications.java

示例6: getMCRObject

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * creates a MCRObject instance on base of JDOM document
 * @param doc
 *  MyCoRe object as XML.
 * @return
 * @throws JDOMException
 *  exception from underlying {@link MCREditorOutValidator}
 * @throws IOException
 *  exception from underlying {@link MCREditorOutValidator} or {@link XMLOutputter}
 * @throws SAXParseException
 * @throws MCRException
 */
static MCRObject getMCRObject(Document doc) throws JDOMException, IOException, MCRException, SAXParseException {
    String id = doc.getRootElement().getAttributeValue("ID");
    MCRObjectID objectID = MCRObjectID.getInstance(id);
    MCREditorOutValidator ev = new MCREditorOutValidator(doc, objectID);
    Document jdom_out = ev.generateValidMyCoReObject();
    if (ev.getErrorLog().size() > 0 && LOGGER.isDebugEnabled()) {
        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        StringWriter swOrig = new StringWriter();
        xout.output(doc, swOrig);
        LOGGER.debug("Input document \n{}", swOrig);
        for (String logMsg : ev.getErrorLog()) {
            LOGGER.debug(logMsg);
        }
        StringWriter swClean = new StringWriter();
        xout.output(jdom_out, swClean);
        LOGGER.debug("Results in \n{}", swClean);
    }
    return new MCRObject(jdom_out);
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:32,代码来源:MCRPersistenceHelper.java

示例7: generateValidMyCoReObject

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * tries to generate a valid MCRObject as JDOM Document.
 * 
 * @return MCRObject
 */
public Document generateValidMyCoReObject() throws JDOMException, SAXParseException, IOException {
    MCRObject obj;
    // load the JDOM object
    XPathFactory.instance()
        .compile("/mycoreobject/*/*/*/@editor.output", Filters.attribute())
        .evaluate(input)
        .forEach(Attribute::detach);
    try {
        byte[] xml = new MCRJDOMContent(input).asByteArray();
        obj = new MCRObject(xml, true);
    } catch (SAXParseException e) {
        XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
        LOGGER.warn("Failure while parsing document:\n{}", xout.outputString(input));
        throw e;
    }
    Date curTime = new Date();
    obj.getService().setDate("modifydate", curTime);

    // return the XML tree
    input = obj.createXML();
    return input;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:28,代码来源:MCREditorOutValidator.java

示例8: getGlobalCostParameters

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * Get the global cost parameters
 *
 * @param request the HTTP Request
 * @return the HTTP Response
 */
@GET
@Path("/remediation-cost-parameters/global")
@Produces(MediaType.APPLICATION_JSON)
public Response getGlobalCostParameters(@Context HttpServletRequest request) {
    String costParametersFolderPath = ProjectProperties.getProperty("cost-parameters-path");
    GlobalParameters globalParameters = new GlobalParameters();
    try {
        globalParameters.loadFromXMLFile(costParametersFolderPath + "/" + GlobalParameters.FILE_NAME);
    } catch (Exception e) {
        return RestApplication.returnErrorMessage(request, "The global parameters " +
                "can not be load: " + e.getMessage());
    }

    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
    return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(globalParameters.toDomElement())));
}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:23,代码来源:RestJsonConfiguration.java

示例9: createOPFContent

import org.jdom2.output.Format; //导入方法依赖的package包/类
public static byte[] createOPFContent(Book book) throws IllegalArgumentException, IllegalStateException
{
    Document opfDocument = write(book);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputter outputter = new XMLOutputter();
    Format xmlFormat = Format.getPrettyFormat();
    outputter.setFormat(xmlFormat);
    try
    {
        outputter.output(opfDocument, baos);
    }
    catch (IOException e)
    {
        logger.error("", e);
    }
    return baos.toByteArray();
}
 
开发者ID:finanzer,项目名称:epubfx,代码行数:19,代码来源:PackageDocumentWriter.java

示例10: getAttackGraph

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * Get the whole attack graph
 *
 * @param request the HTTP Request
 * @return the HTTP Response
 */
@GET
@Path("attack_graph")
@Produces(MediaType.APPLICATION_JSON)
public Response getAttackGraph(@Context HttpServletRequest request) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null) {
        return RestApplication.returnErrorMessage(request, "The monitoring object is empty. Did you forget to " +
                "initialize it ?");
    }

    Element attackGraphXML = monitoring.getAttackGraph().toDomElement();
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
    return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(attackGraphXML)));
}
 
开发者ID:fiware-cybercaptor,项目名称:cybercaptor-server,代码行数:22,代码来源:RestJsonAPI.java

示例11: wrap

import org.jdom2.output.Format; //导入方法依赖的package包/类
private String wrap(Object text) {
    if (text != null) {
        if (text instanceof Attribute) {
            return StringEscapeUtils.unescapeHtml4(((Attribute) text).getValue());
        } else if (text instanceof Content) {
            XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
            if (text instanceof Element) {
                return StringEscapeUtils.unescapeHtml4(xout.outputString((Element) text));
            }
            if (text instanceof Text) {
                return StringEscapeUtils.unescapeHtml4(xout.outputString((Text) text));
            }
        } else {
            LOGGER.error("unsupported document type", text.getClass());
        }
    }
    return "";
}
 
开发者ID:fivesmallq,项目名称:web-data-extractor,代码行数:19,代码来源:XPathExtractor.java

示例12: repair

import org.jdom2.output.Format; //导入方法依赖的package包/类
public static String repair(String originalHtml)
{
    String content = null;
    try
    {
        HtmlCleaner cleaner = createHtmlCleaner();

        //wir probieren es erstmal mit UTF-8
        TagNode rootNode = cleaner.clean(originalHtml);
        Document jdomDocument = new JDomSerializer(cleaner.getProperties(), false).createJDom(rootNode);
        jdomDocument.setDocType(Constants.DOCTYPE_XHTML.clone());

        XMLOutputter outputter = new XMLOutputter();
        Format xmlFormat = Format.getPrettyFormat();
        outputter.setFormat(xmlFormat);
        outputter.setXMLOutputProcessor(new XHTMLOutputProcessor());
        content = outputter.outputString(jdomDocument);
    }
    catch (IllegalAddException e)
    {
        logger.error("", e);
    }
    return content;
}
 
开发者ID:finanzer,项目名称:epubfx,代码行数:25,代码来源:XHTMLUtils.java

示例13: createXml

import org.jdom2.output.Format; //导入方法依赖的package包/类
private void createXml(ISendMessageCallback callback) {

        Document generatedXml = new Document();
        Stack<DocElement> parentStack = new Stack<DocElement>();
        ArrayList<String> outboundPayload = new ArrayList<String>();

        for (Message msg : messagesToProcess) {
            processMsgEntities(parentStack, msg, generatedXml);
        }
        XMLOutputter xmlOutputter = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }
        xmlOutputter.setFormat(format);
        outboundPayload.add(xmlOutputter.outputString(generatedXml));
        callback.sendTextMessage(null, outboundPayload);
    }
 
开发者ID:JumpMind,项目名称:metl,代码行数:23,代码来源:XmlFormatter.java

示例14: buildSettingsXML

import org.jdom2.output.Format; //导入方法依赖的package包/类
/**
 * Read {@code baseFilename.settings.xml} into a string if it exists.
 *
 * @return contents of {@code baseFilename.settings.xml} or {@code null} if
 *         that file couldn't be read.
 */
private static String buildSettingsXML( final String baseFilename )
{
	final String settings = baseFilename + ".settings.xml";
	if ( new File( settings ).exists() )
	{
		try
		{
			final SAXBuilder sax = new SAXBuilder();
			final Document doc = sax.build( settings );
			final XMLOutputter xout = new XMLOutputter( Format.getPrettyFormat() );
			final StringWriter sw = new StringWriter();
			xout.output( doc, sw );
			return sw.toString();
		}
		catch ( JDOMException | IOException e )
		{
			LOG.warn( "Could not read settings file \"" + settings + "\"" );
			LOG.warn( e.getMessage() );
		}
	}
	return null;
}
 
开发者ID:bigdataviewer,项目名称:bigdataviewer-server,代码行数:29,代码来源:CellHandler.java

示例15: buildJnlpResponse

import org.jdom2.output.Format; //导入方法依赖的package包/类
protected String buildJnlpResponse(JnlpTemplate launcher) throws ServletErrorException {

        launcher.rootElt.setAttribute(JNLP_TAG_ATT_CODEBASE,
            ServletUtil.getFirstParameter(launcher.parameterMap.get(PARAM_CODEBASE)));
        launcher.rootElt.removeAttribute(JNLP_TAG_ATT_HREF); // this tag has not to be used inside dynamic JNLP

        handleRequestPropertyParameter(launcher);
        handleRequestArgumentParameter(launcher);

        filterRequestParameterMarker(launcher);

        String outputStr = null;
        try {
            Format format = Format.getPrettyFormat();
            // Converts native encodings to ASCII with escaped Unicode like (ô è é...),
            // necessary for jnlp
            format.setEncoding("US-ASCII");
            outputStr = new XMLOutputter(format).outputString(launcher.rootElt);
        } catch (Exception e) {
            throw new ServletErrorException(HttpServletResponse.SC_NOT_MODIFIED, "Can't build Jnlp launcher ", e);
        }

        return outputStr;
    }
 
开发者ID:nroduit,项目名称:weasis-pacs-connector,代码行数:25,代码来源:JnlpLauncher.java


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