use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.
the class LauncherGeneratorMain method main.
public static void main(String[] args) {
if (args.length != 5) {
System.err.println("Usage: LauncherGeneratorMain <template EXE file> <app info file> <resource.h file> <properties> <output>");
System.exit(1);
}
File template = new File(args[0]);
if (!template.exists()) {
System.err.println("Launcher template EXE file " + args[0] + " not found");
System.exit(2);
}
String appInfoFileName = args[1];
InputStream appInfoStream;
try {
appInfoStream = new FileInputStream(appInfoFileName);
} catch (FileNotFoundException e) {
appInfoStream = LauncherGeneratorMain.class.getClassLoader().getResourceAsStream(appInfoFileName);
}
if (appInfoStream == null) {
System.err.println("Application info file " + appInfoFileName + " not found");
System.exit(3);
}
Document appInfo;
try {
appInfo = new SAXBuilder().build(appInfoStream);
} catch (Exception e) {
System.err.println("Error loading application info file " + appInfoFileName + ": " + e.getMessage());
System.exit(4);
return;
}
Element appInfoRoot = appInfo.getRootElement();
String splashUrl = getChild(appInfoRoot, "logo").getAttributeValue("url");
if (splashUrl.startsWith("/")) {
splashUrl = splashUrl.substring(1);
}
InputStream splashStream = LauncherGeneratorMain.class.getClassLoader().getResourceAsStream(splashUrl);
if (splashStream == null) {
System.err.println("Splash screen image file file " + splashUrl + " not found");
System.exit(5);
}
ByteArrayOutputStream splashBmpStream = new ByteArrayOutputStream();
try {
BufferedImage bufferedImage = Sanselan.getBufferedImage(splashStream);
Sanselan.writeImage(bufferedImage, splashBmpStream, ImageFormat.IMAGE_FORMAT_BMP, new HashMap());
} catch (Exception e) {
System.err.println("Error converting splash screen to BMP: " + e.getMessage());
System.exit(6);
}
String icoUrl = getChild(appInfoRoot, "icon").getAttributeValue("ico");
if (icoUrl == null) {
System.err.println(".ico file URL not specified in application info file " + appInfoFileName);
System.exit(11);
}
InputStream iconStream = LauncherGeneratorMain.class.getClassLoader().getResourceAsStream(icoUrl);
if (iconStream == null) {
System.err.println(".ico file " + icoUrl + " not found");
System.exit(12);
}
Map<String, Integer> resourceIDs;
try {
resourceIDs = loadResourceIDs(args[2]);
} catch (Exception e) {
System.err.println("Error loading resource.h: " + e.getMessage());
System.exit(7);
return;
}
Properties properties = new Properties();
try {
FileInputStream fis = new FileInputStream(args[3]);
try {
properties.load(fis);
} finally {
fis.close();
}
} catch (IOException e) {
System.err.println("Error loading launcher properties: " + e.getMessage());
System.exit(8);
}
String companyName = getChild(appInfoRoot, "company").getAttributeValue("name");
Element names = getChild(appInfoRoot, "names");
String productShortName = names.getAttributeValue("product");
String productFullName = names.getAttributeValue("fullname");
Element versionElement = getChild(appInfoRoot, "version");
int majorVersion = Integer.parseInt(versionElement.getAttributeValue("major"));
String minorVersionString = versionElement.getAttributeValue("minor");
Pattern p = Pattern.compile("(\\d+)(\\.(\\d+))?");
Matcher matcher = p.matcher(minorVersionString);
if (!matcher.matches()) {
System.err.println("Unexpected minor version format: " + minorVersionString);
}
int minorVersion = Integer.parseInt(matcher.group(1));
int bugfixVersion = matcher.group(3) != null ? Integer.parseInt(matcher.group(3)) : 0;
String buildNumber = getChild(appInfoRoot, "build").getAttributeValue("number");
String versionString = "" + majorVersion + "." + minorVersion + "." + bugfixVersion + "." + buildNumber;
int year = new GregorianCalendar().get(Calendar.YEAR);
LauncherGenerator generator = new LauncherGenerator(template, new File(args[4]));
try {
generator.load();
for (Map.Entry<Object, Object> pair : properties.entrySet()) {
String key = (String) pair.getKey();
Integer id = resourceIDs.get(key);
if (id == null) {
System.err.println("Invalid stringtable ID found: " + key);
System.exit(9);
}
generator.setResourceString(id, (String) pair.getValue());
}
generator.injectBitmap(resourceIDs.get("IDB_SPLASH"), splashBmpStream.toByteArray());
generator.injectIcon(resourceIDs.get("IDI_WINLAUNCHER"), iconStream);
generator.setVersionInfoString("LegalCopyright", "Copyright (C) 2000-" + year + " " + companyName);
generator.setVersionInfoString("ProductName", productFullName);
generator.setVersionInfoString("FileVersion", versionString);
generator.setVersionInfoString("FileDescription", productFullName);
generator.setVersionInfoString("ProductVersion", versionString);
generator.setVersionInfoString("InternalName", productShortName.toLowerCase() + ".exe");
generator.setVersionInfoString("OriginalFilename", productShortName.toLowerCase() + ".exe");
generator.setVersionNumber(majorVersion, minorVersion, bugfixVersion);
generator.generate();
} catch (IOException e) {
e.printStackTrace();
System.exit(10);
}
}
use of org.jdom.input.SAXBuilder in project gora by apache.
the class SolrStore method readMapping.
@SuppressWarnings("unchecked")
private SolrMapping readMapping(String filename) throws IOException {
SolrMapping map = new SolrMapping();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(getClass().getClassLoader().getResourceAsStream(filename));
List<Element> classes = doc.getRootElement().getChildren("class");
for (Element classElement : classes) {
if (classElement.getAttributeValue("keyClass").equals(keyClass.getCanonicalName()) && classElement.getAttributeValue("name").equals(persistentClass.getCanonicalName())) {
String tableName = getSchemaName(classElement.getAttributeValue("table"), persistentClass);
map.setCoreName(tableName);
Element primaryKeyEl = classElement.getChild("primarykey");
map.setPrimaryKey(primaryKeyEl.getAttributeValue("column"));
List<Element> fields = classElement.getChildren("field");
for (Element field : fields) {
String fieldName = field.getAttributeValue("name");
String columnName = field.getAttributeValue("column");
map.addField(fieldName, columnName);
}
break;
}
LOG.warn("Check that 'keyClass' and 'name' parameters in gora-solr-mapping.xml " + "match with intended values. A mapping mismatch has been found therefore " + "no mapping has been initialized for class mapping at position " + " {} in mapping file.", classes.indexOf(classElement));
}
} catch (Exception ex) {
throw new IOException(ex);
}
return map;
}
use of org.jdom.input.SAXBuilder in project gora by apache.
the class DynamoDBStore method readMapping.
/**
* Reads the schema file and converts it into a data structure to be used
*
* @return DynamoDBMapping Object containing all necessary information to
* create tables
* @throws IOException
*/
@SuppressWarnings("unchecked")
private DynamoDBMapping readMapping() throws IOException {
DynamoDBMappingBuilder mappingBuilder = new DynamoDBMappingBuilder();
try {
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(getClass().getClassLoader().getResourceAsStream(MAPPING_FILE));
if (doc == null || doc.getRootElement() == null)
throw new GoraException("Unable to load " + MAPPING_FILE + ". Please check its existance!");
Element root = doc.getRootElement();
List<Element> tableElements = root.getChildren("table");
boolean keys = false;
for (Element tableElement : tableElements) {
String tableName = tableElement.getAttributeValue("name");
long readCapacUnits = Long.parseLong(tableElement.getAttributeValue("readcunit"));
long writeCapacUnits = Long.parseLong(tableElement.getAttributeValue("writecunit"));
mappingBuilder.setProvisionedThroughput(tableName, readCapacUnits, writeCapacUnits);
LOG.debug("Basic table properties have been set: Name, and Provisioned throughput.");
// Retrieving attributes
List<Element> fieldElements = tableElement.getChildren("attribute");
for (Element fieldElement : fieldElements) {
String key = fieldElement.getAttributeValue("key");
String attributeName = fieldElement.getAttributeValue("name");
String attributeType = fieldElement.getAttributeValue("type");
mappingBuilder.addAttribute(tableName, attributeName, attributeType);
// Retrieving key's features
if (key != null) {
mappingBuilder.setKeySchema(tableName, attributeName, key);
keys = true;
}
}
LOG.debug("Attributes for table '" + tableName + "' have been read.");
if (!keys)
LOG.warn("Keys for table '" + tableName + "' have NOT been set.");
}
} catch (IOException ex) {
LOG.error("Error while performing xml mapping.", ex.getMessage());
throw new IOException(ex);
} catch (Exception ex) {
LOG.error("Error while performing xml mapping.", ex.getMessage());
throw new RuntimeException(ex);
}
return mappingBuilder.build();
}
use of org.jdom.input.SAXBuilder in project maven-plugins by apache.
the class AbstractEffectiveMojo method addMavenNamespace.
/**
* Add a Pom/Settings namespaces to the effective XML content.
*
* @param effectiveXml not null the effective POM or Settings
* @param isPom if <code>true</code> add the Pom xsd url, otherwise add the settings xsd url.
* @return the content of the root element, i.e. <project/> or <settings/> with the Maven namespace or
* the original <code>effective</code> if an error occurred.
* @see #POM_XSD_URL
* @see #SETTINGS_XSD_URL
*/
protected static String addMavenNamespace(String effectiveXml, boolean isPom) {
SAXBuilder builder = new SAXBuilder();
try {
Document document = builder.build(new StringReader(effectiveXml));
Element rootElement = document.getRootElement();
// added namespaces
Namespace pomNamespace = Namespace.getNamespace("", "http://maven.apache.org/POM/4.0.0");
rootElement.setNamespace(pomNamespace);
Namespace xsiNamespace = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
rootElement.addNamespaceDeclaration(xsiNamespace);
if (rootElement.getAttribute("schemaLocation", xsiNamespace) == null) {
rootElement.setAttribute("schemaLocation", "http://maven.apache.org/POM/4.0.0 " + (isPom ? POM_XSD_URL : SETTINGS_XSD_URL), xsiNamespace);
}
ElementFilter elementFilter = new ElementFilter(Namespace.getNamespace(""));
for (Iterator<?> i = rootElement.getDescendants(elementFilter); i.hasNext(); ) {
Element e = (Element) i.next();
e.setNamespace(pomNamespace);
}
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(document.getRootElement(), w);
return w.toString();
} catch (JDOMException e) {
return effectiveXml;
} catch (IOException e) {
return effectiveXml;
}
}
use of org.jdom.input.SAXBuilder in project maven-plugins by apache.
the class EffectivePomMojo method prettyFormat.
/**
* @param effectivePom not null
* @return pretty format of the xml or the original <code>effectivePom</code> if an error occurred.
*/
private static String prettyFormat(String effectivePom) {
SAXBuilder builder = new SAXBuilder();
try {
Document effectiveDocument = builder.build(new StringReader(effectivePom));
StringWriter w = new StringWriter();
Format format = Format.getPrettyFormat();
XMLOutputter out = new XMLOutputter(format);
out.output(effectiveDocument, w);
return w.toString();
} catch (JDOMException e) {
return effectivePom;
} catch (IOException e) {
return effectivePom;
}
}
Aggregations