By Louisa Lim
BBC News, Beijing
Beijing has moved to stem anti-Japan rallies after having been happy to let them rage through several Chinese cities last month.
Anti-Japanese protests have taken place in several Chinese cities
It has shut down nationalist websites, detained dissidents and sent out text messages warning against illegal demonstrations.
The moves come ahead of a sensitive anniversary in China-Japan relations - the 4 May student protests against Japan, which took place in 1919.
While the Chinese government has always made political use of nationalist sentiment among its public, it also recognises its dangers.
The demonstrations in 1919, when students marched through Beijing to protest against the influence exercised by Japan and other foreign powers, marked the birth of China's first mass movement.
The nationalistic, patriotic gathering was joined by workers and intellectuals, and eventually led to the birth of the Communist Party [CCP].
But now the spectre of 4 May raises very different fears for the government, according to author Yu Jie, an outspoken mainland commentator whose two books on Sino-Japanese relations have been withdrawn from bookshops in China.
"In the past century, anti-Japanese protests, from the 4 May movement in 1919 to the demonstrations in the 1980s, have changed [focus]... to criticising and showing discontent over domestic political issues.
"So the government is very afraid. The government's use of this popular anti-Japanese sentiment is dangerous, like walking along a tightrope," he said.
Before it clamped down on them, China's leadership certainly used last month's anti-Japan protests to support its political line.
The catalyst for the recent outpouring of anger was the Japanese education ministry's decision to approve a revised history textbook which critics say whitewashes atrocities from Japan's militaristic past.
The protesters, many of them students, also opposed Tokyo's ambitions to gain a permanent seat on the United Nations Security Council.
China's Premier Wen Jiabao referred to the demonstrators when he voiced China's opposition to Japan's bid, proclaiming that such "strong responses" should make Tokyo reflect on its past.
China has recently shut down some nationalist websites
"The students realise they were being used as a political tool," one student at Peking University said, "but they still believe their point of view was right."
The University of Colorado's Peter Gries, the author of China's New Nationalism, said: "Anti-Japanese sentiment is in many ways at the core of many of the anxieties and uncertainties that Chinese have about their own place in the world."
"One of the reasons it's coming out now is that under Mao Zedong the Chinese were not really allowed to think about their suffering in World War II," Mr Gries said.
"The Chinese were forced to tell a tale of heroic victory, where the Communist Party defeated the Japanese. That was the story that the new Communist Party needed to tell, and the Communist Party staked its legitimacy on its nationalist credentials."
The use of nationalism to bolster China's leadership went one step further after the government violently suppressed pro-democracy demonstrations in Tiananmen Square in 1989.
Faced with widespread dissatisfaction over the widening income disparity, unemployment and newly emerging social problems caused by economic reforms, patriotic nationalism was probably the only important value shared by the party and its critics.
So a patriotic education campaign was soon launched.
"After the Tiananmen movement, there was a big change in CCP politics," said Chinese commentator Yu Jie.
"Marxism and 'Mao Zedong thought' completely lost their attraction, and the Chinese Communist Party became a nationalistic, patriotic movement.
"And they used nationalistic patriotic propaganda to bolster their ruling legitimacy. They turned Japan into an enemy in order to gain support at home, and to distract the student movement from criticising domestic problems like corruption."
But the costs of this strategy are beginning to emerge.
With China's rising economic might leading to an upsurge in national pride, those schooled in patriotic education are finding a voice on the internet.
This has offered activists a more decentralised way to organise campaigns, beyond the control of the Communist Party.
For a leadership which has tried to sell "China's peaceful rise" to its neighbours, the sight of thousands of angry demonstrators is bound to be alarming.
But Peter Gries said China's foreign policy was increasingly being influenced by what was happening on the streets.
"China's political elite are increasingly playing a two-level game. They're negotiating with their foreign counterparts, but they're looking over their shoulder at domestic nationalists.
After the 1989 Tiananmen protests, party policy changed
"China's leaders cannot afford to be viewed as weak on nationalist issues, as the Chinese Communist Party depends so much on its nationalist credentials to earn the consent of the people to continue governing China."
Many analysts agree that China's Communist Party can no longer ignore popular opinion.
Joseph Cheng from City University in Hong Kong said that was one reason why last month's protests were given tacit approval by China's leaders.
"They realised that to suppress such activities would make the new leadership very unpopular. They understood that [former Communist Party leader] Jiang Zemin was severely criticised for dealing with Japan, and even with the US, too weakly.
"And they probably believed that, under such circumstances, to allow such protests would be a good way to let people vent their anger."
But new levels of denunciation seem to indicate the leadership now regrets that decision.
One major newspaper, the Shanghai Liberation Daily, has referred to the protests as a "conspiracy behind the scenes" aimed at "achieving hidden goals".
That type of language suggests some leaders were worried about the ultimate aim of the demonstrations.
Dozens of people have now been detained over the violence. Joseph Cheng said the leadership was reasserting itself in order to guarantee its own survival.
"One has to appreciate the Chinese leadership want to remain in full control of foreign policy. They don't want to allow civil society or civil groups to affect complete control. Chinese leaders are very worried about protest activities in China today.
"Today Chinese people can march against Japan, tomorrow they can march against the leadership," he said.