本文整理汇总了Java中org.apache.avalon.framework.configuration.DefaultConfigurationBuilder类的典型用法代码示例。如果您正苦于以下问题:Java DefaultConfigurationBuilder类的具体用法?Java DefaultConfigurationBuilder怎么用?Java DefaultConfigurationBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultConfigurationBuilder类属于org.apache.avalon.framework.configuration包,在下文中一共展示了DefaultConfigurationBuilder类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initFopFactoryFromJar
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
public FopFactory initFopFactoryFromJar() throws IOException, SAXException, ConfigurationException {
FopFactory fopFactory = FopFactory.newInstance();
FOURIResolver uriResolver = (FOURIResolver) fopFactory.getURIResolver();
if (context != null) {
uriResolver.setCustomURIResolver(new CustomResolver(context));
} else {
uriResolver.setCustomURIResolver(new CustomResolver());
}
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration cfg = builder.build(getClass().getResourceAsStream("fop-pdf-thai.xml"));
fopFactory.setUserConfig(cfg);
return fopFactory;
}
示例2: PDFExportService
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
public PDFExportService(TimeService timeService, ResourceLoader rb) {
this.timeService = timeService;
this.rb = rb;
transformerFactory = TransformerFactory.newInstance();
transformerFactory.setURIResolver( new MyURIResolver(getClass().getClassLoader()) );
try {
URI baseDir = getClass().getClassLoader().getResource(FOP_FONTBASEDIR).toURI();
FopFactoryBuilder builder = new FopFactoryBuilder(baseDir, new ClassPathResolver());
InputStream userConfig = getClass().getClassLoader().getResourceAsStream(FOP_USERCONFIG);
fopFactory = builder.setConfiguration(new DefaultConfigurationBuilder().build(userConfig)).build();
} catch (IOException | URISyntaxException | SAXException | ConfigurationException e) {
// We won't be able to do anything if we can't create a FopFactory so may as well get caller to handle.
throw new RuntimeException("Failed to setup Apache FOP for calendar PDF exports.", e);
}
}
示例3: main
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
try {
String configFile = "examples/fop-eps.xconf";
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration c = cfgBuilder.buildFromFile(configFile);
FontInfo fontInfo = PDFDocumentGraphics2DConfigurator.createFontInfo(c, false);
OutputStream out = new FileOutputStream("example_eps.eps");
EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
g2d.setGraphicContext(new GraphicContext());
g2d.setCustomTextHandler(new NativeTextHandler(g2d, fontInfo));
g2d.setupDocument(out, 200, 100);
g2d.setFont(new Font("Arial", Font.PLAIN, 12));
g2d.drawString("Hi there Arial", 50, 50);
g2d.finish();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: getConfiguration
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
private Configuration getConfiguration() {
if (symbol != null) {
DefaultConfiguration cfg = new DefaultConfiguration("cfg");
DefaultConfiguration child = new DefaultConfiguration(symbol);
cfg.addChild(child);
return cfg;
}
if (configurationFile != null) {
try {
if (!configurationFile.exists() || !configurationFile.isFile()) {
throw new BuildException("Config file not found: " + configurationFile);
}
log("Using configuration: " + configurationFile);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
return builder.buildFromFile(configurationFile);
} catch (Exception e) {
throw new BuildException("Error reading configuration file: " + e.getMessage());
}
}
return new DefaultConfiguration("cfg");
}
示例5: testCustomConfig
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
@Ignore
public void testCustomConfig() throws IOException, ConfigurationException, SAXException {
String OUTPUT_PATH = "target/TestPdfReportOutputCustomConfig.pdf";
Configuration fopConfig =
new DefaultConfigurationBuilder().build("./input/fopConfigForUnitTests.xml");
PdfReportOutput testOutput =
new PdfReportOutput(ReportIoUtils.createOutputStreamFromPath(OUTPUT_PATH),
new PdfOutputFormat(PageSize.A3_PORTRAIT),
fopConfig);
testOutput.open();
// calling startreport.ftl and endreport.ftl is important for pdf
// because the resulting xml does not have a root and a well-defined
// namespace
testOutput.output("startReport.ftl", new ReportProps(new PdfOutputFormat()));
testOutput.output("paragraph.ftl", new ParagraphProps("This is a report with custom configuration"));
testOutput.output("endReport.ftl");
testOutput.postProcess();
testOutput.close();
File pdfFile = new File(OUTPUT_PATH);
Assert.assertNotNull(pdfFile);
Assert.assertNotNull(pdfFile.exists());
Assert.assertTrue(pdfFile.isFile());
Assert.assertTrue(pdfFile.length() != 0);
}
示例6: setUserConfig
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/**
* Set the user configuration.
* @param userConfigFile the configuration file
* @throws IOException if an I/O error occurs
* @throws SAXException if a parsing error occurs
*/
public void setUserConfig(File userConfigFile) throws SAXException, IOException {
try {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
setUserConfig(cfgBuilder.buildFromFile(userConfigFile));
} catch (ConfigurationException e) {
throw new FOPException(e);
}
}
示例7: main
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/**
* Main method.
* @param args the command-line arguments
*/
public static void main(String[] args) {
try {
//Read configuration
File cfgFile = new File(args[0]);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
Configuration cfg = builder.buildFromFile(cfgFile);
boolean doPrompt = cfg.getAttributeAsBoolean("prompt", false);
if (doPrompt) {
prompt();
}
//Setup testbed
FOPTestbed testbed = new FOPTestbed();
ContainerUtil.enableLogging(testbed, new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
ContainerUtil.configure(testbed, cfg);
ContainerUtil.initialize(testbed);
//Start tests
testbed.doStressTest();
System.exit(0);
} catch (Exception e) {
System.err.println(ExceptionUtil.printStackTrace(e));
System.exit(-1);
}
}
示例8: getConfiguration
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
private Configuration getConfiguration(CommandLine cl) {
if (cl.hasOption("s")) {
String sym = cl.getOptionValue("s");
DefaultConfiguration cfg = new DefaultConfiguration("cfg");
DefaultConfiguration child = new DefaultConfiguration(sym);
cfg.addChild(child);
return cfg;
}
if (cl.hasOption("c")) {
try {
String filename = cl.getOptionValue("c");
File cfgFile = new File(filename);
if (!cfgFile.exists() || !cfgFile.isFile()) {
throw new FileNotFoundException(
"Config file not found: " + cfgFile);
}
log.info("Using configuration: " + cfgFile);
DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
return builder.buildFromFile(cfgFile);
} catch (Exception e) {
exitHandler.failureExit(this,
"Error reading configuration file: " + e.getMessage(), null, -3);
}
}
return new DefaultConfiguration("cfg");
}
示例9: readInput
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
protected void readInput(PipelineContext context, ProcessorInput input, Config config, OutputStream outputStream) {
// Read inputs
final Document configDocument = readCacheInputAsDOM4J(context, "barcode");
final Document instanceDocument = readInputAsDOM4J(context, "data");
// Wraps documents for XPath API
final DocumentInfo configDocumentInfo = new DocumentWrapper(configDocument, null, XPathCache.getGlobalConfiguration());
final DocumentInfo instanceDocumentInfo = new DocumentWrapper(instanceDocument, null, XPathCache.getGlobalConfiguration());
try {
final StringBuilderWriter barcodeConfigWriter = new StringBuilderWriter();
configDocument.write(barcodeConfigWriter);
final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
final Configuration cfg = builder.build(new StringInputStream(Dom4jUtils.domToString(configDocument)));
final BarcodeGenerator gen = BarcodeUtil.getInstance().createBarcodeGenerator(cfg);
// TODO: These parameters (DPI, etc.) should be configurable
final BitmapCanvasProvider provider = new BitmapCanvasProvider(
outputStream, "image/x-png", 300,
BufferedImage.TYPE_BYTE_GRAY, false);
// Read text
final String messageRef = XPathCache.evaluateAsString(
configDocumentInfo, "/barcode/@message", null, null, null,
null, null, null, null);
final String message = XPathCache.evaluateAsString(
instanceDocumentInfo, messageRef, null, null, null, null,
null, null, null);
// Produce barcode
gen.generateBarcode(provider, message);
provider.finish();
} catch (Exception e) {
throw new OXFException(e);
}
}
示例10: processSamples
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
public static void processSamples(String filename, Visualizer visualizer, ResultCollector rc)
throws SAXException, IOException, ConfigurationException
{
DefaultConfigurationBuilder cfgbuilder = new DefaultConfigurationBuilder();
Configuration savedSamples = cfgbuilder.buildFromFile(filename);
Configuration[] samples = savedSamples.getChildren();
final boolean errorsOnly = rc.isErrorLogging();
final boolean successOnly = rc.isSuccessOnlyLogging();
for (int i = 0; i < samples.length; i++) {
SampleResult result = OldSaveService.getSampleResult(samples[i]);
if (ResultCollector.isSampleWanted(result.isSuccessful(), errorsOnly, successOnly)) {
visualizer.add(result);
}
}
}
示例11: generatePDF
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/**
* Takes a DOM structure and renders a PDF
*
* @param doc
* DOM structure
* @param xslFileName
* XSL file to use to translate the DOM document to FOP
*/
@SuppressWarnings("unchecked")
protected void generatePDF(Document doc, OutputStream streamOut)
{
String xslFileName = "participants-all-attrs.xsl";
Locale currentLocale = rb.getLocale();
if (currentLocale!=null){
String fullLocale = currentLocale.toString();
xslFileName = "participants-all-attrs_" + fullLocale + ".xsl";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
xslFileName = "participants-all-attrs_" + currentLocale.getCountry() + ".xsl";
inputStream = getClass().getClassLoader().getResourceAsStream(xslFileName);
if (inputStream == null){
//We use the default file
xslFileName = "participants-all-attrs.xsl";
}
}
IOUtils.closeQuietly(inputStream);
}
String configFileName = "userconfig.xml";
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
InputStream configInputStream = null;
try
{
configInputStream = getClass().getClassLoader().getResourceAsStream(configFileName);
Configuration cfg = cfgBuilder.build(configInputStream);
FopFactory fopFactory = FopFactory.newInstance();
fopFactory.setUserConfig(cfg);
fopFactory.setStrictValidation(false);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
if (!StringUtils.isEmpty(ServerConfigurationService.getString("pdf.default.font"))) {
// this allows font substitution to support i18n chars in PDFs - SAK-21909
FontQualifier fromQualifier = new FontQualifier();
fromQualifier.setFontFamily("DEFAULT_FONT");
FontQualifier toQualifier = new FontQualifier();
toQualifier.setFontFamily(ServerConfigurationService.getString("pdf.default.font", "Helvetica"));
FontSubstitutions result = new FontSubstitutions();
result.add(new FontSubstitution(fromQualifier, toQualifier));
fopFactory.getFontManager().setFontSubstitutions(result);
}
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, streamOut);
InputStream in = getClass().getClassLoader().getResourceAsStream(xslFileName);
Transformer transformer = transformerFactory.newTransformer(new StreamSource(in));
transformer.setParameter("titleName", rb.getString("sitegen.siteinfolist.title.name"));
transformer.setParameter("titleSection", rb.getString("sitegen.siteinfolist.title.section"));
transformer.setParameter("titleId", rb.getString("sitegen.siteinfolist.title.id"));
transformer.setParameter("titleCredit", rb.getString("sitegen.siteinfolist.title.credit"));
transformer.setParameter("titleRole", rb.getString("sitegen.siteinfolist.title.role"));
transformer.setParameter("titleStatus", rb.getString("sitegen.siteinfolist.title.status"));
Source src = new DOMSource(doc);
transformer.transform(src, new SAXResult(fop.getDefaultHandler()));
}
catch (Exception e)
{
log.warn(this+".generatePDF(): " + e);
return;
}
finally
{
IOUtils.closeQuietly(configInputStream);
}
}
示例12: createFopFactory
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/** Create a FOP factory and configure it, if we don't already have one. */
private FopFactory createFopFactory(XPathContext context)
throws ConfigurationException, SAXException, IOException, XPathException
{
// See if any font directories were specified.
String fontDirs = "";
if (attribs.containsKey("fontDirs"))
fontDirs = attribs.get("fontDirs").evaluateAsString(context);
// If we've already created a factory with this set of font directories,
// don't re-create (it's expensive.)
//
if (fopFactories.containsKey(fontDirs))
return fopFactories.get(fontDirs);
// Gotta make a new one.
FopFactory factory = FopFactory.newInstance();
if (fontDirs.length() > 0)
{
// The only way I've figured out to put font search directories into the
// factory is to feed in an XML config file. So construct one.
//
StringBuilder buf = new StringBuilder();
buf.append("<?xml version=\"1.0\"?>" +
"<fop version=\"1.0\">" +
" <renderers>" +
" <renderer mime=\"application/pdf\">" +
" <fonts>");
for (String dir : fontDirs.split(";"))
buf.append(" <directory>" + dir + "</directory>");
buf.append(" </fonts>" +
" </renderer>" +
" </renderers>" +
"</fop>");
// Jump through hoops to make the XML into an InputStream
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos);
osw.write(buf.toString());
osw.flush();
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
// Build the configuration and stick it into the factory.
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration config = cfgBuilder.build(bis);
factory.setUserConfig(config);
}
// Cache this factory so we don't have to create it again (they're expensive.)
fopFactories.put(fontDirs, factory);
return factory;
}
示例13: runBatch
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder; //导入依赖的package包/类
/**
* Runs the batch.
* @param cfgFile configuration file to use
* @throws ConfigurationException In case of a problem with the configuration
* @throws SAXException In case of a problem during SAX processing
* @throws IOException In case of a I/O problem
*/
public void runBatch(File cfgFile)
throws ConfigurationException, SAXException, IOException {
DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
Configuration cfg = cfgBuilder.buildFromFile(cfgFile);
runBatch(cfg);
}