org.jdom.Element

Here are the examples of the java api class org.jdom.Element taken from open source projects.

1. GeneralSettings#writeExternal()

Project: consulo
Source File: GeneralSettings.java
View license
@Override
public void writeExternal(Element parentNode) {
    if (myBrowserPath != null) {
        Element element = new Element(ELEMENT_OPTION);
        element.setAttribute(ATTRIBUTE_NAME, OPTION_BROWSER_PATH);
        element.setAttribute(ATTRIBUTE_VALUE, myBrowserPath);
        parentNode.addContent(element);
    }
    Element optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_LAST_TIP);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Integer.toString(myLastTip));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_SHOW_TIPS_ON_STARTUP);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myShowTipsOnStartup));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_SHOW_OCCUPIED_MEMORY);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myShowOccupiedMemory));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_REOPEN_LAST_PROJECT);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myReopenLastProject));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_AUTO_SYNC_FILES);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(mySyncOnFrameActivation));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_AUTO_SAVE_FILES);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(mySaveOnFrameDeactivation));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_AUTO_SAVE_IF_INACTIVE);
    optionElement.setAttribute(ATTRIBUTE_VALUE, (myAutoSaveIfInactive ? Boolean.TRUE : Boolean.FALSE).toString());
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_INACTIVE_TIMEOUT);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Integer.toString(myInactiveTimeout));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_USE_SAFE_WRITE);
    optionElement.setAttribute(ATTRIBUTE_VALUE, (myUseSafeWrite ? Boolean.TRUE : Boolean.FALSE).toString());
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_USE_DEFAULT_BROWSER);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myUseDefaultBrowser));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_CONFIRM_EXTRACT_FILES);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myConfirmExtractFiles));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_SEARCH_IN_BACKGROUND);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(mySearchInBackground));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_CONFIRM_EXIT);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Boolean.toString(myConfirmExit));
    parentNode.addContent(optionElement);
    optionElement = new Element(ELEMENT_OPTION);
    optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_CONFIRM_OPEN_NEW_PROJECT);
    optionElement.setAttribute(ATTRIBUTE_VALUE, Integer.toString(myConfirmOpenNewProject));
    parentNode.addContent(optionElement);
    if (myLastProjectLocation != null) {
        optionElement = new Element(ELEMENT_OPTION);
        optionElement.setAttribute(ATTRIBUTE_NAME, OPTION_LAST_PROJECT_LOCATION);
        optionElement.setAttribute(ATTRIBUTE_VALUE, myLastProjectLocation);
        parentNode.addContent(optionElement);
    }
}

2. MarkdownGlobalSettings#getState()

View license
/**
     * Get the settings state as a DOM element.
     *
     * @return an ready to serialize DOM {@link Element}.
     * @see {@link #loadState(org.jdom.Element)}
     */
public Element getState() {
    final Element element = new Element("MarkdownSettings");
    element.setAttribute("parsingTimeout", Integer.toString(parsingTimeout));
    element.setAttribute("smarts", Boolean.toString(smarts));
    element.setAttribute("quotes", Boolean.toString(quotes));
    element.setAttribute("abbreviations", Boolean.toString(abbreviations));
    element.setAttribute("hardWraps", Boolean.toString(hardWraps));
    element.setAttribute("autoLinks", Boolean.toString(autoLinks));
    element.setAttribute("wikiLinks", Boolean.toString(wikiLinks));
    element.setAttribute("tables", Boolean.toString(tables));
    element.setAttribute("definitions", Boolean.toString(definitions));
    element.setAttribute("fencedCodeBlocks", Boolean.toString(fencedCodeBlocks));
    element.setAttribute("suppressHTMLBlocks", Boolean.toString(suppressHTMLBlocks));
    element.setAttribute("suppressInlineHTML", Boolean.toString(suppressInlineHTML));
    element.setAttribute("strikethrough", Boolean.toString(strikethrough));
    return element;
}

3. Browser#asXml()

Project: jsunit
Source File: Browser.java
View license
public Element asXml() {
    Element browserElement = new Element(BROWSER);
    Element fullFileNameElement = new Element(FULL_FILE_NAME);
    fullFileNameElement.setText(getFullFileName());
    browserElement.addContent(fullFileNameElement);
    Element idElement = new Element(ID);
    idElement.setText(String.valueOf(getId()));
    browserElement.addContent(idElement);
    Element displayNameElement = new Element("displayName");
    displayNameElement.setText(getDisplayName());
    browserElement.addContent(displayNameElement);
    Element logoElement = new Element("logoPath");
    logoElement.setText(getLogoPath());
    browserElement.addContent(logoElement);
    return browserElement;
}

4. PathMacrosCollectorTest#testCollectMacros()

View license
public void testCollectMacros() {
    Element root = new Element("root");
    root.addContent(new Text("$MACro1$ some text $macro2$ other text $MACRo3$"));
    root.addContent(new Text("$macro4$ some text"));
    root.addContent(new Text("some text$macro5$"));
    root.addContent(new Text("file:$mac_ro6$"));
    root.addContent(new Text("jar://$macr.o7$ "));
    root.addContent(new Text("$mac-ro8$ "));
    root.addContent(new Text("$$$ "));
    root.addContent(new Text("$c:\\a\\b\\c$ "));
    root.addContent(new Text("$Revision 1.23$"));
    root.addContent(new Text("file://$root$/some/path/just$file$name.txt"));
    final Set<String> macros = PathMacrosCollector.getMacroNames(root, null, new PathMacrosImpl());
    UsefulTestCase.assertSameElements(macros, "MACro1", "macro4", "mac_ro6", "macr.o7", "mac-ro8", "root");
}

5. TodoView#getState()

Project: consulo
Source File: TodoView.java
View license
@Override
public Element getState() {
    Element element = new Element("TodoView");
    if (myContentManager != null) {
        // all panel were constructed
        Content content = myContentManager.getSelectedContent();
        element.setAttribute(ATTRIBUTE_SELECTED_INDEX, Integer.toString(myContentManager.getIndexOfContent(content)));
    }
    Element selectedFileElement = new Element(ELEMENT_TODO_PANEL);
    selectedFileElement.setAttribute(ATTRIBUTE_ID, VALUE_SELECTED_FILE);
    myCurrentPanelSettings.writeExternal(selectedFileElement);
    element.addContent(selectedFileElement);
    Element allElement = new Element(ELEMENT_TODO_PANEL);
    allElement.setAttribute(ATTRIBUTE_ID, VALUE_ALL);
    myAllPanelSettings.writeExternal(allElement);
    element.addContent(allElement);
    Element changeListElement = new Element(ELEMENT_TODO_PANEL);
    changeListElement.setAttribute(ATTRIBUTE_ID, VALUE_DEFAULT_CHANGELIST);
    myChangeListTodosPanelSettings.writeExternal(changeListElement);
    element.addContent(changeListElement);
    return element;
}

6. PathMacrosCollectorTest#testCollectMacros()

View license
public void testCollectMacros() {
    Element root = new Element("root");
    root.addContent(new Text("$MACro1$ some text $macro2$ other text $MACRo3$"));
    root.addContent(new Text("$macro4$ some text"));
    root.addContent(new Text("some text$macro5$"));
    root.addContent(new Text("file:$mac_ro6$"));
    root.addContent(new Text("jar://$macr.o7$ "));
    root.addContent(new Text("$mac-ro8$ "));
    root.addContent(new Text("$$$ "));
    root.addContent(new Text("$c:\\a\\b\\c$ "));
    root.addContent(new Text("$Revision 1.23$"));
    final Set<String> macros = PathMacrosService.getInstance().getMacroNames(root, null, new PathMacrosImpl());
    assertEquals(5, macros.size());
    assertTrue(macros.contains("MACro1"));
    assertTrue(macros.contains("macro4"));
    assertTrue(macros.contains("mac_ro6"));
    assertTrue(macros.contains("macr.o7"));
    assertTrue(macros.contains("mac-ro8"));
}

7. GerritSettings#getState()

View license
public Element getState() {
    final Element element = new Element(GERRIT_SETTINGS_TAG);
    element.setAttribute(LOGIN, (getLogin() != null ? getLogin() : ""));
    element.setAttribute(HOST, (getHost() != null ? getHost() : ""));
    element.setAttribute(LIST_ALL_CHANGES, "" + getListAllChanges());
    element.setAttribute(AUTOMATIC_REFRESH, "" + getAutomaticRefresh());
    element.setAttribute(REFRESH_TIMEOUT, "" + getRefreshTimeout());
    element.setAttribute(REVIEW_NOTIFICATIONS, "" + getReviewNotifications());
    element.setAttribute(PUSH_TO_GERRIT, "" + getPushToGerrit());
    element.setAttribute(SHOW_CHANGE_NUMBER_COLUMN, "" + getShowChangeNumberColumn());
    element.setAttribute(SHOW_CHANGE_ID_COLUMN, "" + getShowChangeIdColumn());
    return element;
}

8. FormatInfoPrinter#createSpacingElement()

Project: consulo
Source File: FormatInfoPrinter.java
View license
private Element createSpacingElement(final Spacing spacing) {
    final Element result = new Element("Spacing");
    final SpacingImpl impl = ((SpacingImpl) spacing);
    result.setAttribute("keepBlankLines", String.valueOf(impl.getKeepBlankLines()));
    result.setAttribute("keepLineBreaks", String.valueOf(impl.shouldKeepLineFeeds()));
    result.setAttribute("minspaces", String.valueOf(impl.getMinSpaces()));
    result.setAttribute("maxspaces", String.valueOf(impl.getMaxSpaces()));
    result.setAttribute("minlinefeeds", String.valueOf(impl.getMinLineFeeds()));
    result.setAttribute("readOnly", String.valueOf(impl.isReadOnly()));
    result.setAttribute("safe", String.valueOf(impl.isSafe()));
    return result;
}

9. MartServiceXMLHandler#datasetToElement()

View license
/**
	 * Converts a <code>MartDataset</code> to an XML element.
	 * 
	 * @param dataset
	 *            the <code>MartDataset</code> to serialize
	 * @param namespace
	 *            the <code>Namespace</code> to use when constructing the
	 *            <code>Element</code>
	 * @return an XML serialization of the <code>MartDataset</code>
	 */
public static Element datasetToElement(MartDataset dataset, Namespace namespace) {
    Element element = new Element(MART_DATASET_ELEMENT, namespace);
    element.setAttribute(DISPLAY_NAME_ATTRIBUTE, dataset.getDisplayName());
    element.setAttribute(NAME_ATTRIBUTE, dataset.getName());
    element.setAttribute(TYPE_ATTRIBUTE, dataset.getType());
    element.setAttribute(INITIAL_BATCH_SIZE_ATTRIBUTE, String.valueOf(dataset.getInitialBatchSize()));
    element.setAttribute(MAXIMUM_BATCH_SIZE_ATTRIBUTE, String.valueOf(dataset.getMaximumBatchSize()));
    element.setAttribute(VISIBLE_ATTRIBUTE, String.valueOf(dataset.isVisible()));
    if (dataset.getInterface() != null) {
        element.setAttribute(INTERFACE_ATTRIBUTE, dataset.getInterface());
    }
    if (dataset.getModified() != null) {
        element.setAttribute(MODIFIED_ATTRIBUTE, dataset.getModified());
    }
    element.addContent(locationToElement(dataset.getMartURLLocation(), namespace));
    return element;
}

10. FormatInfoPrinter#createSpacingElement()

View license
private Element createSpacingElement(final Spacing spacing) {
    final Element result = new Element("Spacing");
    final SpacingImpl impl = ((SpacingImpl) spacing);
    result.setAttribute("keepBlankLines", String.valueOf(impl.getKeepBlankLines()));
    result.setAttribute("keepLineBreaks", String.valueOf(impl.shouldKeepLineFeeds()));
    result.setAttribute("minspaces", String.valueOf(impl.getMinSpaces()));
    result.setAttribute("maxspaces", String.valueOf(impl.getMaxSpaces()));
    result.setAttribute("minlinefeeds", String.valueOf(impl.getMinLineFeeds()));
    result.setAttribute("readOnly", String.valueOf(impl.isReadOnly()));
    result.setAttribute("safe", String.valueOf(impl.isSafe()));
    return result;
}

11. Commander#getState()

Project: intellij-community
Source File: Commander.java
View license
@Override
public Element getState() {
    Element element = new Element("commander");
    if (myLeftPanel == null || myRightPanel == null) {
        return element;
    }
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    Element e = new Element(ELEMENT_LEFTPANEL);
    element.addContent(e);
    writePanel(myLeftPanel, e);
    e = new Element(ELEMENT_RIGHTPANEL);
    element.addContent(e);
    writePanel(myRightPanel, e);
    e = new Element(ELEMENT_SPLITTER);
    element.addContent(e);
    e.setAttribute(ATTRIBUTE_PROPORTION, Float.toString(mySplitter.getProportion()));
    if (!MOVE_FOCUS) {
        e = new Element(ELEMENT_OPTION);
        element.addContent(e);
        //noinspection HardCodedStringLiteral
        e.setAttribute(ATTRIBUTE_MOVE_FOCUS, "false");
    }
    return element;
}

12. SLAEventBean#getStatusEvent()

Project: oozie
Source File: SLAEventBean.java
View license
private Element getStatusEvent(String tag) {
    Element eStat = new Element(tag);
    eStat.addContent(createATagElement("sequence-id", String.valueOf(getEvent_id())));
    Element e = new Element("status");
    e.addContent(createATagElement("sla-id", getSlaId()));
    e.addContent(createATagElement("status-timestamp", getDateString(getStatusTimestamp())));
    e.addContent(createATagElement("job-status", getJobStatus().toString()));
    e.addContent(createATagElement("job-data", getJobData()));
    eStat.addContent(e);
    return eStat;
}

13. ProjectStatus#ccTrayXmlElement()

Project: gocd
Source File: ProjectStatus.java
View license
public Element ccTrayXmlElement(String fullContextPath) {
    Element element = new Element("Project");
    element.setAttribute("name", name);
    element.setAttribute("activity", activity);
    element.setAttribute("lastBuildStatus", lastBuildStatus);
    element.setAttribute("lastBuildLabel", lastBuildLabel);
    element.setAttribute("lastBuildTime", DateUtils.formatIso8601ForCCTray(lastBuildTime));
    element.setAttribute("webUrl", fullContextPath + "/" + webUrl);
    if (!breakers.isEmpty()) {
        addBreakers(element);
    }
    return element;
}

14. XMLUtilities#renameSimple()

View license
/**
	 *
	 * @param oldName
	 * @param newName
	 * @param type
	 * @param element
	 * @return
	 * @throws MobyException
	 */
public static Element renameSimple(String newName, String type, Element element) throws MobyException {
    Element e = (Element) element.clone();
    Element mobyData = extractMobyData(e);
    String queryID = getQueryID(e);
    Element serviceNotes = getServiceNotes(e);
    Element simple = mobyData.getChild("Simple");
    if (simple == null)
        simple = mobyData.getChild("Simple", MOBY_NS);
    if (simple == null) {
        return e;
    }
    simple.removeAttribute("articleName");
    simple.removeAttribute("articleName", MOBY_NS);
    simple.setAttribute("articleName", newName, MOBY_NS);
    return createMobyDataElementWrapper(simple, queryID, serviceNotes);
}

15. XMLUtilities#createMobyDataWrapper()

View license
public static Element createMobyDataWrapper(String queryID, Element serviceNotes) throws MobyException {
    Element e = null;
    if (serviceNotes != null)
        e = (Element) serviceNotes.clone();
    Element MOBY = new Element("MOBY", MOBY_NS);
    Element mobyContent = new Element("mobyContent", MOBY_NS);
    if (e != null)
        mobyContent.addContent(e.detach());
    Element mobyData = new Element("mobyData", MOBY_NS);
    mobyData.setAttribute("queryID", queryID, MOBY_NS);
    MOBY.addContent(mobyContent);
    mobyContent.addContent(mobyData);
    return MOBY;
}

16. ClusterMapper#mapServer()

Project: voldemort
Source File: ClusterMapper.java
View license
private Element mapServer(Node node, boolean displayZones) {
    Element server = new Element(SERVER_ELMT);
    server.addContent(new Element(SERVER_ID_ELMT).setText(Integer.toString(node.getId())));
    server.addContent(new Element(HOST_ELMT).setText(node.getHost()));
    server.addContent(new Element(HTTP_PORT_ELMT).setText(Integer.toString(node.getHttpPort())));
    server.addContent(new Element(SOCKET_PORT_ELMT).setText(Integer.toString(node.getSocketPort())));
    server.addContent(new Element(ADMIN_PORT_ELMT).setText(Integer.toString(node.getAdminPort())));
    String serverPartitionsText = StringUtils.join(node.getPartitionIds().toArray(), ", ");
    server.addContent(new Element(SERVER_PARTITIONS_ELMT).setText(serverPartitionsText));
    if (displayZones)
        server.addContent(new Element(ZONE_ID_ELMT).setText(Integer.toString(node.getZoneId())));
    return server;
}

17. FilterInfo#writeExternal()

Project: consulo
Source File: FilterInfo.java
View license
@Override
public void writeExternal(Element filterElement) {
    Element option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_NAME);
    if (myName != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myName);
    }
    option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_DESCRIPTION);
    if (myDescription != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myDescription);
    }
    option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_REGEXP);
    if (myRegExp != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myRegExp);
    }
}

18. ExternalizablePropertyTest#testReadList()

View license
public void testReadList() throws InvalidDataException {
    Element containerElement = new Element("xxx");
    Element listElement = new Element("list");
    containerElement.addContent(listElement);
    listElement.addContent(new Element("unknown"));
    listElement.addContent(new Element("item"));
    listElement.addContent(new Element("unknown"));
    myContainer.registerProperty(PROPERTY, "item", EXTERNALIZER);
    myContainer.readExternal(containerElement);
    List<MockJDOMExternalizable> list = PROPERTY.get(myContainer);
    assertEquals(1, list.size());
}

19. GoControlLog#writeLogFile()

Project: gocd
Source File: GoControlLog.java
View license
/**
     * Writes the current build log to the appropriate directory and filename.
     */
public void writeLogFile(Date now) throws IOException {
    String logFilename = decideLogfileName(now);
    // Add the logDir as an info element
    Element logDirElement = new Element("property");
    logDirElement.setAttribute("name", "logdir");
    logDirElement.setAttribute("value", new File(logDir).getAbsolutePath());
    buildLog.getChild("info").addContent(logDirElement);
    // Add the logFile as an info element
    Element logFileElement = new Element("property");
    logFileElement.setAttribute("name", "logfile");
    logFileElement.setAttribute("value", logFilename);
    buildLog.getChild("info").addContent(logFileElement);
    File logfile = new File(logDir, logFilename);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing log file [" + logfile.getAbsolutePath() + "]");
    }
    writeLogFile(logfile, buildLog);
}

20. XMLUtilities#createServiceInput()

View license
/**
	 *
	 * @param elements
	 *            the fully wrapped moby simples and/or collections to wrap an
	 *            input message around
	 * @param queryID
	 *            the queryID for this input
	 * @return a fully wrapped message with an appropriate queryID and elements
	 *         added to it
	 * @throws MobyException
	 *             if an element is invalid.
	 */
public static Element createServiceInput(Element[] elements, String queryID) throws MobyException {
    // create the main elements
    Element MOBY = new Element("MOBY", MOBY_NS);
    Element mobyContent = new Element("mobyContent", MOBY_NS);
    Element mobyData = new Element("mobyData", MOBY_NS);
    mobyData.setAttribute("queryID", (queryID == null ? "" : queryID), MOBY_NS);
    // add the content
    MOBY.addContent(mobyContent);
    mobyContent.addContent(mobyData);
    // iterate through elements adding the content of mobyData
    for (int i = 0; i < elements.length; i++) {
        Element e = (Element) elements[i].clone();
        e = extractMobyData(e);
        mobyData.addContent(e.cloneContent());
    }
    return MOBY;
}

21. XMLUtilities#renameCollection()

View license
/**
	 *
	 * @param newName
	 *            the new name for this fully wrapped BioMOBY collection
	 * @param element
	 *            the fully wrapped BioMOBY collection
	 * @return @return an element 'Collection' representing the renamed collection
	 * @throws MobyException
	 *             if the message is invalid
	 */
public static Element renameCollection(String newName, Element element) throws MobyException {
    Element e = (Element) element.clone();
    Element mobyData = extractMobyData(e);
    Element coll = mobyData.getChild("Collection");
    if (coll == null)
        coll = mobyData.getChild("Collection", MOBY_NS);
    if (coll == null)
        return e;
    coll.removeAttribute("articleName");
    coll.removeAttribute("articleName", MOBY_NS);
    coll.setAttribute("articleName", newName, MOBY_NS);
    return coll;
}

22. EntryPointsConverterTest#doTest()

View license
private static void doTest(String type, String fqName, String expectedFQName) throws Exception {
    final Element entryPoints = setUpEntryPoint(type, fqName);
    final HashMap<String, SmartRefElementPointer> persistentEntryPoints = new HashMap<String, SmartRefElementPointer>();
    EntryPointsManagerBase.convert(entryPoints, persistentEntryPoints);
    final Element testElement = new Element("comp");
    EntryPointsManagerBase.writeExternal(testElement, persistentEntryPoints, new JDOMExternalizableStringList());
    final Element expectedEntryPoints = setUpEntryPoint(type, expectedFQName);
    expectedEntryPoints.setAttribute("version", "2.0");
    final Element expected = new Element("comp");
    expected.addContent(expectedEntryPoints);
    assertTrue(JDOMUtil.areElementsEqual(testElement, expected));
}

23. FilterInfo#writeExternal()

Project: intellij-community
Source File: FilterInfo.java
View license
@Override
public void writeExternal(Element filterElement) {
    Element option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_NAME);
    if (myName != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myName);
    }
    option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_DESCRIPTION);
    if (myDescription != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myDescription);
    }
    option = new Element(ELEMENT_OPTION);
    filterElement.addContent(option);
    option.setAttribute(ATTRIBUTE_NAME, FILTER_REGEXP);
    if (myRegExp != null) {
        option.setAttribute(ATTRIBUTE_VALUE, myRegExp);
    }
}

24. ExternalizablePropertyTest#testReadList()

View license
public void testReadList() throws InvalidDataException {
    Element containerElement = new Element("xxx");
    Element listElement = new Element("list");
    containerElement.addContent(listElement);
    listElement.addContent(new Element("unknown"));
    listElement.addContent(new Element("item"));
    listElement.addContent(new Element("unknown"));
    myContainer.registerProperty(PROPERTY, "item", EXTERNALIZER);
    myContainer.readExternal(containerElement);
    List<MockJDOMExternalizable> list = PROPERTY.get(myContainer);
    assertEquals(1, list.size());
}

25. RestUtils#constructSerializerInfoXml()

Project: voldemort
Source File: RestUtils.java
View license
/**
     * Given a storedefinition, constructs the xml string to be sent out in
     * response to a "schemata" fetch request
     * 
     * @param storeDefinition
     * @return serialized store definition
     */
public static String constructSerializerInfoXml(StoreDefinition storeDefinition) {
    Element store = new Element(StoreDefinitionsMapper.STORE_ELMT);
    store.addContent(new Element(StoreDefinitionsMapper.STORE_NAME_ELMT).setText(storeDefinition.getName()));
    Element keySerializer = new Element(StoreDefinitionsMapper.STORE_KEY_SERIALIZER_ELMT);
    StoreDefinitionsMapper.addSerializer(keySerializer, storeDefinition.getKeySerializer());
    store.addContent(keySerializer);
    Element valueSerializer = new Element(StoreDefinitionsMapper.STORE_VALUE_SERIALIZER_ELMT);
    StoreDefinitionsMapper.addSerializer(valueSerializer, storeDefinition.getValueSerializer());
    store.addContent(valueSerializer);
    XMLOutputter serializer = new XMLOutputter(Format.getPrettyFormat());
    return serializer.outputString(store);
}

26. WindowManagerImpl#getState()

Project: consulo
Source File: WindowManagerImpl.java
View license
@Nullable
@Override
public Element getState() {
    Element frameState = getFrameState();
    if (frameState == null) {
        return null;
    }
    Element state = new Element("state");
    state.addContent(frameState);
    // Save default layout
    Element layoutElement = new Element(DesktopLayout.TAG);
    state.addContent(layoutElement);
    myLayout.writeExternal(layoutElement);
    return state;
}

27. PathMacrosCollectorTest#testWithFilter()

View license
public void testWithFilter() throws Exception {
    Element root = new Element("root");
    final Element testTag = new Element("test");
    testTag.setAttribute("path", "$MACRO$");
    testTag.setAttribute("ignore", "$PATH$");
    root.addContent(testTag);
    final Set<String> macros = PathMacrosCollectorImpl.getMacroNames(root, null, new PathMacrosImpl());
    assertEquals(2, macros.size());
    assertTrue(macros.contains("MACRO"));
    assertTrue(macros.contains("PATH"));
    final Set<String> filtered = PathMacrosCollectorImpl.getMacroNames(root, new PathMacroFilter() {

        @Override
        public boolean skipPathMacros(Attribute attribute) {
            return "ignore".equals(attribute.getName());
        }
    }, new PathMacrosImpl());
    assertEquals(1, filtered.size());
    assertTrue(macros.contains("MACRO"));
}

28. VimPlugin#getState()

Project: ideavim
Source File: VimPlugin.java
View license
@Override
public Element getState() {
    LOG.debug("Saving state");
    final Element element = new Element("ideavim");
    // Save whether the plugin is enabled or not
    final Element state = new Element("state");
    state.setAttribute("version", Integer.toString(STATE_VERSION));
    state.setAttribute("enabled", Boolean.toString(enabled));
    element.addContent(state);
    mark.saveData(element);
    register.saveData(element);
    search.saveData(element);
    history.saveData(element);
    key.saveData(element);
    editor.saveData(element);
    return element;
}

29. UsageStatisticsPersistenceComponent#getState()

View license
@Override
public Element getState() {
    Element element = new Element("state");
    for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages()).entrySet()) {
        Element projectElement = new Element(GROUP_TAG);
        projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
        projectElement.setAttribute(GROUP_PRIORITY_ATTR, Double.toString(entry.getKey().getPriority()));
        projectElement.setAttribute(DATA_ATTR, ConvertUsagesUtil.convertValueMap(entry.getValue()));
        element.addContent(projectElement);
    }
    element.setAttribute(LAST_TIME_ATTR, String.valueOf(getLastTimeSent()));
    element.setAttribute(IS_ALLOWED_ATTR, String.valueOf(isAllowed()));
    element.setAttribute(SHOW_NOTIFICATION_ATTR, String.valueOf(isShowNotification()));
    element.setAttribute(PERIOD_ATTR, myPeriod.getName());
    return element;
}

30. WindowManagerImpl#getState()

View license
@Nullable
@Override
public Element getState() {
    Element frameState = getFrameState();
    if (frameState == null) {
        return null;
    }
    Element state = new Element("state");
    state.addContent(frameState);
    // Save default layout
    Element layoutElement = new Element(DesktopLayout.TAG);
    state.addContent(layoutElement);
    myLayout.writeExternal(layoutElement);
    return state;
}

31. PathMacrosCollectorTest#testWithRecursiveFilter()

View license
public void testWithRecursiveFilter() throws Exception {
    Element root = new Element("root");
    final Element configuration = new Element("configuration");
    configuration.setAttribute("value", "some text$macro5$fdsjfhdskjfsd$MACRO$");
    configuration.setAttribute("value2", "file://$root$/some/path/just$file$name.txt");
    root.addContent(configuration);
    final Set<String> macros = PathMacrosCollector.getMacroNames(root, new PathMacroFilter() {

        @Override
        public boolean recursePathMacros(Attribute attribute) {
            return "value".equals(attribute.getName());
        }
    }, new PathMacrosImpl());
    UsefulTestCase.assertSameElements(macros, "macro5", "MACRO", "root");
}

32. PathMacrosCollectorTest#testWithFilter()

View license
public void testWithFilter() throws Exception {
    Element root = new Element("root");
    final Element testTag = new Element("test");
    testTag.setAttribute("path", "$MACRO$");
    testTag.setAttribute("ignore", "$PATH$");
    root.addContent(testTag);
    final Set<String> macros = PathMacrosCollector.getMacroNames(root, null, new PathMacrosImpl());
    assertEquals(2, macros.size());
    assertTrue(macros.contains("MACRO"));
    assertTrue(macros.contains("PATH"));
    final Set<String> filtered = PathMacrosCollector.getMacroNames(root, new PathMacroFilter() {

        @Override
        public boolean skipPathMacros(Attribute attribute) {
            return "ignore".equals(attribute.getName());
        }
    }, new PathMacrosImpl());
    assertEquals(1, filtered.size());
    assertTrue(macros.contains("MACRO"));
}

33. SubmitMRCommand#getWorkflowXml()

Project: oozie
Source File: SubmitMRCommand.java
View license
/*
     * (non-Javadoc)
     *
     * @see
     * org.apache.oozie.command.wf.SubmitHttpCommand#getWorkflowXml(org.apache
     * .hadoop.conf.Configuration)
     */
@Override
protected String getWorkflowXml(Configuration conf) {
    for (String key : MANDATORY_OOZIE_CONFS) {
        String value = conf.get(key);
        if (value == null) {
            throw new RuntimeException(key + " is not specified");
        }
    }
    Namespace ns = Namespace.getNamespace("uri:oozie:workflow:0.2");
    Element root = new Element("workflow-app", ns);
    root.setAttribute("name", "oozie-mapreduce");
    Element start = new Element("start", ns);
    start.setAttribute("to", "hadoop1");
    root.addContent(start);
    Element action = new Element("action", ns);
    action.setAttribute("name", "hadoop1");
    Element mapreduce = generateMRSection(conf, ns);
    action.addContent(mapreduce);
    Element ok = new Element("ok", ns);
    ok.setAttribute("to", "end");
    action.addContent(ok);
    Element error = new Element("error", ns);
    error.setAttribute("to", "fail");
    action.addContent(error);
    root.addContent(action);
    Element kill = new Element("kill", ns);
    kill.setAttribute("name", "fail");
    Element message = new Element("message", ns);
    message.addContent("Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    kill.addContent(message);
    root.addContent(kill);
    Element end = new Element("end", ns);
    end.setAttribute("name", "end");
    root.addContent(end);
    return XmlUtils.prettyPrint(root).toString();
}

34. SubmitMRXCommand#getWorkflowXml()

Project: oozie
Source File: SubmitMRXCommand.java
View license
/*
     * (non-Javadoc)
     *
     * @see
     * org.apache.oozie.command.wf.SubmitHttpCommand#getWorkflowXml(org.apache
     * .hadoop.conf.Configuration)
     */
@Override
protected String getWorkflowXml(Configuration conf) {
    for (String key : MANDATORY_OOZIE_CONFS) {
        String value = conf.get(key);
        if (value == null) {
            throw new RuntimeException(key + " is not specified");
        }
    }
    Namespace ns = Namespace.getNamespace("uri:oozie:workflow:0.2");
    Element root = new Element("workflow-app", ns);
    root.setAttribute("name", "oozie-mapreduce");
    Element start = new Element("start", ns);
    start.setAttribute("to", "hadoop1");
    root.addContent(start);
    Element action = new Element("action", ns);
    action.setAttribute("name", "hadoop1");
    Element mapreduce = generateMRSection(conf, ns);
    action.addContent(mapreduce);
    Element ok = new Element("ok", ns);
    ok.setAttribute("to", "end");
    action.addContent(ok);
    Element error = new Element("error", ns);
    error.setAttribute("to", "fail");
    action.addContent(error);
    root.addContent(action);
    Element kill = new Element("kill", ns);
    kill.setAttribute("name", "fail");
    Element message = new Element("message", ns);
    message.addContent("Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    kill.addContent(message);
    root.addContent(kill);
    Element end = new Element("end", ns);
    end.setAttribute("name", "end");
    root.addContent(end);
    return XmlUtils.prettyPrint(root).toString();
}

35. SubmitPigCommand#getWorkflowXml()

Project: oozie
Source File: SubmitPigCommand.java
View license
/*
     * (non-Javadoc)
     *
     * @see
     * org.apache.oozie.command.wf.SubmitHttpCommand#getWorkflowXml(org.apache
     * .hadoop.conf.Configuration)
     */
@Override
protected String getWorkflowXml(Configuration conf) {
    for (String key : MANDATORY_OOZIE_CONFS) {
        String value = conf.get(key);
        if (value == null) {
            throw new RuntimeException(key + " is not specified");
        }
    }
    Namespace ns = Namespace.getNamespace("uri:oozie:workflow:0.2");
    Element root = new Element("workflow-app", ns);
    root.setAttribute("name", "oozie-pig");
    Element start = new Element("start", ns);
    start.setAttribute("to", "pig1");
    root.addContent(start);
    Element action = new Element("action", ns);
    action.setAttribute("name", "pig1");
    Element pig = generatePigSection(conf, ns);
    action.addContent(pig);
    Element ok = new Element("ok", ns);
    ok.setAttribute("to", "end");
    action.addContent(ok);
    Element error = new Element("error", ns);
    error.setAttribute("to", "fail");
    action.addContent(error);
    root.addContent(action);
    Element kill = new Element("kill", ns);
    kill.setAttribute("name", "fail");
    Element message = new Element("message", ns);
    message.addContent("Pig failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    kill.addContent(message);
    root.addContent(kill);
    Element end = new Element("end", ns);
    end.setAttribute("name", "end");
    root.addContent(end);
    return XmlUtils.prettyPrint(root).toString();
}

36. SubmitPigXCommand#getWorkflowXml()

Project: oozie
Source File: SubmitPigXCommand.java
View license
/*
     * (non-Javadoc)
     *
     * @see
     * org.apache.oozie.command.wf.SubmitHttpCommand#getWorkflowXml(org.apache
     * .hadoop.conf.Configuration)
     */
@Override
protected String getWorkflowXml(Configuration conf) {
    for (String key : MANDATORY_OOZIE_CONFS) {
        String value = conf.get(key);
        if (value == null) {
            throw new RuntimeException(key + " is not specified");
        }
    }
    Namespace ns = Namespace.getNamespace("uri:oozie:workflow:0.2");
    Element root = new Element("workflow-app", ns);
    root.setAttribute("name", "oozie-pig");
    Element start = new Element("start", ns);
    start.setAttribute("to", "pig1");
    root.addContent(start);
    Element action = new Element("action", ns);
    action.setAttribute("name", "pig1");
    Element pig = generatePigSection(conf, ns);
    action.addContent(pig);
    Element ok = new Element("ok", ns);
    ok.setAttribute("to", "end");
    action.addContent(ok);
    Element error = new Element("error", ns);
    error.setAttribute("to", "fail");
    action.addContent(error);
    root.addContent(action);
    Element kill = new Element("kill", ns);
    kill.setAttribute("name", "fail");
    Element message = new Element("message", ns);
    message.addContent("Pig failed, error message[${wf:errorMessage(wf:lastErrorNode())}]");
    kill.addContent(message);
    root.addContent(kill);
    Element end = new Element("end", ns);
    end.setAttribute("name", "end");
    root.addContent(end);
    return XmlUtils.prettyPrint(root).toString();
}

37. UsageStatisticsPersistenceComponent#getState()

View license
@Override
public Element getState() {
    Element element = new Element("state");
    for (Map.Entry<GroupDescriptor, Set<UsageDescriptor>> entry : ConvertUsagesUtil.sortDescriptorsByPriority(getSentUsages()).entrySet()) {
        Element projectElement = new Element(GROUP_TAG);
        projectElement.setAttribute(GROUP_ID_ATTR, entry.getKey().getId());
        projectElement.setAttribute(GROUP_PRIORITY_ATTR, Double.toString(entry.getKey().getPriority()));
        projectElement.setAttribute(DATA_ATTR, ConvertUsagesUtil.convertValueMap(entry.getValue()));
        element.addContent(projectElement);
    }
    element.setAttribute(LAST_TIME_ATTR, String.valueOf(getLastTimeSent()));
    element.setAttribute(IS_ALLOWED_ATTR, String.valueOf(isAllowed()));
    element.setAttribute(PERIOD_ATTR, myPeriod.getName());
    return element;
}

38. PathMacrosCollectorTest#testWithRecursiveFilter()

View license
public void testWithRecursiveFilter() throws Exception {
    Element root = new Element("root");
    final Element configuration = new Element("configuration");
    configuration.setAttribute("value", "some text$macro5$fdsjfhdskjfsd$MACRO$");
    root.addContent(configuration);
    final Set<String> macros = PathMacrosCollectorImpl.getMacroNames(root, new PathMacroFilter() {

        @Override
        public boolean recursePathMacros(Attribute attribute) {
            return "value".equals(attribute.getName());
        }
    }, new PathMacrosImpl());
    assertEquals(2, macros.size());
    assertTrue(macros.contains("macro5"));
    assertTrue(macros.contains("MACRO"));
}

39. XmlSerializerTest#testShuffledDeserialize()

Project: consulo
Source File: XmlSerializerTest.java
View license
public void testShuffledDeserialize() {
    BeanWithPublicFields bean = new BeanWithPublicFields();
    bean.INT_V = 987;
    bean.STRING_V = "1234";
    Element element = serialize(bean, null);
    Element node = (Element) element.getChildren().get(0);
    element.removeContent(node);
    element.addContent(node);
    bean = XmlSerializer.deserialize(element, bean.getClass());
    assert bean != null;
    assertEquals(987, bean.INT_V);
    assertEquals("1234", bean.STRING_V);
}

40. LocalMechanismCreator#convert()

View license
public InvocationMechanism convert(Element detailsElement, String mechanismName) {
    ExternalToolLocalInvocationMechanism result = new ExternalToolLocalInvocationMechanism();
    result.setName(mechanismName);
    Element directoryElement = detailsElement.getChild("directory");
    if (directoryElement != null) {
        result.setDirectory(directoryElement.getText());
    }
    Element shellPrefixElement = detailsElement.getChild("shellPrefix");
    if (shellPrefixElement != null) {
        result.setShellPrefix(shellPrefixElement.getText());
    }
    Element linkCommandElement = detailsElement.getChild("linkCommand");
    if (linkCommandElement != null) {
        result.setLinkCommand(linkCommandElement.getText());
    }
    Element retrieveDataElement = detailsElement.getChild("retrieveData");
    result.setRetrieveData(retrieveDataElement != null);
    return result;
}

41. MartServiceXMLHandler#martQueryToElement()

View license
/**
	 * Converts a <code>MartQuery</code> to an XML element.
	 * 
	 * @param martQuery
	 *            the <code>MartQuery</code> to serialize
	 * @param namespace
	 *            the <code>Namespace</code> to use when constructing the
	 *            <code>Element</code>
	 * @return an XML serialization of the <code>MartQuery</code>
	 */
public static Element martQueryToElement(MartQuery martQuery, Namespace namespace) {
    Element element = new Element(MART_QUERY_ELEMENT, namespace);
    element.addContent(martServiceToElement(martQuery.getMartService(), namespace));
    element.addContent(datasetToElement(martQuery.getMartDataset(), namespace));
    element.addContent(QueryXMLHandler.queryToElement(martQuery.getQuery(), namespace));
    Set linkedDatasets = martQuery.getLinkedDatasets();
    if (linkedDatasets.size() > 0) {
        Element linksElement = new Element(LINKED_DATASETS_ELEMENT, namespace);
        for (Iterator iter = linkedDatasets.iterator(); iter.hasNext(); ) {
            String datasetName = (String) iter.next();
            Element datasetElement = new Element(LINKED_DATASETS_ELEMENT, namespace);
            datasetElement.setAttribute(NAME_ATTRIBUTE, datasetName);
            datasetElement.setAttribute(LINK_ATTRIBUTE, martQuery.getLink(datasetName));
            linksElement.addContent(datasetElement);
        }
        element.addContent(linksElement);
    }
    return element;
}

42. XMLUtilities#getSimplesFromCollection()

View license
/**
	 *
	 * @param name
	 *            the name of the collection to extract the simples from.
	 * @param element
	 *            the Element to extract from
	 * @return an array of Elements objects that represent the 'unwrapped'
	 *         simples
	 * @throws MobyException
	 */
public static Element[] getSimplesFromCollection(Element element) throws MobyException {
    Element e = (Element) element.clone();
    Element mobyData = extractMobyData(e);
    Element collection = mobyData.getChild("Collection");
    if (collection == null)
        collection = mobyData.getChild("Collection", MOBY_NS);
    List list = collection.getChildren("Simple");
    if (list.isEmpty())
        list = collection.getChildren("Simple", MOBY_NS);
    if (list.isEmpty())
        return new Element[] {};
    Vector vector = new Vector();
    for (Iterator it = list.iterator(); it.hasNext(); ) {
        vector.add(it.next());
    }
    Element[] elements = new Element[vector.size()];
    vector.copyInto(elements);
    return elements;
}

43. XMLUtilities#getWrappedSimplesFromCollection()

View license
/**
	 *
	 * @param name
	 *            the name of the collection to extract the simples from.
	 * @param element
	 *            the Element to extract from
	 * @return an array of Elements objects that represent the simples, with the
	 *         name of the collection
	 * @throws MobyException
	 *             MobyException if the collection doesnt exist or the xml is
	 *             invalid
	 */
public static Element[] getWrappedSimplesFromCollection(String name, Element element) throws MobyException {
    Element el = (Element) element.clone();
    String queryID = getQueryID(el);
    Element collection = getCollection(name, el);
    Element serviceNotes = getServiceNotes(el);
    List list = collection.getChildren("Simple");
    if (list.isEmpty())
        list = collection.getChildren("Simple", MOBY_NS);
    if (list.isEmpty())
        return new Element[] {};
    Vector vector = new Vector();
    for (Iterator it = list.iterator(); it.hasNext(); ) {
        Element e = (Element) it.next();
        e.setAttribute("articleName", name, MOBY_NS);
        e = createMobyDataElementWrapper(e, queryID + "_split" + queryCount++, serviceNotes);
        vector.add(e);
    }
    Element[] elements = new Element[vector.size()];
    vector.copyInto(elements);
    return elements;
}

44. XMLUtilities#createMultipleInvokations()

View license
/**
	 *
	 * @param elements
	 * @return
	 * @throws MobyException
	 */
public static Element createMultipleInvokations(Element[] elements) throws MobyException {
    Element MOBY = new Element("MOBY", MOBY_NS);
    Element mobyContent = new Element("mobyContent", MOBY_NS);
    Element serviceNotes = null;
    for (int i = 0; i < elements.length; i++) {
        if (serviceNotes == null) {
            serviceNotes = getServiceNotes((Element) elements[i].clone());
            if (serviceNotes != null)
                mobyContent.addContent(serviceNotes.detach());
        }
        Element mobyData = new Element("mobyData", MOBY_NS);
        Element md = extractMobyData((Element) elements[i].clone());
        String queryID = getQueryID((Element) elements[i].clone());
        mobyData.setAttribute("queryID", queryID, MOBY_NS);
        mobyData.addContent(md.cloneContent());
        mobyContent.addContent(mobyData);
    }
    MOBY.addContent(mobyContent);
    return MOBY;
}

45. OPMLExporter#createElement()

Project: RSSOwl
Source File: OPMLExporter.java
View license
private Element createElement(IFolder folder, boolean exportPreferences) {
    Element folderElement = new Element(Tag.OUTLINE.get());
    folderElement.setAttribute(Attributes.TEXT.get(), folder.getName());
    folderElement.setAttribute(Attributes.IS_SET.get(), String.valueOf(folder.getParent() == null), RSSOWL_NS);
    folderElement.setAttribute(Attributes.ID.get(), String.valueOf(folder.getId()), RSSOWL_NS);
    /* Export Preferences if set */
    if (exportPreferences)
        exportPreferences(folderElement, folder);
    return folderElement;
}

46. OvalFileAggregator#buildDocument()

Project: spacewalk
Source File: OvalFileAggregator.java
View license
private void buildDocument() {
    Element defsElement = new Element("definitions");
    attachChildren(defsElement, defs);
    Element testsElement = new Element("tests");
    attachChildren(testsElement, tests);
    Element objectsElement = new Element("objects");
    attachChildren(objectsElement, objects);
    Element statesElement = new Element("states");
    attachChildren(statesElement, states);
    List children = aggregate.getRootElement().getChildren();
    children.add(defsElement);
    children.add(testsElement);
    children.add(objectsElement);
    children.add(statesElement);
}

47. SmartRefElementPointerImpl#writeExternal()

View license
@Override
public void writeExternal(Element parentNode) {
    Element element = new Element(ENTRY_POINT);
    element.setAttribute(TYPE_ATTR, myType);
    element.setAttribute(FQNAME_ATTR, getFQName());
    /*if (myRefElement != null) {
      final RefEntity entity = myRefElement.getOwner();
      if (entity != null) {
        new SmartRefElementPointerImpl(entity, myIsPersistent).writeExternal(element);
      }
    }*/
    parentNode.addContent(element);
}

48. ModuleCompilerPathsManagerImpl#getState()

View license
@Nullable
@Override
public Element getState() {
    if (myInheritOutput) {
        return null;
    }
    Element moduleElement = new Element(MODULE_OUTPUT_TAG);
    moduleElement.setAttribute(NAME, myModule.getName());
    moduleElement.setAttribute(EXCLUDE, String.valueOf(isExcludeOutput()));
    for (Map.Entry<String, VirtualFilePointer> tempEntry : myVirtualFilePointers.entrySet()) {
        final Element elementForOutput = createElementForOutput(tempEntry.getValue());
        elementForOutput.setAttribute(TYPE, tempEntry.getKey());
        moduleElement.addContent(elementForOutput);
    }
    return moduleElement;
}

49. DefaultArrangementSettingsSerializer#serialize()

View license
@Nullable
public Element serialize(@NotNull ArrangementMatchRule rule) {
    Element matcherElement = myMatcherSerializer.serialize(rule.getMatcher());
    if (matcherElement == null) {
        return null;
    }
    Element result = new Element(RULE_ELEMENT_NAME);
    result.addContent(new Element(MATCHER_ELEMENT_NAME).addContent(matcherElement));
    if (rule.getOrderType() != ArrangementMatchRule.DEFAULT_ORDER_TYPE) {
        result.addContent(new Element(ORDER_TYPE_ELEMENT_NAME).setText(rule.getOrderType().getId()));
    }
    return result;
}

50. FileColorConfiguration#save()

Project: consulo
Source File: FileColorConfiguration.java
View license
public void save(@NotNull final Element e) {
    if (!isValid(null)) {
        return;
    }
    final Element tab = new Element(FileColorsModel.FILE_COLOR);
    tab.setAttribute(SCOPE_NAME, getScopeName());
    tab.setAttribute(COLOR, myColorName);
    e.addContent(tab);
}

51. ExternalizablePropertyTest#testWriteList()

View license
public void testWriteList() throws WriteExternalException {
    myContainer.registerProperty(PROPERTY, "item", EXTERNALIZER);
    PROPERTY.getModifiableList(myContainer).add(new MockJDOMExternalizable());
    Element containerElement = new Element("xxx");
    myContainer.writeExternal(containerElement);
    List children = containerElement.getChildren();
    assertEquals(1, children.size());
    Element listElement = (Element) children.get(0);
    assertEquals("list", listElement.getName());
    children = listElement.getChildren();
    assertEquals(1, children.size());
    Element itemElement = (Element) children.get(0);
    assertEquals("item", itemElement.getName());
}

52. ChangeListManagerSerialization#readExternal()

View license
@SuppressWarnings({ "unchecked" })
public void readExternal(final Element element) throws InvalidDataException {
    final List<Element> listNodes = element.getChildren(NODE_LIST);
    for (Element listNode : listNodes) {
        readChangeList(listNode);
    }
    final List<Element> ignoredNodes = element.getChildren(NODE_IGNORED);
    for (Element ignoredNode : ignoredNodes) {
        readFileToIgnore(ignoredNode);
    }
    Element manuallyRemovedFromIgnoredTag = element.getChild(MANUALLY_REMOVED_FROM_IGNORED);
    Set<String> manuallyRemovedFromIgnoredPaths = new HashSet<String>();
    if (manuallyRemovedFromIgnoredTag != null) {
        for (Element tag : manuallyRemovedFromIgnoredTag.getChildren(DIRECTORY_TAG)) {
            manuallyRemovedFromIgnoredPaths.add(tag.getAttributeValue(ATT_PATH));
        }
    }
    myIgnoredIdeaLevel.setDirectoriesManuallyRemovedFromIgnored(manuallyRemovedFromIgnoredPaths);
}

53. DirectoryEntriesTest#shouldListAllArtifactsWhenArtifactsNotPurged()

Project: gocd
Source File: DirectoryEntriesTest.java
View license
@Test
public void shouldListAllArtifactsWhenArtifactsNotPurged() throws Exception {
    HtmlRenderer renderer = new HtmlRenderer("context");
    DirectoryEntries directoryEntries = new DirectoryEntries();
    directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries()));
    directoryEntries.add(new FolderDirectoryEntry("some-artifact", "", new DirectoryEntries()));
    directoryEntries.render(renderer);
    Element document = getRenderedDocument(renderer);
    assertThat(document.getChildren().size(), is(2));
    Element cruiseOutputElement = (Element) document.getChildren().get(0);
    assertThat(cruiseOutputElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output"));
    Element artifactElement = (Element) document.getChildren().get(1);
    assertThat(artifactElement.getChild("div").getChild("span").getChild("a").getTextNormalize(), is("some-artifact"));
}

54. SearchGroup#readData()

Project: ideavim
Source File: SearchGroup.java
View license
public void readData(@NotNull Element element) {
    logger.debug("readData");
    Element search = element.getChild("search");
    if (search == null) {
        return;
    }
    lastSearch = getSafeChildText(search, "last-search");
    lastOffset = getSafeChildText(search, "last-offset");
    lastPattern = getSafeChildText(search, "last-pattern");
    lastReplace = getSafeChildText(search, "last-replace");
    lastSubstitute = getSafeChildText(search, "last-substitute");
    Element dir = search.getChild("last-dir");
    lastDir = Integer.parseInt(dir.getText());
    Element show = search.getChild("show-last");
    final ListOption vimInfo = Options.getInstance().getListOption(Options.VIMINFO);
    final boolean disableHighlight = vimInfo != null && vimInfo.contains("h");
    showSearchHighlight = !disableHighlight && Boolean.valueOf(show.getText());
    if (logger.isDebugEnabled()) {
        logger.debug("show=" + show + "(" + show.getText() + ")");
        logger.debug("showSearchHighlight=" + showSearchHighlight);
    }
}

55. XMLSplitterSerialisationHelper#typeDescriptorToExtensionXML()

View license
/**
	 * Generates the extensions XML that describes the TypeDescriptor to allow
	 * an XMLInputSplitter or XMLOutputSplitter to be reconstructed using
	 * consumeXML.
	 */
public static Element typeDescriptorToExtensionXML(TypeDescriptor descriptor) {
    Element result = new Element("extensions", XScuflNS);
    Element type = null;
    if (descriptor instanceof ComplexTypeDescriptor) {
        type = constructElementForComplexType((ComplexTypeDescriptor) descriptor, new ArrayList<String>());
    } else if (descriptor instanceof ArrayTypeDescriptor) {
        type = constructElementForArrayType((ArrayTypeDescriptor) descriptor, new ArrayList<String>());
    }
    result.addContent(type);
    return result;
}

56. XMLUtilities#getSimplesFromCollection()

View license
/**
	 *
	 * @param name
	 *            the name of the collection to extract the simples from.
	 * @param element
	 *            the Element to extract from
	 * @return an array of Elements objects that represent the simples
	 * @throws MobyException
	 */
public static Element[] getSimplesFromCollection(String name, Element element) throws MobyException {
    Element e = (Element) element.clone();
    // exception thrown if not found
    Element collection = getCollection(name, e);
    List list = collection.getChildren("Simple");
    if (list.isEmpty())
        list = collection.getChildren("Simple", MOBY_NS);
    if (list.isEmpty())
        return new Element[] {};
    Vector vector = new Vector();
    for (Iterator it = list.iterator(); it.hasNext(); ) {
        Object o = it.next();
        if (o instanceof Element) {
            ((Element) o).setAttribute("articleName", name, MOBY_NS);
            if (((Element) o).getChildren().size() > 0)
                vector.add(o);
        }
    }
    Element[] elements = new Element[vector.size()];
    vector.copyInto(elements);
    return elements;
}

57. XMLUtilities#getServiceNotes()

View license
/**
	 *
	 * @param element
	 *            a full moby message (root element called MOBY) and may be
	 *            prefixed
	 * @return the serviceNotes element if it exists, null otherwise.
	 */
public static Element getServiceNotes(Element element) {
    Element serviceNotes = null;
    Element e = (Element) element.clone();
    Element mobyContent = e.getChild("mobyContent");
    if (mobyContent == null)
        mobyContent = e.getChild("mobyContent", MOBY_NS);
    // should throw exception?
    if (mobyContent == null)
        return serviceNotes;
    serviceNotes = mobyContent.getChild("serviceNotes");
    if (serviceNotes == null)
        serviceNotes = mobyContent.getChild("serviceNotes", MOBY_NS);
    // note: servicenotes may be null
    return serviceNotes;
}

58. PsiTestCase#loadData()

Project: intellij-community
Source File: PsiTestCase.java
View license
private PsiTestData loadData(String dataName) throws Exception {
    PsiTestData data = createData();
    Element documentElement = JdomKt.loadElement(Paths.get(myDataRoot, "data.xml"));
    for (Element node : documentElement.getChildren("data")) {
        String value = node.getAttributeValue("name");
        if (value.equals(dataName)) {
            DefaultJDOMExternalizer.readExternal(data, node);
            data.loadText(myDataRoot);
            return data;
        }
    }
    throw new IllegalArgumentException("Cannot find data chunk '" + dataName + "'");
}

59. DefaultArrangementSettingsSerializer#serialize()

View license
@Nullable
public Element serialize(@NotNull ArrangementMatchRule rule) {
    Element matcherElement = myMatcherSerializer.serialize(rule.getMatcher());
    if (matcherElement == null) {
        return null;
    }
    Element result = new Element(RULE_ELEMENT_NAME);
    result.addContent(new Element(MATCHER_ELEMENT_NAME).addContent(matcherElement));
    if (rule.getOrderType() != ArrangementMatchRule.DEFAULT_ORDER_TYPE) {
        result.addContent(new Element(ORDER_TYPE_ELEMENT_NAME).setText(rule.getOrderType().getId()));
    }
    return result;
}

60. ArrangementSettingsSerializationTest#testSimpleSectionSerialize()

View license
@Test
public void testSimpleSectionSerialize() {
    final StdArrangementSettings settings = settings(ContainerUtil.newArrayList(group(OVERRIDDEN_METHODS)), ContainerUtil.newArrayList(section(true, FIELD)));
    final Element holder = doSerializationTest(settings, emptySettings());
    assertTrue(holder.getChildren().size() == 2);
    assertNotNull(holder.getChild("groups"));
    final Element rules = holder.getChild("rules");
    assertNotNull(rules);
    assertTrue(rules.getChildren().size() == 1);
    final Element section = rules.getChild("section");
    assertNotNull(section);
    assertTrue(section.getChildren().size() == 1);
    assertNotNull(section.getChild("rule"));
}

61. ArrangementSettingsSerializationTest#testSectionSerialize()

View license
@Test
public void testSectionSerialize() {
    final ArrayList<ArrangementSectionRule> sections = ContainerUtil.newArrayList(section("start section", "end section", rule(true, METHOD, PRIVATE), rule(false, METHOD, PUBLIC)), section("start section", "end section", rule(true, FIELD)));
    final StdArrangementSettings settings = settings(ContainerUtil.newArrayList(group(OVERRIDDEN_METHODS)), sections);
    final Element holder = doSerializationTest(settings, emptySettings());
    assertTrue(holder.getChildren().size() == 2);
    assertNotNull(holder.getChild("groups"));
    final Element rules = holder.getChild("rules");
    assertNotNull(rules);
    assertTrue(rules.getChildren().size() == 2);
    final Element section = rules.getChild("section");
    assertEquals(section.getAttribute("start_comment").getValue(), "start section");
    assertEquals(section.getAttribute("end_comment").getValue(), "end section");
}

62. ConversionContextImpl#findModuleFiles()

View license
private File[] findModuleFiles(final Element root) {
    final Element modulesManager = JDomSerializationUtil.findComponent(root, ModuleManagerImpl.COMPONENT_NAME);
    if (modulesManager == null)
        return new File[0];
    final Element modules = modulesManager.getChild(ModuleManagerImpl.ELEMENT_MODULES);
    if (modules == null)
        return new File[0];
    final ExpandMacroToPathMap macros = createExpandMacroMap();
    List<File> files = new ArrayList<File>();
    for (Element module : JDOMUtil.getChildren(modules, ModuleManagerImpl.ELEMENT_MODULE)) {
        String filePath = module.getAttributeValue(ModuleManagerImpl.ATTRIBUTE_FILEPATH);
        filePath = macros.substitute(filePath, true);
        files.add(new File(FileUtil.toSystemDependentName(filePath)));
    }
    return files.toArray(new File[files.size()]);
}

63. EnvironmentVariablesData#readExternal()

View license
@NotNull
public static EnvironmentVariablesData readExternal(@NotNull Element element) {
    Element envsElement = element.getChild(ENVS);
    if (envsElement == null) {
        return DEFAULT;
    }
    Map<String, String> envs = ImmutableMap.of();
    String passParentEnvsStr = envsElement.getAttributeValue(PASS_PARENT_ENVS);
    boolean passParentEnvs = passParentEnvsStr == null || Boolean.parseBoolean(passParentEnvsStr);
    for (Element envElement : envsElement.getChildren(ENV)) {
        String envName = envElement.getAttributeValue(NAME);
        String envValue = envElement.getAttributeValue(VALUE);
        if (envName != null && envValue != null) {
            if (envs.isEmpty()) {
                envs = ContainerUtil.newLinkedHashMap();
            }
            envs.put(envName, envValue);
        }
    }
    return create(envs, passParentEnvs);
}

64. FileColorConfiguration#save()

View license
public void save(@NotNull final Element e) {
    if (!isValid(null)) {
        return;
    }
    final Element tab = new Element(FileColorsModel.FILE_COLOR);
    tab.setAttribute(SCOPE_NAME, getScopeName());
    tab.setAttribute(COLOR, myColorName);
    e.addContent(tab);
}

65. ExternalizablePropertyTest#testWriteList()

View license
public void testWriteList() throws WriteExternalException {
    myContainer.registerProperty(PROPERTY, "item", EXTERNALIZER);
    PROPERTY.getModifiableList(myContainer).add(new MockJDOMExternalizable());
    Element containerElement = new Element("xxx");
    myContainer.writeExternal(containerElement);
    List children = containerElement.getChildren();
    assertEquals(1, children.size());
    Element listElement = (Element) children.get(0);
    assertEquals("list", listElement.getName());
    children = listElement.getChildren();
    assertEquals(1, children.size());
    Element itemElement = (Element) children.get(0);
    assertEquals("item", itemElement.getName());
}

66. LibraryOrderEntryImpl#writeExternal()

View license
@Override
public void writeExternal(@NotNull Element rootElement) throws WriteExternalException {
    final Element element = OrderEntryFactory.createOrderEntryElement(ENTRY_TYPE);
    final String libraryLevel = getLibraryLevel();
    if (myExported) {
        element.setAttribute(EXPORTED_ATTR, "");
    }
    myScope.writeExternal(element);
    element.setAttribute(NAME_ATTR, getLibraryName());
    element.setAttribute(LEVEL_ATTR, libraryLevel);
    rootElement.addContent(element);
}

67. JDOMExternalizer#readMap()

View license
public static void readMap(Element root, Map<String, String> map, @NonNls @Nullable String rootName, @NonNls String entryName) {
    Element mapRoot;
    if (StringUtil.isNotEmpty(rootName)) {
        mapRoot = root.getChild(rootName);
    } else {
        mapRoot = root;
    }
    if (mapRoot == null) {
        return;
    }
    for (@NonNls Element element : mapRoot.getChildren(entryName)) {
        String name = element.getAttributeValue("name");
        if (name != null) {
            map.put(name, element.getAttributeValue("value"));
        }
    }
}

68. ChangeListManagerSerialization#readExternal()

View license
@SuppressWarnings({ "unchecked" })
public void readExternal(final Element element) throws InvalidDataException {
    final List<Element> listNodes = element.getChildren(NODE_LIST);
    for (Element listNode : listNodes) {
        readChangeList(listNode);
    }
    final List<Element> ignoredNodes = element.getChildren(NODE_IGNORED);
    for (Element ignoredNode : ignoredNodes) {
        readFileToIgnore(ignoredNode);
    }
    Element manuallyRemovedFromIgnoredTag = element.getChild(MANUALLY_REMOVED_FROM_IGNORED);
    Set<String> manuallyRemovedFromIgnoredPaths = new HashSet<String>();
    if (manuallyRemovedFromIgnoredTag != null) {
        for (Element tag : manuallyRemovedFromIgnoredTag.getChildren(DIRECTORY_TAG)) {
            manuallyRemovedFromIgnoredPaths.add(tag.getAttributeValue(ATT_PATH));
        }
    }
    myIgnoredIdeaLevel.setDirectoriesManuallyRemovedFromIgnored(manuallyRemovedFromIgnoredPaths);
}

69. YouTrackIntegrationTest#checkSpentTime()

View license
private void checkSpentTime(@NotNull HttpClient client, @NotNull String issueId, @NotNull String expectedTime) throws IOException, JDOMException {
    // Endpoint /rest/issue/BTYT4TT-8/timetracking/workitem/ doesn't work on this instance of YouTrack for some reason
    final GetMethod method = new GetMethod(myRepository.getUrl() + "/rest/issue/" + issueId);
    final int statusCode = client.executeMethod(method);
    assertEquals(HttpStatus.SC_OK, statusCode);
    final Element root = JDOMUtil.load(method.getResponseBodyAsStream());
    for (Element field : root.getChildren("field")) {
        if ("Spent time".equals(field.getAttributeValue("name"))) {
            final Element value = field.getChild("value");
            assertNotNull(value);
            assertEquals(expectedTime, value.getText().trim());
            return;
        }
    }
    fail("Field 'Spent time' not found in issue " + issueId);
}

70. StudyTaskManager#getState()

View license
@Nullable
@Override
public Element getState() {
    if (myCourse == null) {
        return null;
    }
    Element el = new Element("taskManager");
    Element courseElement = new Element(StudySerializationUtils.Xml.MAIN_ELEMENT);
    XmlSerializer.serializeInto(this, courseElement);
    el.addContent(courseElement);
    return el;
}

71. SLAEventBean#getRegistrationEvent()

Project: oozie
Source File: SLAEventBean.java
View license
private Element getRegistrationEvent(String tag) {
    Element eReg = new Element(tag);
    eReg.addContent(createATagElement("sequence-id", String.valueOf(getEvent_id())));
    Element e = new Element("registration");
    e.addContent(createATagElement("sla-id", getSlaId()));
    //e.addContent(createATagElement("sla-id", String.valueOf(getSlaId())));
    e.addContent(createATagElement("app-type", getAppType().toString()));
    e.addContent(createATagElement("app-name", getAppName()));
    e.addContent(createATagElement("user", getUser()));
    e.addContent(createATagElement("group", getGroupName()));
    e.addContent(createATagElement("parent-sla-id", String.valueOf(getParentSlaId())));
    e.addContent(createATagElement("expected-start", getDateString(getExpectedStart())));
    e.addContent(createATagElement("expected-end", getDateString(getExpectedEnd())));
    e.addContent(createATagElement("status-timestamp", getDateString(getStatusTimestamp())));
    e.addContent(createATagElement("notification-msg", getNotificationMsg()));
    e.addContent(createATagElement("alert-contact", getAlertContact()));
    e.addContent(createATagElement("dev-contact", getDevContact()));
    e.addContent(createATagElement("qa-contact", getQaContact()));
    e.addContent(createATagElement("se-contact", getSeContact()));
    e.addContent(createATagElement("alert-percentage", getAlertPercentage()));
    e.addContent(createATagElement("alert-frequency", getAlertFrequency()));
    e.addContent(createATagElement("upstream-apps", getUpstreamApps()));
    e.addContent(createATagElement("job-status", getJobStatus().toString()));
    e.addContent(createATagElement("job-data", getJobData()));
    eReg.addContent(e);
    return eReg;
}

72. SlackNotificationMainConfig#getProxyAsElement()

View license
public Element getProxyAsElement() {
    /*
    		  <proxy host="myproxy.mycompany.com" port="8080" >
      			<noproxy url=".mycompany.com" />
      			<noproxy url="192.168.0." />
    		  </proxy>
		 */
    if (this.getProxyHost() == null || this.getProxyPort() == null) {
        return null;
    }
    Element el = new Element(PROXY);
    el.setAttribute("host", this.getProxyHost());
    el.setAttribute("port", String.valueOf(this.getProxyPort()));
    if (this.proxyPassword != null && this.proxyPassword.length() > 0 && this.proxyUsername != null && this.proxyUsername.length() > 0) {
        el.setAttribute(USERNAME, this.getProxyUsername());
        el.setAttribute(PASSWORD, this.getProxyPassword());
    }
    return el;
}

73. InspectionProfileConvertor#convertToNewFormat()

View license
public static Element convertToNewFormat(Element profileFile, InspectionProfile profile) {
    Element rootElement = new Element(INSPECTIONS_TAG);
    rootElement.setAttribute(NAME_ATT, profile.getName());
    final InspectionToolWrapper[] tools = profile.getInspectionTools(null);
    for (final Object o : profileFile.getChildren(INSP_TOOL_TAG)) {
        Element toolElement = ((Element) o).clone();
        String toolClassName = toolElement.getAttributeValue(CLASS_ATT);
        final String shortName = convertToShortName(toolClassName, tools);
        if (shortName == null) {
            continue;
        }
        toolElement.setAttribute(CLASS_ATT, shortName);
        rootElement.addContent(toolElement);
    }
    return rootElement;
}

74. InspectionProfileLoadUtil#load()

View license
@NotNull
public static Profile load(@NotNull File file, @NotNull InspectionToolRegistrar registrar, @NotNull ProfileManager profileManager) throws JDOMException, IOException, InvalidDataException {
    Element element = JDOMUtil.loadDocument(file).getRootElement();
    InspectionProfileImpl profile = new InspectionProfileImpl(getProfileName(file, element), registrar, profileManager);
    final Element profileElement = element.getChild(PROFILE_TAG);
    if (profileElement != null) {
        element = profileElement;
    }
    profile.readExternal(element);
    return profile;
}

75. CompilerConfigurationImpl#getState()

View license
@Nullable
@Override
public Element getState() {
    if (myOutputDirPointer == null) {
        return null;
    }
    Element element = new Element("state");
    element.setAttribute(URL, myOutputDirPointer.getUrl());
    for (Module module : myModuleManager.getModules()) {
        val moduleCompilerPathsManager = (ModuleCompilerPathsManagerImpl) ModuleCompilerPathsManager.getInstance(module);
        Element state = moduleCompilerPathsManager.getState();
        if (state != null) {
            element.addContent(state);
        }
    }
    return element;
}

76. ArtifactManagerImpl#serializePackagingElement()

Project: consulo
Source File: ArtifactManagerImpl.java
View license
private static Element serializePackagingElement(PackagingElement<?> packagingElement) {
    Element element = new Element(PACKAGING_ELEMENT_NAME);
    element.setAttribute(TYPE_ID_ATTRIBUTE, packagingElement.getType().getId());
    final Object bean = packagingElement.getState();
    if (bean != null) {
        XmlSerializer.serializeInto(bean, element, new SkipDefaultValuesSerializationFilters());
    }
    if (packagingElement instanceof CompositePackagingElement) {
        for (PackagingElement<?> child : ((CompositePackagingElement<?>) packagingElement).getChildren()) {
            element.addContent(serializePackagingElement(child));
        }
    }
    return element;
}

77. ResourceCompilerConfiguration#getState()

View license
@Nullable
@Override
public Element getState() {
    Element parentNode = new Element("state");
    final Element newChild = addChild(parentNode, RESOURCE_EXTENSIONS);
    for (final String pattern : getRegexpPatterns()) {
        addChild(newChild, ENTRY).setAttribute(NAME, pattern);
    }
    if (myWildcardPatternsInitialized || !myWildcardPatterns.isEmpty()) {
        final Element wildcardPatterns = addChild(parentNode, WILDCARD_RESOURCE_PATTERNS);
        for (final String wildcardPattern : myWildcardPatterns) {
            addChild(wildcardPatterns, ENTRY).setAttribute(NAME, wildcardPattern);
        }
    }
    return parentNode;
}

78. ExtensionComponentAdapterTest#readElement()

View license
static Element readElement(String text) {
    Element extensionElement1 = null;
    try {
        extensionElement1 = new SAXBuilder().build(new StringReader(text)).getRootElement();
    } catch (JDOMException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Element extensionElement = extensionElement1;
    return extensionElement;
}

79. DefaultArrangementSettingsSerializer#deserializeTokensDefinition()

View license
@Nullable
private Set<StdArrangementRuleAliasToken> deserializeTokensDefinition(@NotNull Element element, @NotNull ArrangementSettings defaultSettings) {
    if (!(defaultSettings instanceof ArrangementExtendableSettings)) {
        return null;
    }
    final Element tokensRoot = element.getChild(TOKENS_ELEMENT_NAME);
    if (tokensRoot == null) {
        return ((ArrangementExtendableSettings) myDefaultSettings).getRuleAliases();
    }
    final Set<StdArrangementRuleAliasToken> tokenDefinitions = new THashSet<StdArrangementRuleAliasToken>();
    final List<Element> tokens = tokensRoot.getChildren(TOKEN_ELEMENT_NAME);
    for (Element token : tokens) {
        final Attribute id = token.getAttribute(TOKEN_ID);
        final Attribute name = token.getAttribute(TOKEN_NAME);
        assert id != null && name != null : "Can not find id for token: " + token;
        final Element rules = token.getChild(RULES_ELEMENT_NAME);
        final List<StdArrangementMatchRule> tokenRules = rules == null ? ContainerUtil.<StdArrangementMatchRule>emptyList() : deserializeRules(rules, null);
        tokenDefinitions.add(new StdArrangementRuleAliasToken(id.getValue(), name.getValue(), tokenRules));
    }
    return tokenDefinitions;
}

80. CopyrightManager#readExternal()

Project: consulo
Source File: CopyrightManager.java
View license
private void readExternal(Element element) throws InvalidDataException {
    clearCopyrights();
    final Element module2copyright = element.getChild(MODULE2COPYRIGHT);
    if (module2copyright != null) {
        for (Element o : module2copyright.getChildren(ELEMENT)) {
            final String moduleName = o.getAttributeValue(MODULE);
            final String copyrightName = o.getAttributeValue(COPYRIGHT);
            myModule2Copyrights.put(moduleName, copyrightName);
        }
    }
    for (Element o : element.getChildren(COPYRIGHT)) {
        final CopyrightProfile copyrightProfile = new CopyrightProfile();
        copyrightProfile.readExternal(o);
        myCopyrights.put(copyrightProfile.getName(), copyrightProfile);
    }
    myDefaultCopyright = myCopyrights.get(element.getAttributeValue(DEFAULT));
    myCopyrightFileConfigManager.readExternal(element);
}

81. ModuleExtensionImpl#getState()

Project: consulo
Source File: ModuleExtensionImpl.java
View license
@Nullable
@Override
public final Element getState() {
    if (!isEnabled()) {
        return null;
    }
    Element element = new Element("extension");
    element.setAttribute("id", myId);
    getStateImpl(element);
    return element;
}

82. NotificationSettings#save()

Project: consulo
Source File: NotificationSettings.java
View license
@NotNull
public Element save() {
    final Element result = new Element("notification");
    result.setAttribute("groupId", getGroupId());
    final NotificationDisplayType displayType = getDisplayType();
    if (displayType != NotificationDisplayType.BALLOON) {
        result.setAttribute("displayType", displayType.toString());
    }
    if (!myShouldLog) {
        result.setAttribute("shouldLog", "false");
    }
    if (myShouldReadAloud) {
        result.setAttribute("shouldReadAloud", "true");
    }
    return result;
}

83. HistoryEntry#writeExternal()

Project: consulo
Source File: HistoryEntry.java
View license
/**
   * @return element that was added to the <code>element</code>.
   * Returned element has tag {@link #TAG}. Never null.
   */
public Element writeExternal(Element element, Project project) {
    Element e = new Element(TAG);
    element.addContent(e);
    e.setAttribute(FILE_ATTR, myFile.getUrl());
    for (final Map.Entry<FileEditorProvider, FileEditorState> entry : myProvider2State.entrySet()) {
        FileEditorProvider provider = entry.getKey();
        Element providerElement = new Element(PROVIDER_ELEMENT);
        if (provider.equals(mySelectedProvider)) {
            providerElement.setAttribute(SELECTED_ATTR_VALUE, Boolean.TRUE.toString());
        }
        providerElement.setAttribute(EDITOR_TYPE_ID_ATTR, provider.getEditorTypeId());
        Element stateElement = new Element(STATE_ELEMENT);
        providerElement.addContent(stateElement);
        provider.writeState(entry.getValue(), project, stateElement);
        e.addContent(providerElement);
    }
    return e;
}

84. ProjectManagerImpl#getState()

Project: consulo
Source File: ProjectManagerImpl.java
View license
@Nullable
@Override
public Element getState() {
    if (myDefaultProject != null) {
        myDefaultProject.save();
    }
    if (myDefaultProjectRootElement == null) {
        // we are not ready to save
        return null;
    }
    Element element = new Element("state");
    myDefaultProjectRootElement.detach();
    element.addContent(myDefaultProjectRootElement);
    return element;
}

85. WindowManagerImpl#loadState()

Project: consulo
Source File: WindowManagerImpl.java
View license
@Override
public void loadState(Element state) {
    final Element frameElement = state.getChild(FRAME_ELEMENT);
    if (frameElement != null) {
        myFrameBounds = loadFrameBounds(frameElement);
        try {
            myFrameExtendedState = Integer.parseInt(frameElement.getAttributeValue(EXTENDED_STATE_ATTR));
            if ((myFrameExtendedState & Frame.ICONIFIED) > 0) {
                myFrameExtendedState = Frame.NORMAL;
            }
        } catch (NumberFormatException ignored) {
            myFrameExtendedState = Frame.NORMAL;
        }
    }
    final Element desktopElement = state.getChild(DesktopLayout.TAG);
    if (desktopElement != null) {
        myLayout.readExternal(desktopElement);
    }
}

86. UsefulTestCase#checkSettingsEqual()

Project: consulo
Source File: UsefulTestCase.java
View license
protected static void checkSettingsEqual(JDOMExternalizable expected, JDOMExternalizable settings, String message) throws Exception {
    if (expected == null) {
        return;
    }
    if (settings == null) {
        return;
    }
    Element oldS = new Element("temp");
    expected.writeExternal(oldS);
    Element newS = new Element("temp");
    settings.writeExternal(newS);
    String newString = JDOMUtil.writeElement(newS, "\n");
    String oldString = JDOMUtil.writeElement(oldS, "\n");
    Assert.assertEquals(message, oldString, newString);
}

87. JDOMExternalizableStringList#writeExternal()

View license
@Override
public void writeExternal(Element element) {
    int listSize = size();
    Element listElement = new Element(ATTR_LIST);
    listElement.setAttribute(ATTR_LISTSIZE, Integer.toString(listSize));
    element.addContent(listElement);
    for (int i = 0; i < listSize; i++) {
        String listItem = get(i);
        if (listItem != null) {
            Element itemElement = new Element(ATTR_ITEM);
            itemElement.setAttribute(ATTR_INDEX, Integer.toString(i));
            itemElement.setAttribute(ATTR_CLASS, listItem.getClass().getName());
            itemElement.setAttribute(ATTR_VALUE, DefaultJDOMExternalizer.filterXMLCharacters(listItem));
            listElement.addContent(itemElement);
        }
    }
}

88. JDOMExternalizer#readMap()

Project: consulo
Source File: JDOMExternalizer.java
View license
public static void readMap(Element root, Map<String, String> map, @NonNls @Nullable String rootName, @NonNls String entryName) {
    Element mapRoot;
    if (StringUtil.isNotEmpty(rootName)) {
        mapRoot = root.getChild(rootName);
    } else {
        mapRoot = root;
    }
    if (mapRoot == null)
        return;
    for (@NonNls Element element : (List<Element>) mapRoot.getChildren(entryName)) {
        final String name = element.getAttributeValue("name");
        if (name != null) {
            final String value = element.getAttributeValue("value");
            map.put(name, value);
        }
    }
}

89. JDomBuilderWithLicenseTest#checkBuildLicenseWithParameters()

View license
/**
     * @param numberOfParameters
     */
private void checkBuildLicenseWithParameters(final int numberOfParameters) {
    final Element licenseParametersElement = new Element("license-parameters");
    for (int i = 0; i < numberOfParameters; i++) {
        licenseParametersElement.addContent(new Element("parameter").addContent(new Element("name").addContent(new CDATA(name(i)))).addContent(new Element("value").addContent(new CDATA(value(i)))));
    }
    final Element input = new Element("with-license").addContent(licenseParametersElement);
    final Map<String, String> results = subject.parameters(input);
    assertNotNull("Expected builder to build parameters", results);
    assertEquals("Expected builder to add one name, value pair per parameter", numberOfParameters, results.size());
    for (int i = 0; i < numberOfParameters; i++) {
        assertEquals("Value indexed by name", results.get(name(i)), value(i));
    }
}

90. JDomBuilderWithLicenseTest#checkBuildWithLicenseWithParameters()

View license
/**
     * @param numberOfParameters
     */
private void checkBuildWithLicenseWithParameters(final int numberOfParameters) {
    final String id = "some id";
    final Map<String, License> licenses = new HashMap<String, License>();
    final Map<String, Organisation> organisations = new HashMap<String, Organisation>();
    addLicenseTo(licenses, id);
    final Element licenseParametersElement = new Element("license-parameters");
    for (int i = 0; i < numberOfParameters; i++) {
        licenseParametersElement.addContent(new Element("parameter").addContent(new Element("name").addContent(new CDATA(name(i)))).addContent(new Element("value").addContent(new CDATA(value(i)))));
    }
    final Element input = new Element("with-license").setAttribute("id", id).addContent(licenseParametersElement);
    final Map<String, String> results = subject.withLicense(input, licenses, organisations).getParameters();
    assertNotNull("Expected builder to build parameters", results);
    assertEquals("Expected builder to add one name, value pair per parameter", numberOfParameters, results.size());
    for (int i = 0; i < numberOfParameters; i++) {
        assertEquals("Value indexed by name", results.get(name(i)), value(i));
    }
}

91. JavaSourceJdom#parseType()

Project: freud
Source File: JavaSourceJdom.java
View license
public static String parseType(final Element element) {
    final Element typeElement = element.getChild(JavaSourceTokenType.TYPE.getName());
    if (typeElement == null) {
        //void
        return JavaSourceTokenType.VOID.name().toLowerCase();
    }
    Element qualifiedType = typeElement.getChild(JavaSourceTokenType.QUALIFIED_TYPE_IDENT.getName());
    if (qualifiedType != null) {
        return qualifiedType.getChildText(JavaSourceTokenType.IDENT.getName());
    } else {
        //primitive type
        List<Element> children = typeElement.getChildren();
        return children.get(0).getText();
    }
}

92. CassandraMappingManager#get()

Project: gora
Source File: CassandraMappingManager.java
View license
public CassandraMapping get(Class<?> persistentClass) {
    String className = persistentClass.getName();
    Element mappingElement = mappingMap.get(className);
    if (mappingElement == null) {
        LOG.error("Mapping element does not exist for className=" + className);
        return null;
    }
    String keyspaceName = mappingElement.getAttributeValue(KEYSPACE_ELEMENT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("persistentClassName=" + className + " -> keyspaceName=" + keyspaceName);
    }
    Element keyspaceElement = keyspaceMap.get(keyspaceName);
    if (keyspaceElement == null) {
        LOG.error("Keyspace element does not exist for keyspaceName=" + keyspaceName);
        return null;
    }
    return new CassandraMapping(keyspaceElement, mappingElement);
}

93. EventProcessor#processOutput()

View license
@SuppressWarnings("unchecked")
private void processOutput(OutputDataProvenanceItem provenanceItem, ProcessorBinding procBinding, String currentWorkflowID) {
    Element dataItemAsXML = getDataItemAsXML(provenanceItem);
    List<Element> outputPorts = dataItemAsXML.getChildren("port");
    for (Element outputport : outputPorts) {
        String portName = outputport.getAttributeValue("name");
        // value type may vary
        List<Element> valueElements = outputport.getChildren();
        if (valueElements != null && !valueElements.isEmpty()) {
            // only really 1 child
            Element valueEl = valueElements.get(0);
            processPortBinding(valueEl, procBinding.getProcessorName(), portName, procBinding.getIterationVector(), getWorkflowRunId(), currentWorkflowID);
        }
    }
}

94. ProvenanceQuery#addToCollection()

View license
private void addToCollection(LineageQueryResultRecord record, Document d) {
    Element root = d.getRootElement();
    String[] itVector = record.getIteration().split(",");
    Element currentEl = root;
    // each element gives us a corresponding child in the tree
    for (int i = 0; i < itVector.length; i++) {
        int index = Integer.parseInt(itVector[i]);
        List<?> children = currentEl.getChildren();
        if (index < children.size())
            currentEl = (Element) children.get(index);
        else if (i == itVector.length - 1)
            currentEl.addContent(new Element(record.getValue()));
        else
            currentEl.addContent(new Element("list"));
    }
}

95. QueryXMLHandler#datasetToElement()

View license
/**
	 * Converts a <code>Dataset</code> to an XML element.
	 * 
	 * @param dataset
	 *            the <code>Dataset</code> to serialize
	 * @param namespace
	 *            the <code>Namespace</code> to use when constructing the
	 *            <code>Element</code>
	 * @return an XML serialization of the <code>Dataset</code>
	 */
public static Element datasetToElement(Dataset dataset, Namespace namespace) {
    Element datasetElement = new Element(DATASET_ELEMENT, namespace);
    datasetElement.setAttribute(NAME_ATTRIBUTE, dataset.getName());
    for (Attribute attribute : dataset.getAttributes()) {
        datasetElement.addContent(attributeToElement(attribute, namespace));
    }
    for (Filter filter : dataset.getFilters()) {
        datasetElement.addContent(filterToElement(filter, namespace));
    }
    return datasetElement;
}

96. QueryXMLHandler#filterToElement()

View license
/**
	 * Converts a <code>Filter</code> to an XML element.
	 * 
	 * @param filter
	 *            the <code>Filter</code> to serialize
	 * @param namespace
	 *            the <code>Namespace</code> to use when constructing the
	 *            <code>Element</code>
	 * @return an XML serialization of the <code>Filter</code>
	 */
public static Element filterToElement(Filter filter, Namespace namespace) {
    Element filterElement = new Element(FILTER_ELEMENT, namespace);
    filterElement.setAttribute(NAME_ATTRIBUTE, filter.getName());
    String value = filter.getValue();
    if (filter.isBoolean()) {
        if ("excluded".equalsIgnoreCase(value)) {
            filterElement.setAttribute("excluded", "1");
        } else {
            filterElement.setAttribute("excluded", "0");
        }
    } else {
        if (value == null) {
            filterElement.setAttribute("value", "");
        } else {
            filterElement.setAttribute("value", value);
        }
    }
    if (filter.isList()) {
        filterElement.setAttribute("list", "true");
    }
    return filterElement;
}

97. QueryXMLHandler#elementToQuery()

View license
/**
	 * Creates a <code>Query</code> from an XML element.
	 * 
	 * @param element
	 *            the <code>Element</code> to deserialize
	 * @param namespace
	 *            the <code>Namespace</code> containing the
	 *            <code>Element</code>
	 * @return a deserialized <code>Query</code>
	 */
public static Query elementToQuery(Element element, Namespace namespace) {
    String virtualSchema = element.getAttributeValue(SCHEMA_ATTRIBUTE);
    int count = Integer.parseInt(element.getAttributeValue(COUNT_ATTRIBUTE));
    String version = element.getAttributeValue(VERSION_ATTRIBUTE);
    String formatter = element.getAttributeValue(FORMATTER_ATTRIBUTE);
    String requestId = element.getAttributeValue(REQUEST_ID_ATTRIBUTE);
    Query query = new Query(virtualSchema, count, version, requestId);
    query.setFormatter(formatter);
    String uniqueRows = element.getAttributeValue(UNIQUE_ROWS_ATTRIBUTE);
    if (uniqueRows != null) {
        query.setUniqueRows(Integer.parseInt(uniqueRows));
    }
    List<Element> datasets = element.getChildren(DATASET_ELEMENT, namespace);
    for (Element datasetElement : datasets) {
        query.addDataset(elementToDataset(datasetElement, namespace));
    }
    List<Element> links = element.getChildren(LINK_ELEMENT, namespace);
    for (Element linkElement : links) {
        query.addLink(elementToLink(linkElement));
    }
    return query;
}

98. QueryXMLHandler#elementToDataset()

View license
/**
	 * Creates a <code>Dataset</code> from an XML element.
	 * 
	 * @param element
	 *            the <code>Element</code> to deserialize
	 * @param namespace
	 *            the <code>Namespace</code> containing the
	 *            <code>Element</code>
	 * @return a deserialized <code>Dataset</code>
	 */
public static Dataset elementToDataset(Element element, Namespace namespace) {
    Dataset dataset = new Dataset(element.getAttributeValue(NAME_ATTRIBUTE));
    List<Element> attributes = element.getChildren(ATTRIBUTE_ELEMENT, namespace);
    for (Element attributeElement : attributes) {
        dataset.addAttribute(elementToAttribute(attributeElement));
    }
    List<Element> filters = element.getChildren(FILTER_ELEMENT, namespace);
    for (Element filterElement : filters) {
        dataset.addFilter(elementToFilter(filterElement));
    }
    return dataset;
}

99. XMLUtilities#getListOfSimples()

View license
/**
	 *
	 * @param message
	 *            the String of xml to extract the list of simples from. This
	 *            method assumes that you are passing in a single invokation and
	 *            that you wish to extract the Simples not contained in any
	 *            collections. This method also maintains any past queryIDs.
	 * @return an array of Strings that represent fully 'wrapped' simples.
	 * @throws MobyException
	 *             if the String doesnt contain a structurally valid Moby
	 *             message structure or if an unexpected error occurs
	 */
public static String[] getListOfSimples(String message) throws MobyException {
    Element element = getDOMDocument(message).getRootElement();
    Element[] elements = getListOfSimples(element);
    String[] strings = new String[elements.length];
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(false));
    for (int count = 0; count < elements.length; count++) {
        try {
            strings[count] = outputter.outputString(elements[count]);
        } catch (Exception e) {
            throw new MobyException(newline + "Unexpected error occured while creating String[]:" + newline + Utils.format(e.getLocalizedMessage(), 3));
        }
    }
    return strings;
}

100. XMLUtilities#getListOfCollections()

View license
/**
	 *
	 * @param message
	 *            the String to extract the list of collections from and assumes
	 *            that you are passing in a single invocation message.
	 * @return an array of Strings representing all of the fully 'wrapped'
	 *         collections in the message.
	 * @throws MobyException
	 *             if the the element contains an invalid BioMOBY message
	 */
public static String[] getListOfCollections(String message) throws MobyException {
    Element element = getDOMDocument(message).getRootElement();
    Element[] elements = getListOfCollections(element);
    String[] strings = new String[elements.length];
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat().setOmitDeclaration(false));
    for (int count = 0; count < elements.length; count++) {
        try {
            strings[count] = outputter.outputString(elements[count]);
        } catch (Exception e) {
            throw new MobyException(newline + "Unexpected error occured while creating String[]:" + newline + Utils.format(e.getLocalizedMessage(), 3));
        }
    }
    return strings;
}