Search in sources :

Example 61 with Attribute

use of org.dom4j.Attribute in project atlas by alibaba.

the class BundleInfoUtils method addComponents.

private static void addComponents(BundleInfo bundleInfo, Element root) {
    List<? extends Node> serviceNodes = root.selectNodes("//service");
    for (Node node : serviceNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        bundleInfo.getServices().add(attribute.getValue());
    }
    List<? extends Node> receiverNodes = root.selectNodes("//receiver");
    for (Node node : receiverNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        bundleInfo.getReceivers().add(attribute.getValue());
    }
    List<? extends Node> providerNodes = root.selectNodes("//provider");
    for (Node node : providerNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        bundleInfo.getContentProviders().add(attribute.getValue());
    }
    List<? extends Node> activityNodes = root.selectNodes("//activity");
    for (Node node : activityNodes) {
        Element element = (Element) node;
        Attribute attribute = element.attribute("name");
        bundleInfo.getActivities().add(attribute.getValue());
    }
}
Also used : Attribute(org.dom4j.Attribute) Node(org.dom4j.Node) Element(org.dom4j.Element)

Example 62 with Attribute

use of org.dom4j.Attribute in project atlas by alibaba.

the class ManifestFileUtils method getManifestFileObject.

/**
     * 获取mainifest文件的内容
     *
     * @param manifestFile
     * @return
     */
public static ManifestFileObject getManifestFileObject(File manifestFile) throws DocumentException {
    SAXReader reader = new SAXReader();
    ManifestFileObject manifestFileObject = new ManifestFileObject();
    manifestFileObject.setManifestFile(manifestFile);
    if (manifestFile.exists()) {
        // 读取XML文件
        Document document = reader.read(manifestFile);
        // 得到根节点
        Element root = document.getRootElement();
        for (Attribute attribute : root.attributes()) {
            if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                manifestFileObject.addManifestProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
            } else {
                manifestFileObject.addManifestProperty(attribute.getName(), attribute.getValue());
            }
        }
        Element useSdkElement = root.element("uses-sdk");
        Element applicationElement = root.element("application");
        if (null != useSdkElement) {
            for (Attribute attribute : useSdkElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addUseSdkProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addUseSdkProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
        if (null != applicationElement) {
            for (Attribute attribute : applicationElement.attributes()) {
                if (StringUtils.isNotBlank(attribute.getNamespacePrefix())) {
                    manifestFileObject.addApplicationProperty(attribute.getNamespacePrefix() + ":" + attribute.getName(), attribute.getValue());
                } else {
                    manifestFileObject.addApplicationProperty(attribute.getName(), attribute.getValue());
                }
            }
        }
    }
    return manifestFileObject;
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Document(org.dom4j.Document)

Example 63 with Attribute

use of org.dom4j.Attribute in project tdi-studio-se by Talend.

the class ChangeMappingFileMigrationTask method changeSAPHanaMappingFile.

private void changeSAPHanaMappingFile(URL url) {
    File dir = new File(url.getFile());
    File target = null;
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (file.getName().equals("mapping_SAPHana.xml")) {
                //$NON-NLS-1$
                target = file;
                break;
            }
        }
    }
    if (target != null) {
        try {
            SAXReader reader = new SAXReader();
            Document document = reader.read(target);
            Element root = document.getRootElement();
            //$NON-NLS-1$
            Element node = root.element("dbms");
            //$NON-NLS-1$
            Attribute attr = node.attribute("label");
            if (attr != null && attr.getValue().equals("Mapping SAP Hana")) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                attr.setValue("Mapping SAPHana");
                target.delete();
                XMLWriter writer = new XMLWriter(new FileWriter(target));
                writer.write(document);
                writer.close();
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) FileWriter(java.io.FileWriter) Document(org.dom4j.Document) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 64 with Attribute

use of org.dom4j.Attribute in project tdi-studio-se by Talend.

the class JobJavaScriptsWSManager method editWSDDFile.

/**
     * DOC x Comment method "genWebInfoForder".
     * 
     * @param list
     */
private void editWSDDFile(ProcessItem processItem) {
    String projectName = getCorrespondingProjectName(processItem);
    String selectedProcessVersion = processItem.getProperty().getVersion();
    if (!isMultiNodes() && this.getSelectedJobVersion() != null) {
        selectedProcessVersion = this.getSelectedJobVersion();
    }
    String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), selectedProcessVersion);
    String deployFileName = getTmpFolder() + PATH_SEPARATOR + projectName + PATH_SEPARATOR + jobFolderName + PATH_SEPARATOR + //$NON-NLS-1$
    "deploy.wsdd";
    //$NON-NLS-1$
    String serverConfigFile = getTmpFolder() + PATH_SEPARATOR + "server-config.wsdd";
    File deployFile = new File(deployFileName);
    if (!deployFile.exists()) {
        //$NON-NLS-1$
        log.error(org.talend.repository.i18n.Messages.getString("JobJavaScriptsWSManager.errorMessage"));
        return;
    }
    // edit the server-config.wsdd file
    try {
        File wsddFile = new File(serverConfigFile);
        BufferedReader reader = new BufferedReader(new FileReader(wsddFile));
        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(reader);
        BufferedReader wsdlreader = new BufferedReader(new FileReader(deployFile));
        SAXReader wsdlsaxReader = new SAXReader();
        Document wsdldoc = wsdlsaxReader.read(wsdlreader);
        Element wsdlroot = wsdldoc.getRootElement();
        //$NON-NLS-1$
        Element element = wsdlroot.element("service");
        //$NON-NLS-1$
        List<Element> elements = element.elements("arrayMapping");
        for (Element item : elements) {
            //$NON-NLS-1$
            Attribute attribute = item.attribute("qname");
            item.remove(attribute);
            //$NON-NLS-1$ //$NON-NLS-2$
            attribute.setValue(attribute.getValue().replaceFirst(">", ""));
            item.add(attribute);
        }
        Element root = doc.getRootElement();
        List<Node> content = root.content();
        for (int i = 0; i < content.size(); i++) {
            Node n = content.get(i);
            if (n instanceof Element) {
                if (n.getName().equals("transport")) {
                    //$NON-NLS-1$
                    content.add(i - 1, element);
                    break;
                }
            }
        }
        //$NON-NLS-1$
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(serverConfigFile), "UTF-8"));
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter output = new XMLWriter(writer, format);
        output.write(doc);
        output.flush();
        output.close();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : Attribute(org.dom4j.Attribute) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Node(org.dom4j.Node) OutputFormat(org.dom4j.io.OutputFormat) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 65 with Attribute

use of org.dom4j.Attribute in project CodeUtils by boredream.

the class TempUtils method compareStrings.

public static void compareStrings() {
    List<String> hasStrName = new ArrayList<String>();
    // save to
    File file = new File("D:\\work\\BusinessCMT2.0\\res\\values-en\\strings.xml");
    Document valuesDoc = XmlUtil.read(file);
    Element rootElement = valuesDoc.getRootElement();
    List<Element> elements = rootElement.elements();
    for (Element element : elements) {
        Attribute nameAtt = element.attribute("name");
        String name = nameAtt.getValue();
        hasStrName.add(name);
    }
    // save to
    File fileChn = new File("D:\\work\\BusinessCMT2.0\\res\\values\\strings.xml");
    Document valuesDocChn = XmlUtil.read(fileChn);
    Element rootElementChn = valuesDocChn.getRootElement();
    List<Element> elementsChn = rootElementChn.elements();
    for (Element element : elementsChn) {
        Attribute nameAtt = element.attribute("name");
        String name = nameAtt.getValue();
        if (!hasStrName.contains(name)) {
            System.out.println(element.getText());
        }
    }
}
Also used : Attribute(org.dom4j.Attribute) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Document(org.dom4j.Document) File(java.io.File)

Aggregations

Attribute (org.dom4j.Attribute)114 Element (org.dom4j.Element)88 Document (org.dom4j.Document)30 ArrayList (java.util.ArrayList)28 List (java.util.List)26 Iterator (java.util.Iterator)23 Node (org.dom4j.Node)14 HashMap (java.util.HashMap)12 File (java.io.File)11 SAXReader (org.dom4j.io.SAXReader)11 IOException (java.io.IOException)10 Map (java.util.Map)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 QTIObject (org.olat.ims.qti.editor.beecom.objects.QTIObject)6 Namespace (org.dom4j.Namespace)5 QName (org.dom4j.QName)5 PropertyString (org.pentaho.commons.util.repository.type.PropertyString)5 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 OutcomesProcessing (org.olat.ims.qti.editor.beecom.objects.OutcomesProcessing)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)3