Search in sources :

Example 86 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class MavenEffectivePomDumper method addMavenNamespace.

/**
   * Copy/pasted from org.apache.maven.plugins.help.AbstractEffectiveMojo
   */
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);
        }
        addLineBreaks(document, pomNamespace);
        StringWriter w = new StringWriter();
        Format format = Format.getRawFormat();
        XMLOutputter out = new XMLOutputter(format);
        out.output(document.getRootElement(), w);
        return w.toString();
    } catch (JDOMException e) {
        return effectiveXml;
    } catch (IOException e) {
        return effectiveXml;
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Format(org.jdom.output.Format) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ElementFilter(org.jdom.filter.ElementFilter)

Example 87 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class XsltDocumentationProvider method getDocumentationDocument.

private Document getDocumentationDocument() throws IOException, JDOMException {
    Document d = com.intellij.reference.SoftReference.dereference(myDocument);
    if (d == null) {
        d = new SAXBuilder().build(XsltSupport.class.getResource("resources/documentation.xml"));
        myDocument = new SoftReference<>(d);
    }
    return d;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Document(org.jdom.Document)

Example 88 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class ModelLoader method load.

protected final void load(String name) {
    try {
        InputStream stream = getClass().getResourceAsStream(name);
        Document document = new SAXBuilder().build(stream);
        stream.close();
        loadDocument(document.getRootElement());
    } catch (Throwable e) {
        LOG.error(e);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) Document(org.jdom.Document)

Example 89 with SAXBuilder

use of org.jdom.input.SAXBuilder in project ACS by ACS-Community.

the class TestHighLevelNodes method testXmlMACI.

public void testXmlMACI() throws Exception {
    logger.info("MACI XML string -- Classic: " + xmlXml);
    SAXBuilder sb = new SAXBuilder();
    InputStream is = new ByteArrayInputStream(rdbXml.getBytes("UTF-8"));
    Document doc = sb.build(is);
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    xout.output(doc, out);
    logger.info("MACI XML string -- RDB: " + out.toString());
    // This fails at the moment because XML returns namespace info, TMCDB doesn't
    assertXMLEqual("MACI XML pieces are similar ", xmlXml, rdbXml);
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.jdom.Document)

Example 90 with SAXBuilder

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);
    }
}
Also used : Matcher(java.util.regex.Matcher) Element(org.jdom.Element) Document(org.jdom.Document) BufferedImage(java.awt.image.BufferedImage) Pattern(java.util.regex.Pattern) SAXBuilder(org.jdom.input.SAXBuilder)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)146 Document (org.jdom.Document)110 Element (org.jdom.Element)84 IOException (java.io.IOException)61 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5